FastLED 3.10.8
Loading...
Searching...
No Matches

◆ seti16()

void fl::WaveSimulation2D::seti16 ( fl::size x,
fl::size y,
i16 value )

Definition at line 161 of file wave_simulation.cpp.hpp.

161 {
162 if (!has(x, y))
163 return;
164
165 u8 mult = fl::max(1, mMultiplier);
166
167 // radius in pixels of your diamond
168 int rad = static_cast<int>(mult) / 2;
169
170 for (fl::size j = 0; j < mult; ++j) {
171 for (fl::size i = 0; i < mult; ++i) {
172 // compute offset from the center of this block
173 int dx = static_cast<int>(i) - rad;
174 int dy = static_cast<int>(j) - rad;
175 // keep only those points whose Manhattan distance ≤ rad
176 if (fl::abs(dx) + fl::abs(dy) > rad) {
177 continue;
178 }
179 fl::size xx = x * mult + i;
180 fl::size yy = y * mult + j;
181 if (mSim->has(xx, yy)) {
182 if (mUseChangeGrid) {
183 i16 &pt = mChangeGrid.at(xx, yy);
184 if (pt == 0) {
185 // not set yet so set unconditionally.
186 pt = v16;
187 } else {
188 const bool sign_matches = (pt >= 0) == (v16 >= 0);
189 if (!sign_matches) {
190 // opposite signs, so overwrite
191 pt = v16;
192 } else {
193 // if the magnitude of the new pt is greater than what
194 // was already there, then overwrite.
195 u16 abs_pt = static_cast<u16>(fl::abs(pt));
196 u16 abs_v16 = static_cast<u16>(fl::abs(v16));
197 if (abs_v16 > abs_pt) {
198 pt = v16;
199 }
200 }
201 }
202 } else {
203 // Directly set the value in the simulation when change grid is disabled
204 mSim->seti16(xx, yy, v16);
205 }
206 }
207 }
208 }
209}
bool has(fl::size x, fl::size y) const FL_NO_EXCEPT
fl::Grid< i16 > mChangeGrid
fl::unique_ptr< WaveSimulation2D_Real > mSim
unsigned char u8
Definition stdint.h:131
constexpr common_type_t< T, U > max(T a, U b) FL_NO_EXCEPT
Definition math.h:75
constexpr enable_if< is_fixed_point< T >::value, T >::type abs(T x) FL_NO_EXCEPT

References fl::abs(), fl::FL_NO_EXCEPT, has(), fl::max(), mChangeGrid, mMultiplier, mSim, mUseChangeGrid, fl::x, and fl::y.

Referenced by setf().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: