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 Pixels.[int,float,toInt,toFloat] #28

Closed
ianmackenzie opened this issue Feb 20, 2019 · 3 comments
Closed

Add Pixels.[int,float,toInt,toFloat] #28

ianmackenzie opened this issue Feb 20, 2019 · 3 comments

Comments

@ianmackenzie
Copy link
Owner

Similar to the corresponding functions in Quantity:

Pixels.int : Int -> Quantity Int Pixels
Pixels.float : Float -> Quantity Float Pixels
Pixels.toInt : Quantity Int Pixels -> Int
Pixels.toFloat : Quantity Float Pixels -> Float

A little less flexible than Pixels.pixels/Pixels.inPixels (not generic on number type) but a bit more clear/explicit and read better when used in prefixed form (Pixels.toInt vs. Pixels.inPixels).

Seems like a good general pattern to follow for any quantity type where the units type is synonymous with the quantity itself (pixels, game tiles, grid cells etc.) as opposed to ones where the same quantity can be expressed in many different units (length in meters/centimeters/feet, duration in hours/minutes/seconds, etc.).

@ianmackenzie
Copy link
Owner Author

Pixels.fromInt and Pixels.fromFloat might be better - a little inconsistent with Quantity.int and Quantity.float, but it is a slightly different operation: a Quantity Float Unitless is semantically the same as a plain Float value, while a Quantity Float Pixels is not. So it kind of makes sense that the former is constructed by Quantity.float (just "a Float quantity") while the latter would be constructed by Pixels.fromFloat (convert a Float to a number of pixels).

@ianmackenzie
Copy link
Owner Author

Problem: what should pixelsPerSecond, inPixelsPerSecond etc. be then? Perhaps best to stick with pixels/inPixels and either:

  • use functions unqualified (pixels 200 vs Pixels.pixels 200)
  • alias all quantity modules to Quantity on import (e.g. import Pixels as Quantity) and then use Quantity.pixels, Quantity.inPixels etc.

@ianmackenzie
Copy link
Owner Author

Aliasing-to-Quantity (or perhaps even moving everything into a huge Quantity module as suggested in #31) seems more promising - closing this for now.

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

No branches or pull requests

1 participant