Closed ianmackenzie closed 5 years ago
Brainstorming a bit, not fully formed:
module Angle exposing
( DegreesMinutesSeconds(..)
, fromDegreesMinutesSeconds
, toDegreesMinutesSeconds
)
type DegreesMinutesSeconds
= Positive { degrees : Float, minutes : Float, seconds : Float }
| Negative { degrees : Float, minutes : Float, seconds : Float }
fromDegreesMinutesSeconds : DegreesMinutesSeconds -> Angle
toDegreesMinutesSeconds : Angle -> DegreesMinutesSeconds
which you would then use as
angle =
Angle.fromDegreesMinutesSeconds <|
Angle.Positive { degrees = 12, minutes = 34, seconds = 56 }
something =
case angle of
Angle.Positive { degrees, minutes, seconds } ->
...
Angle.Negative { degrees, minutes, seconds } ->
...
A couple more thoughts from musing about this on the bus:
Another potential API:
type Sign
= Positive
| Negative
fromDms : { sign : Sign, degrees : Int, minutes : Int, seconds : Float } -> Angle
toDms : Angle -> { sign : Sign, degrees : Int, minutes : Int, seconds : Float }
which would be used as
angle =
Angle.fromDms
{ sign = Angle.Positive
, degrees = 45
, minutes = 30
, seconds = 0
}
{ sign, degrees, minutes, seconds } =
Angle.toDms angle
Potential drawback: could be easy to destructure as
{ degrees, minutes, seconds} =
Angle.toDms angle
and forget to check for sign.
Implemented in 447c3c53cca69e83ab63ccc445b41b407c539a5f.
At a minimum:
Perhaps also some support for compound definitions, something like:
Or perhaps:
For the compound definitions, how exactly should negative angles be converted to degrees/minutes/seconds?