MCPcopy Create free account
hub / github.com/VCVRack/Rack / getLineCrossing

Function getLineCrossing

src/window/Svg.cpp:130–139  ·  view source on GitHub ↗

Returns the parameterized value of the line p2--p3 where it intersects with p0--p1 */

Source from the content-addressed store, hash-verified

128
129/** Returns the parameterized value of the line p2--p3 where it intersects with p0--p1 */
130static float getLineCrossing(math::Vec p0, math::Vec p1, math::Vec p2, math::Vec p3) {
131 math::Vec b = p2.minus(p0);
132 math::Vec d = p1.minus(p0);
133 math::Vec e = p3.minus(p2);
134 float m = d.x * e.y - d.y * e.x;
135 // Check if lines are parallel, or if either pair of points are equal
136 if (std::abs(m) < 1e-6)
137 return NAN;
138 return -(d.x * b.y - d.y * b.x) / m;
139}
140
141void svgDraw(NVGcontext* vg, NSVGimage* svg) {
142 DEBUG_ONLY(printf("new image: %g x %g px\n", svg->width, svg->height);)

Callers 1

svgDrawFunction · 0.85

Calls 2

absFunction · 0.85
minusMethod · 0.80

Tested by

no test coverage detected