ImmutableMeasure

A measure holds the magnitude and unit of some dimension, such as distance, time, or speed. An immutable measure is immutable and type safe, making it easy to use in concurrent situations and gives compile-time safety. Two measures with the same unit and magnitude are effectively equivalent objects.

Since

1.0.0-pre

Parameters

the unit type of the measure

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
open override fun baseUnitMagnitude(): Double

Gets the magnitude of this measure in terms of the base unit. If the unit is the base unit for its system of measure, then the value will be equivalent to magnitude.

Link copied to clipboard
open override fun copy(): Measure<U>

Returns an immutable copy of this measure. The copy can be used freely and is guaranteed never to change.

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean

Checks for object equality. To check if two measures are equivalent, use isEquivalent.

Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard
open override fun magnitude(): Double

Gets the unitless magnitude of this measure.

Link copied to clipboard
open override fun toString(): String
Link copied to clipboard
open override fun unit(): U

Gets the units of this measure.

Inherited functions

Link copied to clipboard
open infix operator override fun compareTo(other: Measure<U>): Int
Link copied to clipboard

Calculates the shortest difference between two given angles.

Link copied to clipboard
open operator fun <U2 : Unit<U2>> div(other: Measure<U2>): Measure<*>

Divides this measurement by another measure and performs some dimensional analysis to reduce the units.

open operator fun div(divisor: Double): Measure<U>

Divides this measurement by some constant divisor and returns the result. This is equivalent to times(1 / divisor)

Link copied to clipboard
open infix fun gt(o: Measure<U>): Boolean

Checks if this measure is greater than another measure of the same unit.

Link copied to clipboard
open infix fun gte(o: Measure<U>): Boolean

Checks if this measure is greater than or equivalent to another measure of the same unit.

Link copied to clipboard
open infix fun in(unit: Unit<U>): Double

Converts this measure to a measure with a different unit of the same type, eg minutes to seconds. Converting to the same unit is equivalent to calling magnitude.

Link copied to clipboard
open infix fun isEquivalent(other: Measure<*>): Boolean

Checks if this measure is equivalent to another measure of the same unit.

Link copied to clipboard
open infix fun Measure<*>.isNear(varianceThreshold: Double): Boolean

Checks if this measure is near another measure of the same unit. Provide a variance threshold for use for a +/- scalar, such as 0.05 for +/- 5%.

open infix fun Measure<U>.isNear(tolerance: Measure<U>): Boolean

Checks if this measure is near another measure of the same unit, with a specified tolerance of the same unit.

Link copied to clipboard
open infix fun lt(o: Measure<U>): Boolean

Checks if this measure is less than another measure of the same unit.

Link copied to clipboard
open infix fun lte(o: Measure<U>): Boolean

Checks if this measure is less than or equivalent to another measure of the same unit.

Link copied to clipboard
open operator fun minus(other: Measure<U>): Measure<U>

Subtracts another measure from this one. The resulting measure has the same unit as this one.

Link copied to clipboard

Same as moveTowards, but makes sure the values interpolate correctly when they wrap around 1 revolution (360 degrees).

Link copied to clipboard

Creates a new mutable copy of this measure.

Link copied to clipboard
open fun negate(): Measure<U>

Negates this measure and returns the result.

Link copied to clipboard
open infix fun <U2 : Unit<U2>> per(denominator: U2): Measure<Per<U, U2>>

Creates a relational measure equivalent to this one per some other unit.

open infix fun per(period: Measure<Time>): Measure<Velocity<U>>

Creates a velocity measure by dividing this one by a time period measure.

open infix fun per(time: Time): Measure<Velocity<U>>

Creates a velocity measure equivalent to this one per a unit of time.

Link copied to clipboard
open operator fun plus(other: Measure<U>): Measure<U>

Adds another measure to this one. The resulting measure has the same unit as this one.

Link copied to clipboard
fun Measure<Angle>.smoothDamp(target: Measure<Angle>, currentVelocity: Reference<Double>, smoothTime: Measure<Time>, maxVelocity: Number, deltaTime: Measure<Time>): Measure<Angle>

Gradually changes an angle towards a desired goal over time.

Link copied to clipboard
open operator fun <U2 : Unit<U2>> times(other: Measure<U2>): Measure<*>

Generates a new measure that is equal to this measure multiplied by another. Some dimensional analysis is performed to reduce the units down somewhat; for example, multiplying a Measure<Time> by a Measure<Velocity<Distance>> will return just a Measure<Distance> instead of the naive Measure<Mult<Time, Velocity<Distance>>. This is not guaranteed to perform perfect dimensional analysis.

open operator fun times(multiplier: Double): Measure<U>

Multiplies this measurement by some constant multiplier and returns the result. The magnitude of the result will be the base magnitude multiplied by the scalar value. If the measure uses a unit with a non-linear relation to its base unit (such as Fahrenheit for temperature), then the result will only be a multiple in terms of the base unit.

Link copied to clipboard
open infix fun to(unit: Unit<U>): Double

Converts this measure to a measure with a different unit of the same type, eg minutes to seconds. Converting to the same unit is equivalent to calling magnitude.

Link copied to clipboard
open fun toLongString(): String

Returns a string representation of this measurement in a longhand form. The name of the backing unit is used, rather than its symbol, and the magnitude is represented in a full string, not scientific notation. (Very large values may be represented in scientific notation, however)

Link copied to clipboard

Returns a string representation of this measurement in a scientific shorthand form. The symbol of the backing unit is used, rather than the full name, and the magnitude is represented in scientific notation.

Link copied to clipboard
open fun toShortString(): String

Returns a string representation of this measurement in the default form. The symbol of the backing unit is used, rather than the full name, and the magnitude is represented in full, not in scientific notation. (Very large values may be represented in scientific notation, however)

Link copied to clipboard
open operator fun unaryMinus(): Measure<U>

Negates this measure and returns the result.

Link copied to clipboard

Normalizes the given angle to be within the range of [0, 2pi) radians or [0, 360) degrees.

Link copied to clipboard

Wraps an angle to the range -pi to pi radians.