Curves in elm-geometry
are parameterized
by a value that ranges from 0 to 1. A value of 0 corresponds to the start point
of the curve and a value of 1 corresponds to the end point. This module contains
functionality for:
A parameter value between 0 and 1. Curve types such as Arc2d
and
CubicSpline3d
use ParameterValue
arguments for curve
evaluation functions such as Arc2d.pointOn
and
CubicSpline3d.samplesAt
.
zero : ParameterValue
The parameter value 0.
ParameterValue.value ParameterValue.zero
--> 0
half : ParameterValue
The parameter value 0.5.
ParameterValue.value ParameterValue.half
--> 0.5
one : ParameterValue
The parameter value 1.
ParameterValue.value ParameterValue.one
--> 1
Float
valuesvalue : ParameterValue -> Basics.Float
Convert a ParameterValue
to a plain Float
value between 0 and 1.
ParameterValue.value ParameterValue.half
--> 0.5
clamped : Basics.Float -> ParameterValue
Construct a valid parameter value by clamping a plain Float
value to
between 0 and 1.
ParameterValue.value (ParameterValue.clamped 0.75)
--> 0.75
ParameterValue.value (ParameterValue.clamped -0.25)
--> 0
ParameterValue.value (ParameterValue.clamped 1.25)
--> 1
checked : Basics.Float -> Maybe ParameterValue
If the given value is between 0 and 1, return Just
that value as a
ParameterValue
. Otherwise, return Nothing
.
ParameterValue.checked 0.75
|> Maybe.map ParameterValue.value
--> Just 0.75
ParameterValue.checked -0.25
--> Nothing
ParameterValue.checked 1.25
--> Nothing
unsafe : Basics.Float -> ParameterValue
Directly construct a ParameterValue
from a Float
without checking
whether it is valid. ParameterValue.clamped
should generally be used instead,
unless you are very sure you know what you are doing and
profiling/benchmarking shows that ParameterValue.clamped
is a performance
bottleneck.
steps : Basics.Int -> List ParameterValue
Construct a list of parameter values by taking a given number of steps from 0 to 1. Note that the number of returned values will in general be one greater than the number of steps!
ParameterValue.steps 0
--> []
ParameterValue.steps 1
--> [ ParameterValue.zero, ParameterValue.one ]
Parametervalue.steps 2
--> [ ParameterValue.zero
--> , ParameterValue.half
--> , ParameterValue.one
--> ]
ParameterValue.steps 5
|> List.map ParameterValue.value
--> [ 0, 0.2, 0.4, 0.6, 0.8, 1 ]
leading : Basics.Int -> List ParameterValue
Construct a list of parameter values by dividing the range [0,1] into a given number of steps and then returning the value at the beginning of each step.
ParameterValue.leading 0
--> []
ParameterValue.leading 1
--> [ ParameterValue.zero ]
Parametervalue.leading 2
--> [ ParameterValue.zero, ParameterValue.half ]
ParameterValue.leading 5
|> List.map ParameterValue.value
--> [ 0, 0.2, 0.4, 0.6, 0.8 ]
trailing : Basics.Int -> List ParameterValue
Construct a list of parameter values by dividing the range [0,1] into a given number of steps and then returning the value at the end of each step.
ParameterValue.trailing 0
--> []
ParameterValue.trailing 1
--> [ ParameterValue.one ]
Parametervalue.trailing 2
--> [ ParameterValue.half, ParameterValue.one ]
ParameterValue.trailing 5
|> List.map ParameterValue.value
--> [ 0.2, 0.4, 0.6, 0.8, 1 ]
midpoints : Basics.Int -> List ParameterValue
Construct a list of parameter values by dividing the range [0,1] into a given number of steps and then returning the value at the midpoint of each step.
ParameterValue.midpoints 0
--> []
ParameterValue.midpoints 1
--> [ ParameterValue.half ]
ParameterValue.midpoints 2
|> List.map ParameterValue.value
--> [ 0.25, 0.75 ]
ParameterValue.midpoints 5
|> List.map ParameterValue.value
--> [ 0.1, 0.3, 0.5, 0.7, 0.9 ]
range : { numSteps : Basics.Int, includeStart : Basics.Bool, includeEnd : Basics.Bool } -> List ParameterValue
Construct a list of evenly-spaced parameter values between 0 and 1 by specifying:
This is a more general form of steps
, leading
and trailing
; for example,
ParameterValue.steps 10
is equivalent to
ParameterValue.range
{ numSteps = 10
, includeStart = True
, includeEnd = True
}
and
ParameterValue.trailing 10
is equivalent to
ParameterValue.range
{ numSteps = 10
, includeStart = False
, includeEnd = True
}
midpoint : ParameterValue -> ParameterValue -> ParameterValue
Find the midpoint between two parameter values.
ParameterValue.midpoint
ParameterValue.zero
ParameterValue.one
--> ParameterValue.half
oneMinus : ParameterValue -> ParameterValue
Subtract a parameter value from 1 to give a new parameter value.
ParameterValue.oneMinus ParameterValue.one
--> ParameterValue.zero
ParameterValue.oneMinus ParameterValue.zero
--> ParameterValue.one
ParameterValue.oneMinus ParameterValue.half
--> ParameterValue.half
This can be thought of as the 'negation' or 'complement' of a parameter value.
For example, evaluating a reversed curve at a parameter value t
is generally
equivalent to evaluating the original curve at a parameter value
1 - t
, and vice versa.