MutableMeasure

class MutableMeasure<U : Unit<U>> : Measure<U>

A specialization of Measure that allows for mutability. This is intended to be used for memory use reasons (such as on the memory-restricted roboRIO 1 or 2 or SBC coprocessors) and should NOT be exposed in the public API for a class that uses it.

The advantage of using this class is to reuse one instance of a measurement object, as opposed to instantiating a new immutable instance every time an operation is performed. This will reduce memory pressure, but comes at the cost of increased code complexity and sensitivity to race conditions if misused.

Any unsafe methods are prefixed with mut_*, such as mut_plus or mut_replace. These methods will change the internal state of the measurement object, and as such can be dangerous to use. They are primarily intended for use to track internal state of things like sensors

Since

1.0.0-pre

Parameters

the type of the unit of 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
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

Increments the current magnitude of the measure by the amount of the given measure.

Increments the current magnitude of the measure by the given value. The value must be in terms of the current unit.

Link copied to clipboard

Divides this measurement by some constant value. This will mutate the object instead of generating a new measurement object.

Link copied to clipboard

Subtracts another measurement to this one. This will mutate the object instead of generating a new measurement object.

fun mut_minus(magnitude: Double, unit: U): MutableMeasure<U>

Subtracts another measurement to this one. This will mutate the object instead of generating a new measurement object. This is a denormalized version of mut_minus to avoid having to wrap raw numbers in a Measure object and pay for an object allocation.

Link copied to clipboard

Adds another measurement to this one. This will mutate the object instead of generating a new measurement object.

fun mut_plus(magnitude: Double, unit: U): MutableMeasure<U>

Adds another measurement to this one. This will mutate the object instead of generating a new measurement object. This is a denormalized version of mut_plus to avoid having to wrap raw numbers in a Measure object and pay for an object allocation.

Link copied to clipboard

Overwrites the state of this measure and replaces it with values from the given one.

fun mut_replace(magnitude: Double, unit: U): MutableMeasure<U>

Overwrites the state of this measure with new values.

Link copied to clipboard
fun mut_setBaseUnitMagnitude(baseUnitMagnitude: Double)

Sets the new magnitude of the measurement. The magnitude must be in terms of the base unit of the current unit.

Link copied to clipboard
fun mut_setMagnitude(magnitude: Double)

Sets the new magnitude of the measurement. The magnitude must be in terms of the unit.

Link copied to clipboard
fun mut_times(multiplier: Double): MutableMeasure<U>

Multiplies this measurement by some constant value. This will mutate the object instead of generating a new measurement object.

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.