PerUnit

open class PerUnit<N : Unit<N>, D : Unit<D>> : Unit<PerUnit<N, D>> (source)

Represents a unit that is the ratio of two other units (e.g., meters per second, degrees per second).

The PerUnit automatically normalizes to use base units for internal calculations. For example, if you create a PerUnit with Miles and Hours, it internally works with Meters and Seconds (the base units), ensuring that conversions work correctly.

Parameters

numerator

the numerator unit (e.g., Meters, Miles)

denominator

the denominator unit (e.g., Seconds, Hours)

Type Parameters

N

the type of the numerator unit

D

the type of the denominator unit

Inheritors

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

The base PerUnit using the base units of both numerator and denominator. For example, Miles per Hour would have a basePerUnit of Meters per Second.

Link copied to clipboard

The base unit for this unit's measurement system. This is found by traversing the parent chain until reaching a unit with no parent. For example:

Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean
Link copied to clipboard
fun equivalent(other: Unit<*>): Boolean

Checks if this unit is equivalent to another one. Equivalence is determined by both units having the same base type and treat the same base unit magnitude as the same magnitude in their own units, to within Measure.EQUIVALENCE_THRESHOLD.

Link copied to clipboard
fun fromBaseUnits(valueInBaseUnits: Double): Double

Converts a value in terms of base units to a value in terms of this unit.

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

Checks if this unit is the base unit for its own system of measurement.

Link copied to clipboard
fun name(): String

Gets the name of this unit.

Link copied to clipboard
open override fun of(magnitude: Double): Per<N, D>

Creates a new immutable measurement of the given magnitude in terms of this unit. Implementations are strongly recommended to sharpen the return type to a unit-specific measurement implementation.

Link copied to clipboard
open override fun ofBaseUnits(baseUnitMagnitude: Double): Per<N, D>

Creates a new immutable measurement of the given magnitude in terms of this unit's base unit. Implementations are strongly recommended to sharpen the return type to a unit-specific measurement implementation.

Link copied to clipboard
open fun one(): Measure<PerUnit<N, D>>

Gets a measure with a magnitude of 1.0 in terms of this unit. The returned object is guaranteed to be of the same type returned by of. Subclasses are encouraged to override this method to sharpen the return type.

Link copied to clipboard
open override fun per(time: TimeUnit): PerUnit<PerUnit<N, D>, TimeUnit>

Combines this unit with a unit of time. This often - but not always - results in a velocity. Subclasses should sharpen the return type to be unit-specific.

Link copied to clipboard
fun symbol(): String

Gets the symbol of this unit.

Link copied to clipboard
fun toBaseUnits(valueInNativeUnits: Double): Double

Converts a value in terms of this unit to a value in terms of the base unit.

Link copied to clipboard
open override fun toString(): String
Link copied to clipboard
open fun zero(): Measure<PerUnit<N, D>>

Gets a measure of zero magnitude in terms of this unit. The returned object is guaranteed to be of the same type returned by of. Subclasses are encouraged to override this method to sharpen the return type.