class Transform
Defined at line 52 of file ../../zircon/system/ulib/affine/include/lib/affine/transform.h
A small helper class which represents a 1 dimensional affine transformation
from a signed 64 bit space A, to a signed 64 bit space B. Conceptually, this
is the function...
f(a) = b = (a * scale) + offset
Internally, however, the exact function used is
f(a) = b = (((a - A_offset) * B_scale) / A_scale) + B_offset
Where the offsets involved are 64 bit signed integers, and the scale factors
are 32 bit unsigned integers.
Overflow/Underflow saturation behavior is as follows.
The transformation operation is divided into three stages.
1) Offset by A_offset
2) Scale by (B_scale / A_scale)
3) Offset by B_offset
Each stage is saturated independently. That is to say, if the result of
stage #1 is clamped at int64::min, this is the input value which will be fed
into stage #2. The calculations are *not* done with infinite precision and
then clamped at the end.
TODO(johngro): Reconsider this. Clamping at intermediate stages can make it
more difficult to understand that saturation happened at all, and might be
important to a client. It may be better to either signal explicitly that
this happened, or to extend the precision of the operation in the rare slow
path so that saturation behavior occurs only at the end of the op, and
produces a correct result if the transform would have saturated at an
intermediate step, but got brought back into range by a subsequent operation.
Saturation is enabled by default, but may be disabled by choosing the
Saturate::No form of Apply/ApplyInverse. When saturation behavior is
disabled, the results of a transformation where over/underflow occurs at any
stage is undefined.
Public Methods
Transform Compose (const Transform & bc, const Transform & ab, Exact exact)
Composes two timeline functions B->C and A->B producing A->C. If exact is
Exact::Yes, DCHECKs on loss of precision.
During composition, the saturation behavior is as follows
1) The intermediate offset (bc.a_offset - ab.b_offset) will be saturated
before distribution to the offsets ac.
2) Both offsets of ac will be saturated as ab.a_offset and bc.b_offset
are combined with the distributed intermediate offset.
Defined at line 9 of file ../../zircon/system/ulib/affine/transform.cc
template <Saturate SATURATE = Saturate::Yes>
int64_t Apply (int64_t a_offset, int64_t b_offset, Ratio ratio, int64_t val)
Applies a transformation from A -> B
Defined at line 59 of file ../../zircon/system/ulib/affine/include/lib/affine/transform.h
template <Saturate SATURATE = Saturate::Yes>
int64_t ApplyInverse (int64_t a_offset, int64_t b_offset, Ratio ratio, int64_t val)
Applies the inverse transformation B -> A
Defined at line 76 of file ../../zircon/system/ulib/affine/include/lib/affine/transform.h
void Transform ()
Default construction is identity
Defined at line 83 of file ../../zircon/system/ulib/affine/include/lib/affine/transform.h
void Transform (int64_t a_offset, int64_t b_offset, Ratio ratio)
Explicit construction
Defined at line 86 of file ../../zircon/system/ulib/affine/include/lib/affine/transform.h
void Transform (Ratio ratio)
Construct a linear transformation (zero offsets) from a ratio
Defined at line 90 of file ../../zircon/system/ulib/affine/include/lib/affine/transform.h
bool invertible ()
Defined at line 92 of file ../../zircon/system/ulib/affine/include/lib/affine/transform.h
int64_t a_offset ()
Defined at line 93 of file ../../zircon/system/ulib/affine/include/lib/affine/transform.h
int64_t b_offset ()
Defined at line 94 of file ../../zircon/system/ulib/affine/include/lib/affine/transform.h
Ratio ratio ()
Defined at line 95 of file ../../zircon/system/ulib/affine/include/lib/affine/transform.h
uint32_t numerator ()
Defined at line 96 of file ../../zircon/system/ulib/affine/include/lib/affine/transform.h
uint32_t denominator ()
Defined at line 97 of file ../../zircon/system/ulib/affine/include/lib/affine/transform.h
Transform Inverse ()
Construct and return a transform which is the inverse of this transform.
Defined at line 100 of file ../../zircon/system/ulib/affine/include/lib/affine/transform.h
template <Saturate SATURATE = Saturate::Yes>
int64_t Apply (int64_t val)
Applies the transformation
Defined at line 104 of file ../../zircon/system/ulib/affine/include/lib/affine/transform.h
template <Saturate SATURATE = Saturate::Yes>
int64_t ApplyInverse (int64_t subject_input)
Applies the inverse transformation
Defined at line 110 of file ../../zircon/system/ulib/affine/include/lib/affine/transform.h
template <Saturate SATURATE = Saturate::Yes>
int64_t operator() (int64_t val)
Applies the transformation using functor operator notation.
Defined at line 117 of file ../../zircon/system/ulib/affine/include/lib/affine/transform.h
Enumerations
enum Saturate
| Name | Value |
|---|---|
| No | 0 |
| Yes | 1 |
Defined at line 55 of file ../../zircon/system/ulib/affine/include/lib/affine/transform.h