MCPcopy Create free account
hub / github.com/idank/explainshell / intersect

Function intersect

explainshell/web/static/js/d3.v3.js:2616–2637  ·  view source on GitHub ↗
(a, b, two)

Source from the content-addressed store, hash-verified

2614 };
2615 }
2616 function intersect(a, b, two) {
2617 var pa = d3_geo_cartesian(a), pb = d3_geo_cartesian(b);
2618 var n1 = [ 1, 0, 0 ], n2 = d3_geo_cartesianCross(pa, pb), n2n2 = d3_geo_cartesianDot(n2, n2), n1n2 = n2[0], determinant = n2n2 - n1n2 * n1n2;
2619 if (!determinant) return !two && a;
2620 var c1 = cr * n2n2 / determinant, c2 = -cr * n1n2 / determinant, n1xn2 = d3_geo_cartesianCross(n1, n2), A = d3_geo_cartesianScale(n1, c1), B = d3_geo_cartesianScale(n2, c2);
2621 d3_geo_cartesianAdd(A, B);
2622 var u = n1xn2, w = d3_geo_cartesianDot(A, u), uu = d3_geo_cartesianDot(u, u), t2 = w * w - uu * (d3_geo_cartesianDot(A, A) - 1);
2623 if (t2 < 0) return;
2624 var t = Math.sqrt(t2), q = d3_geo_cartesianScale(u, (-w - t) / uu);
2625 d3_geo_cartesianAdd(q, A);
2626 q = d3_geo_spherical(q);
2627 if (!two) return q;
2628 var λ0 = a[0], λ1 = b[0], φ0 = a[1], φ1 = b[1], z;
2629 if (λ1 < λ0) z = λ0, λ0 = λ1, λ1 = z;
2630 var δλ = λ1 - λ0, polar = Math.abs(δλ - π) < ε, meridian = polar || δλ < ε;
2631 if (!polar && φ1 < φ0) z = φ0, φ0 = φ1, φ1 = z;
2632 if (meridian ? polar ? φ0 + φ1 > 0 ^ q[1] < (Math.abs(q[0] - λ0) < ε ? φ0 : φ1) : φ0 <= q[1] && q[1] <= φ1 : δλ > π ^ (λ0 <= q[0] && q[0] <= λ1)) {
2633 var q1 = d3_geo_cartesianScale(u, (-w + t) / uu);
2634 d3_geo_cartesianAdd(q1, A);
2635 return [ q, d3_geo_spherical(q1) ];
2636 }
2637 }
2638 function code(λ, φ) {
2639 var r = smallRadius ? radius : π - radius, code = 0;
2640 if (λ < -r) code |= 1; else if (λ > r) code |= 2;

Callers 1

clipLineFunction · 0.85

Calls 6

d3_geo_cartesianFunction · 0.85
d3_geo_cartesianCrossFunction · 0.85
d3_geo_cartesianDotFunction · 0.85
d3_geo_cartesianScaleFunction · 0.85
d3_geo_cartesianAddFunction · 0.85
d3_geo_sphericalFunction · 0.85

Tested by

no test coverage detected