MCPcopy Create free account
hub / github.com/andrewwillmott/splines-lib / LineError

Function LineError

Splines.cpp:1111–1141  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1109namespace
1110{
1111 float LineError(const Spline2& s) // Calculate line approx error as max distance of hull points p1/p2 from p0_p1
1112 {
1113 Vec2f p0 = { s.xb.x, s.yb.x };
1114 Vec2f p1 = { s.xb.y, s.yb.y };
1115 Vec2f p2 = { s.xb.z, s.yb.z };
1116 Vec2f p3 = { s.xb.w, s.yb.w };
1117
1118 Vec2f w = p3 - p0;
1119 float dww = dot(w, w);
1120
1121 Vec2f v1 = p1 - p0;
1122 float dvw1 = dot(v1, w);
1123 Vec2f v2 = p2 - p0;
1124 float dvw2 = dot(v2, w);
1125
1126 float error;
1127
1128 if (dvw1 <= 0.0f)
1129 error = sqrlen(v1);
1130 else if (dvw1 >= dww)
1131 error = sqrlen(p1 - p3);
1132 else
1133 error = sqrlen((dvw1 / dww) * w - v1);
1134
1135 if (dvw2 <= 0.0f)
1136 return vl_max(error, sqrlen(v2));
1137 else if (dvw2 >= dww)
1138 return vl_max(error, sqrlen(p2 - p3));
1139 else
1140 return vl_max(error, sqrlen((dvw2 / dww) * w - v2));
1141 }
1142}
1143
1144int SL::SplinesToLinesAdaptive(int numSplines, const Spline2 splines[], tEmitLinesFunc2 emitLines, void* context, float tolerance)

Callers 1

Calls 3

dotFunction · 0.85
sqrlenFunction · 0.85
vl_maxFunction · 0.85

Tested by

no test coverage detected