MCPcopy Create free account
hub / github.com/OneLoneCoder/olcPixelGameEngine / coefficients

Method coefficients

utilities/olcUTIL_Geometry2D.h:618–632  ·  view source on GitHub ↗

Returns line equation "mx + a" coefficients where: x: m y: a NOTE: Returns {inf, inf} if std::abs(end.x - start.x) < epsilon:

Source from the content-addressed store, hash-verified

616 // y: a
617 // NOTE: Returns {inf, inf} if std::abs(end.x - start.x) < epsilon:
618 inline constexpr olc::vd2d coefficients() const
619 {
620 double x1 = start.x;
621 double x2 = end.x;
622 double y1 = start.y;
623 double y2 = end.y;
624
625 // check if line is vertical or close to vertical
626 if (std::abs(x2 - x1) < epsilon) {
627 return olc::vd2d{ std::numeric_limits<double>::infinity(), std::numeric_limits<double>::infinity() };
628 }
629
630 double m = (y2 - y1) / (x2 - x1);
631 return olc::vd2d{ m, -m * x1 + y1 };
632 }
633 };
634
635 template<typename T>

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected