ianmackenzie/elm-units-interval

Version of elm-interval based on elm-units


Keywords
elm, interval, units
License
MPL-2.0
Install
elm-package install ianmackenzie/elm-units-interval 3.2.0

Documentation

elm-units-interval

This package lets you work with ranges of values (intervals) based on the Quantity type from elm-units. You can do things like:

  • Check if a given value is within an interval
  • Construct intervals from lists of values or other intervals
  • Find the intersection of two intervals
  • Perform arithmetic on intervals
import Quantity.Interval as Interval exposing (Interval)
import Angle exposing (Radians)
import Pixels exposing (Pixels)

angleRange : Interval Float Radians
angleRange =
    Interval.fromEndpoints
        ( Angle.degrees 0, Angle.degrees 180 )

widthRange : Interval Int Pixels
widthRange =
    Interval.fromEndpoints
        ( Pixels.int 100, Pixels.int 300 )

Various functionality is included for constructing intervals (including as the union or intersection of other intervals) and checking for overlap, intersection or containment:

import Quantity.Interval as Interval exposing (Interval)
import Length
import Duration

distanceInterval =
    Interval.fromEndpoints
        ( Length.meters 10, Length.meters 20 )

Interval.endpoints distanceInterval
--> ( Length.meters 10, Length.meters 20 )

Interval.hull
    (Length.feet 5)
    [ Length.feet 3
    , Length.feet 2
    , Length.feet 4
    ]
--> Interval.fromEndpoints
-->     ( Length.feet 2, Length.feet 5 )

Interval.aggregate2
    (Interval.fromEndpoints
        ( Duration.minutes 1
        , Duration.minutes 2
        )
    )
    (Interval.fromEndpoints
        ( Duration.minutes 3
        , Duration.minutes
        )
    )
--> Interval.fromEndpoints
-->     ( Duration.minutes 1, Duration.minutes 5 )

Interval.intersection
    (Interval.fromEndpoints
        ( Duration.hours 1
        , Duration.hours 3
        )
    )
    (Interval.fromEndpoints
        ( Duration.hours 2
        , Duration.hours 5
        )
    )
--> Just <|
-->     Interval.fromEndpoints
-->         ( Duration.hours 2
-->         , Duration.hours 3
-->         )

Interval.fromEndpoints
    ( Angle.radians 0, Angle.radians pi )
    |> Interval.contains (Angle.degrees 90)
--> True

Interval.fromEndpoints
    ( Angle.radians 0, Angle.radians pi )
    |> Interval.contains (Angle.degrees 270)
--> False

Most functionality is contained in the Quantity.Interval module, but some functionality specific to particular kinds of intervals is contained in Angle.Interval and Temperature.Interval.