ianmackenzie/elm-units-interval/2.2.1

NOTE: the latest version is 3.2.0

Temperature.Interval

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

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

Constructors

from : Temperature -> Temperature -> Interval

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

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.

Booleans

Construct an interval containing both of the given intervals.

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.

Hull

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

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.

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 -> 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 -> 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.

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

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

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

Interpolation

interpolate : Interval -> 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 -> 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

add : Delta -> Interval -> Interval

Add a temperature delta to a temperature interval.

subtract : Delta -> Interval -> Interval

Subtract a temperature delta from a temperature interval.

The plus and minus functions both involve Interval Float CelsiusDegrees values, where Interval in this case refers to the type in the Quantity.Interval module. This represents an interval of temperature deltas.

plus : Interval Float CelsiusDegrees -> Interval -> Interval

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

temperatureInterval =
    Temperature.Interval.from
        (Temperature.degreesCelsius 20)
        (Temperature.degreesCelsius 25)


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


temperatureInterval
    |> Temperature.Interval.plus deltaInterval
--> Temperature.Interval.from
-->     (Temperature.degreesCelsius 19)
-->     (Temperature.degreesCelsius 29)
minus : Interval -> Interval -> Interval Float CelsiusDegrees

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

firstInterval =
    Temperature.Interval.from
        (Temperature.degreesCelsius 5)
        (Temperature.degreesCelsius 10)


secondInterval =
    Temperature.Interval.from
        (Temperature.degreesCelsius 30)
        (Temperature.degreesCelsius 40)


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