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

◆ PerpendicularDistance2()

template<typename NumberT = float>
static NumberT fl::LineSimplifier< NumberT >::PerpendicularDistance2 ( const Point & pt,
const Point & a,
const Point & b )
inlinestaticprivate

Definition at line 212 of file line_simplification.h.

213 {
214 // vector AB
215 NumberT dx = b.x - a.x;
216 NumberT dy = b.y - a.y;
217 // vector AP
218 NumberT vx = pt.x - a.x;
219 NumberT vy = pt.y - a.y;
220
221 // squared length of AB
222 NumberT len2 = dx * dx + dy * dy;
223 if (len2 <= NumberT(0)) {
224 // A and B coincide — just return squared dist from A to P
225 return vx * vx + vy * vy;
226 }
227
228 // cross‐product magnitude (AB × AP) in 2D is (dx*vy − dy*vx)
229 NumberT cross = dx * vy - dy * vx;
230 // |cross|/|AB| is the perpendicular distance; we want squared:
231 return (cross * cross) / len2;
232 }

References fl::vec2< T >::x, and fl::vec2< T >::y.

Referenced by simplifyInternal().

+ Here is the caller graph for this function: