MCPcopy Create free account
hub / github.com/microsoft/SandDance / resampleLineTo

Function resampleLineTo

docs/tests/v2/es6/js/sanddance.js:116359–116387  ·  view source on GitHub ↗
(x0, y0, lambda0, a0, b0, c0, x1, y1, lambda1, a1, b1, c1, depth, stream)

Source from the content-addressed store, hash-verified

116357
116358function resample(project, delta2) {
116359 function resampleLineTo(x0, y0, lambda0, a0, b0, c0, x1, y1, lambda1, a1, b1, c1, depth, stream) {
116360 var dx = x1 - x0,
116361 dy = y1 - y0,
116362 d2 = dx * dx + dy * dy;
116363
116364 if (d2 > 4 * delta2 && depth--) {
116365 var a = a0 + a1,
116366 b = b0 + b1,
116367 c = c0 + c1,
116368 m = (0, _math.sqrt)(a * a + b * b + c * c),
116369 phi2 = (0, _math.asin)(c /= m),
116370 lambda2 = (0, _math.abs)((0, _math.abs)(c) - 1) < _math.epsilon || (0, _math.abs)(lambda0 - lambda1) < _math.epsilon ? (lambda0 + lambda1) / 2 : (0, _math.atan2)(b, a),
116371 p = project(lambda2, phi2),
116372 x2 = p[0],
116373 y2 = p[1],
116374 dx2 = x2 - x0,
116375 dy2 = y2 - y0,
116376 dz = dy * dx2 - dx * dy2;
116377
116378 if (dz * dz / d2 > delta2 // perpendicular projected distance
116379 || (0, _math.abs)((dx * dx2 + dy * dy2) / d2 - 0.5) > 0.3 // midpoint close to an end
116380 || a0 * a1 + b0 * b1 + c0 * c1 < cosMinDistance) {
116381 // angular distance
116382 resampleLineTo(x0, y0, lambda0, a0, b0, c0, x2, y2, lambda2, a /= m, b /= m, c, depth, stream);
116383 stream.point(x2, y2);
116384 resampleLineTo(x2, y2, lambda2, a, b, c, x1, y1, lambda1, a1, b1, c1, depth, stream);
116385 }
116386 }
116387 }
116388
116389 return function (stream) {
116390 var lambda00, x00, y00, a00, b00, c00, // first point

Callers 2

linePointFunction · 0.70
ringEndFunction · 0.70

Calls 1

projectFunction · 0.70

Tested by

no test coverage detected