ianmackenzie/elm-geometry

Add BoundingBox2d.aspectRatio

开放

#133 创建于 2020年5月30日

 (1 条评论) (0 个反应) (0 位负责人)Elm (28 个派生)auto 404
Hacktoberfest

仓库指标

星标
 (186 个星标)
PR 合并指标
 (PR 指标待抓取)

描述

I've found that I've needed this function a couple times. Writing the code in a one-off fashion looks like this

( w, h ) =
    BoundingBox2d.dimensions boundingBox

aspectRatio =
    Quantity.ratio h w

safeAspectRatio = 
    if isNaN aspectRatio || isInfinite aspectRatio then
        Nothing
    else
        Just aspectRatio

This is verbose so it would be nice to just have as BoundingBox2d.aspectRatio: BoundingBox2d -> Maybe Float and possibly BoundingBox2d.aspectRatioInv: BoundingBox2d -> Maybe Float for the width over height version.

Edit: I know elm-geometry tends to avoid having functions that depend on a particular x y coordinate system but I think an exception should be made for BoundingBox2d since it's already defined in terms of an x y coordinate system.

贡献者指南