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 213 of file line_simplification.h.

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

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

Referenced by simplifyInternal().

+ Here is the caller graph for this function: