FastLED 3.9.15
Loading...
Searching...
No Matches

◆ ToBounds() [2/2]

Transform16 fl::Transform16::ToBounds ( const vec2< alpha16 > & min,
const vec2< alpha16 > & max,
alpha16 rotation = 0 )
static

Definition at line 64 of file transform.cpp.

65 {
66 Transform16 tx;
67 // Compute a Q16 “scale” so that:
68 // (alpha16 * scale) >> 16 == max_value when alpha16==0xFFFF
69 alpha16 scale16 = 0;
70 if (max.x > min.x) {
71 // numerator = max_value * 2^16
72 uint32_t numer = static_cast<uint32_t>(max.x - min.x) << 16;
73 // denom = 0xFFFF; use ceil so 0xFFFF→max_value exactly:
74 uint32_t scale32 = numer / 0xFFFF;
75 scale16 = static_cast<alpha16>(scale32);
76 }
77 tx.scale_x = scale16;
78 if (max.y > min.y) {
79 // numerator = max_value * 2^16
80 uint32_t numer = static_cast<uint32_t>(max.y - min.y) << 16;
81 // denom = 0xFFFF; use ceil so 0xFFFF→max_value exactly:
82 uint32_t scale32 = numer / 0xFFFF;
83 scale16 = static_cast<alpha16>(scale32);
84 }
85 tx.scale_y = scale16;
86 tx.offset_x = min.x;
87 tx.offset_y = min.y;
88 tx.rotation = rotation;
89 return tx;
90}
LIB8STATIC uint16_t scale16(uint16_t i, fract16 scale)
Scale a 16-bit unsigned value by an 16-bit value, which is treated as the numerator of a fraction who...
Definition scale8.h:546
uint16_t alpha16
Definition transform.h:21
Transform16()=default
alpha16 rotation
Definition transform.h:46

References Transform16(), offset_x, offset_y, rotation, scale16(), scale_x, scale_y, fl::vec2< T >::x, and fl::vec2< T >::y.

+ Here is the call graph for this function: