Common methods and helpers to implement the RangeType interface
- Source
Methods
(static) compare()
Basic implementation of RangeType.compare. This uses the numeric difference for distance
, and the sign of that value for side
. The inputs are coerced to numbers prior to calculation.
This isn't useful on its own (technically a normalized, real type) but can be used to build other types.
- Source
(static) compareBinarySearch(type, subclassopt) → {RangeType}
Simple decorator that forces the RangeType.compare method to opt in to binary search, rather than interpolation search. It does this by forcing non-zero distance
to have the same magnitude.
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
type | RangeType | the type whose RangeType.compare method should be wrapped | ||
subclass | boolean | <optional> | true | if true, a new RangeType is created that extends |
- Source
depending on the value of extend
, either type
or a new type that inherits from type
- Type:
- RangeType
(static) compareEpsilon(epsilon, type, subclassopt) → {RangeType}
Simple decorator that adds fuzzy comparison to an existing RangeType. This causes ranges to be merged if their endpoints are within epsilon
distance. It can be especially useful if using RealType or FloatNormType, where imprecision in floating point arithmetic can mean adjacent ranges don't quite line up.
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
epsilon | number | the absolute threshold at which RangeType~CompareResult | ||
type | RangeType | the type whose RangeType.compare method should be wrapped | ||
subclass | boolean | <optional> | true | if true, a new RangeType is created that extends |
- Source
depending on the value of extend
, either type
or a new type that inherits from type
- Type:
- RangeType
(static) copy()
Basic implementation of RangeType.copy. This uses Object.assign
to copy the object
- Source
(static) create(start, end, startExclnullable, endExclnullable) → {Range}
Basic implementation of RangeType.create. This uses RangeType.setStart and RangeType.setEnd to initialize the range.
Name | Type | Attributes | Description |
---|---|---|---|
start | any | starting bound | |
end | any | ending bound | |
startExcl | boolean | <nullable> | whether starting bound is exclusive |
endExcl | boolean | <nullable> | whether ending bound is exclusive |
- Source
- Type:
- Range
(static) setEnd()
Basic implementation of RangeType.setEnd. This deletes Range#endExcl, rather than set it to false
- Source
(static) setStart()
Basic implementation of RangeType.setStart. This deletes Range#startExcl, rather than set it to false
- Source
(static) size()
Basic implementation of RangeType.size. This simply takes the difference in Range#end and Range#start, with values coerced to numbers. This is suitable for continuous types, but not for discrete.
- Source