Package org.openjdk.jmc.common.unit
Interface IScalarAffineTransform
-
- All Known Implementing Classes:
BinaryScaleFactor
,DecimalScaleFactor
,ImpreciseScaleFactor
,LongPostOffsetTransform
,LongPreOffsetTransform
,LongScaleFactor
,ScaleFactor
,SimpleAffineTransform
public interface IScalarAffineTransform
A one dimensional affine transform, to be used on numerical quantity values (that is, the numbers in front of a unit). In other words, a transformation for numbers consisting of a linear scaling followed by the addition of an offset. Typically, you request a value transform from a source unit to a target unit.The transform is fully described (apart from numerical precision) by the
multiplier
and theoffset
. These methods are intended for when the transform is to be performed on a large number of primitives and possibly in conjunction with other transformations. A coalesced transformation can then be applied to every primitive, optimally by specialized hardware (like a GPU).
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description IScalarAffineTransform
concat(IScalarAffineTransform innerTransform)
Concatenate this transform withinnerTransform
, such that applying the resulting transform is equivalent to first applyinginnerTransform
and then applying this transform on the resulting value.double
getMultiplier()
Number
getOffset()
IScalarAffineTransform
invert()
IScalarAffineTransform
invertAndConcat(IScalarAffineTransform innerTransform)
Concatenate the inverse of this transform withinnerTransform
, such that applying the resulting transform is equivalent to first applyinginnerTransform
and then applying this inverse of this transform on the resulting value.boolean
isInteger()
boolean
isUnity()
double
targetFloor(double srcNumericalValue)
long
targetFloor(long srcNumericalValue)
int
targetIntFloor(Number srcNumericalValue)
Number
targetNumber(long srcNumericalValue)
Number
targetNumber(Number srcNumericalValue)
boolean
targetOutOfRange(double srcNumericalValue, long maxAbsValue)
boolean
targetOutOfRange(long srcNumericalValue, long maxAbsValue)
double
targetValue(double srcNumericalValue)
long
targetValue(long srcNumericalValue)
-
-
-
Method Detail
-
getOffset
Number getOffset()
- Returns:
- the offset to be added (after the source value has been multiplied with the
multiplier
)
-
getMultiplier
double getMultiplier()
- Returns:
- the multiplier which source values should be multiplied with (before the
offset
is added)
-
targetOutOfRange
boolean targetOutOfRange(long srcNumericalValue, long maxAbsValue)
-
targetOutOfRange
boolean targetOutOfRange(double srcNumericalValue, long maxAbsValue)
-
targetValue
long targetValue(long srcNumericalValue)
- Parameters:
srcNumericalValue
- a numerical quantity value, expressed in the source unit- Returns:
- the corresponding numerical quantity value, when expressed in the target unit,
rounded to the closest integer that can be represented by a
long
-
targetFloor
long targetFloor(long srcNumericalValue)
- Parameters:
srcNumericalValue
- a numerical quantity value, expressed in the source unit- Returns:
- the floor of the corresponding numerical quantity value, when expressed in the target
unit, clamped to a
long
-
targetFloor
double targetFloor(double srcNumericalValue)
- Parameters:
srcNumericalValue
- a numerical quantity value, expressed in the source unit- Returns:
- the floor of the corresponding numerical quantity value, when expressed in the target unit
-
targetIntFloor
int targetIntFloor(Number srcNumericalValue)
- Parameters:
srcNumericalValue
- a numerical quantity value, expressed in the source unit- Returns:
- the floor of the corresponding numerical quantity value, when expressed in the target
unit, clamped to an
int
-
targetNumber
Number targetNumber(long srcNumericalValue)
- Parameters:
srcNumericalValue
- an exact numerical quantity value, expressed in the source unit- Returns:
- the corresponding numerical quantity value, when expressed in the target unit, as a
Long
if it can exactly be represented in one, otherwise as some otherNumber
with at least the precision ofdouble
-
targetNumber
Number targetNumber(Number srcNumericalValue)
- Parameters:
srcNumericalValue
- an exact or inexact numerical quantity value, expressed in the source unit- Returns:
- the corresponding numerical quantity value, when expressed in the target unit, as a
Long
if it can exactly be represented in one, otherwise as some otherNumber
with at least the precision ofdouble
-
targetValue
double targetValue(double srcNumericalValue)
- Parameters:
srcNumericalValue
- a numerical quantity value, expressed in the source unit- Returns:
- the corresponding numerical quantity value, when expressed in the target unit
-
invert
IScalarAffineTransform invert()
- Returns:
- the inverse transform
-
isUnity
boolean isUnity()
- Returns:
- true iff this represents the identity transform
-
isInteger
boolean isInteger()
- Returns:
- true iff this transform can exactly be described by an integer multiplier followed by an integer offset
-
concat
IScalarAffineTransform concat(IScalarAffineTransform innerTransform)
Concatenate this transform withinnerTransform
, such that applying the resulting transform is equivalent to first applyinginnerTransform
and then applying this transform on the resulting value. That is, R(v) = T(I(v)), where R(v) is the resulting transform, T(v) is this transform, and I(v) isinnerTransform
.In this snippet,
v1
andv2
should be equal, apart from numerical precision, for anyv
.IScalarAffineTransform R, T = ..., I = ...; double v = ...; R = T.concat(I); double v1 = R.targetValue(v); double v2 = T.targetValue(I.targetValue(v));
- Parameters:
innerTransform
- the transform that should be applied before this transform- Returns:
- the concatenated transform
-
invertAndConcat
IScalarAffineTransform invertAndConcat(IScalarAffineTransform innerTransform)
Concatenate the inverse of this transform withinnerTransform
, such that applying the resulting transform is equivalent to first applyinginnerTransform
and then applying this inverse of this transform on the resulting value. That is, R(v) = T-1(I(v)), where R(v) is the resulting transform, T-1(v) is the inverse of this transform, and I(v) isinnerTransform
.In this snippet,
v1
andv2
should be equal, apart from numerical precision, for anyv
.IScalarAffineTransform R, T = ..., I = ...; double v = ...; R = T.invertAndConcat(I); double v1 = R.targetValue(v); double v2 = T.invert().targetValue(I.targetValue(v));
- Parameters:
innerTransform
- the transform that should be applied before this transform- Returns:
- the concatenated transform
-
-