ianmackenzie / elm-units-interval / Temperature.Interval

This module behaves much like Quantity.Interval, but works on Temperature values.


type Interval

Represents a finite, closed interval with a minimum and maximum temperature, for example the interval from 20 to 30 degrees Celsius.

Constructors

fromEndpoints : ( Temperature, Temperature ) -> Interval

Construct an interval from its endpoints (the minimum and maximum temperatures of the interval). The two values should be given in order but will be swapped if necessary to ensure a valid interval is returned.

singleton : Temperature -> Interval

Construct a zero-width interval containing a single temperature.

Hull

These functions let you construct an Interval containing one or more input temperatures.

hull2 : Temperature -> Temperature -> Interval

Construct an interval with the two given endpoints (which can be provided in either order).

hull : Temperature -> List Temperature -> Interval

Construct an interval containing one or more input temperatures.

hullN : List Temperature -> Maybe Interval

Construct an interval containing all temperatures in the given list. If the list is empty, returns Nothing.

hullOf : (a -> Temperature) -> a -> List a -> Interval

Like hull, but lets you work on any kind of item as long as a Temperature can be extracted from it:

type alias WeatherMeasurement =
    { windSpeed : Speed
    , temperature : Temperature
    , barometricPressure : Pressure
    }

temperatureRange =
    Temperature.Interval.hullOf .temperature <|
        measurement1
        [ measurement2
        , measurement3
        , measurement4
        ]

hullOfN : (a -> Temperature) -> List a -> Maybe Interval

Combination of hullOf and hullN.

Aggregation

These functions let you 'aggregate' one or more temperature intervals into a single larger interval that contains all of them.

aggregate2 : Interval -> Interval -> Interval

Construct an interval containing both of the given intervals.

aggregate : Interval -> List Interval -> Interval

Construct an interval containing one or more given intervals.

aggregateN : List Interval -> Maybe Interval

Construct an interval containing all of the intervals in the given list. If the list is empty, returns Nothing.

aggregateOf : (a -> Interval) -> a -> List a -> Interval

Like aggregate, but lets you work on any kind of item as long as a temperature interval can be generated from it (similar to hullOf).

aggregateOfN : (a -> Interval) -> List a -> Maybe Interval

Combination of aggregateOf and aggregateN.

Properties

endpoints : Interval -> ( Temperature, Temperature )

Get the endpoints of an interval (its minimum and maximum temperatures) as a tuple. The first temperature will always be less than or equal to the second.

minValue : Interval -> Temperature

Get the minimum temperature of an interval.

maxValue : Interval -> Temperature

Get the maximum temperature of an interval.

midpoint : Interval -> Temperature

Get the midpoint of an interval.

width : Interval -> Temperature.Delta

Get the width of an interval. This will never be negative. Note that this returns a Temperature.Delta, not a Temperature.

Queries

contains : Temperature -> Interval -> Basics.Bool

Check if an interval contains a given temperature. The minimum and maximum temperatures of the interval are considered to be contained in the interval.

isContainedIn : Interval -> Interval -> Basics.Bool

Check if the second interval is fully contained in the first.

intersects : Interval -> Interval -> Basics.Bool

Check if two intervals touch or overlap (have any temperatures in common). Intervals that just touch each other are considered to intersect.

intersection : Interval -> Interval -> Maybe Interval

Attempt to construct an interval containing all the temperatures common to both given intervals. If the intervals do not intersect, returns Nothing. If the two intervals just touch, a singleton interval will be returned.

isSingleton : Interval -> Basics.Bool

Check if the interval is a singleton (the minimum and maximum temperatures are the same).

Interpolation

interpolate : Interval -> Basics.Float -> Temperature

Interpolate between an interval's endpoints; a value of 0.0 corresponds to the minimum temperature of the interval, a value of 0.5 corresponds to its midpoint and a value of 1.0 corresponds to its maximum temperature. Values less than 0.0 or greater than 1.0 can be used to extrapolate.

interpolationParameter : Interval -> Temperature -> Basics.Float

Given an interval and a given value, determine the corresponding interpolation parameter (the parameter that you would pass to interpolate to get the given value).

Arithmetic

plus : Temperature.Delta -> Interval -> Interval

Add a temperature delta to a temperature interval, resulting in a new temperature interval.

temperatureInterval =
    Temperature.Interval.fromEndpoints
        ( Temperature.degreesCelsius 20
        , Temperature.degreesCelsius 25
        )

temperatureInterval
    |> Temperature.Interval.plus
        (Temperature.celsiusDegrees 10)
--> Temperature.Interval.fromEndpoints
-->     ( Temperature.degreesCelsius 30
-->     , Temperature.degreesCelsius 35
-->     )

plusInterval : Quantity.Interval.Interval Basics.Float Temperature.CelsiusDegrees -> Interval -> Interval

Add a temperature delta interval to a temperature interval to give a new temperature interval:

temperatureInterval =
    Temperature.Interval.fromEndpoints
        ( Temperature.degreesCelsius 20
        , Temperature.degreesCelsius 25
        )

deltaInterval =
    Quantity.Interval.fromEndpoints
        ( Temperature.celsiusDegrees -1
        , Temperature.celsiusDegrees 4
        )

temperatureInterval
    |> Temperature.Interval.plus deltaInterval
--> Temperature.Interval.fromEndpoints
-->     ( Temperature.degreesCelsius 19
-->     , Temperature.degreesCelsius 29
-->     )

minusInterval : Interval -> Interval -> Quantity.Interval.Interval Basics.Float Temperature.CelsiusDegrees

Subtract the first given temperature interval from the second, resulting in a temperature delta interval:

firstInterval =
    Temperature.Interval.fromEndpoints
        ( Temperature.degreesCelsius 5
        , Temperature.degreesCelsius 10
        )

secondInterval =
    Temperature.Interval.fromEndpoints
        ( Temperature.degreesCelsius 30
        , Temperature.degreesCelsius 40
        )

secondInterval
    |> Temperature.Interval.minus firstInterval
--> Quantity.Interval.fromEndpoints
-->     ( Temperature.celsiusDegrees 20
-->     , Temperature.celsiusDegrees 35
-->     )

Deprecated

from : Temperature -> Temperature -> Interval

Deprecated alias of hull2.

union : Interval -> Interval -> Interval

Deprecated alias of aggregate2.