Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add BoundingBox2d.aspectRatio #133

Open
MartinSStewart opened this issue May 30, 2020 · 1 comment
Open

Add BoundingBox2d.aspectRatio #133

MartinSStewart opened this issue May 30, 2020 · 1 comment

Comments

@MartinSStewart
Copy link

MartinSStewart commented May 30, 2020

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.

@ianmackenzie
Copy link
Owner

I think I'd be inclined to just return a Float, to be consistent with Quantity.ratio and other Elm functions in general (sqrt, the built-in division operator etc.) that can return infinity or NaN.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants