replacement for fastled sqrt16() (#4426)
* added bitwise operation based sqrt16 - replacement for fastled, it is about 10% slower for numbers smaller 128 but faster for larger numbers. speed difference is irrelevant to WLED but it saves some flash. * updated to 32bit, improved for typical WLED use - making it 32bits allows for larger numbers - added another initial condition check for medium sized numbers - increased the "small number" optimization to larger numbers: the function is currently only used to calculate sqrt(x^2+y^2) which even for small segments is larger than the initially used 64, so optimizing for 1024 makes more sense, although the value is arbitrarily chosen
This commit is contained in:
@@ -5446,15 +5446,15 @@ uint16_t mode_2Dmetaballs(void) { // Metaballs by Stefan Petrick. Cannot have
|
||||
// and add them together with weightening
|
||||
unsigned dx = abs(x - x1);
|
||||
unsigned dy = abs(y - y1);
|
||||
unsigned dist = 2 * sqrt16((dx * dx) + (dy * dy));
|
||||
unsigned dist = 2 * sqrt32_bw((dx * dx) + (dy * dy));
|
||||
|
||||
dx = abs(x - x2);
|
||||
dy = abs(y - y2);
|
||||
dist += sqrt16((dx * dx) + (dy * dy));
|
||||
dist += sqrt32_bw((dx * dx) + (dy * dy));
|
||||
|
||||
dx = abs(x - x3);
|
||||
dy = abs(y - y3);
|
||||
dist += sqrt16((dx * dx) + (dy * dy));
|
||||
dist += sqrt32_bw((dx * dx) + (dy * dy));
|
||||
|
||||
// inverse result
|
||||
int color = dist ? 1000 / dist : 255;
|
||||
|
||||
Reference in New Issue
Block a user