MCPcopy Index your code
hub / github.com/apache/echarts / intersectCurveCircle

Function intersectCurveCircle

src/chart/graph/adjustEdge.ts:31–95  ·  view source on GitHub ↗
(
    curvePoints: number[][],
    center: number[],
    radius: number
)

Source from the content-addressed store, hash-verified

29const v2DistSquare = vec2.distSquare;
30const mathAbs = Math.abs;
31function intersectCurveCircle(
32 curvePoints: number[][],
33 center: number[],
34 radius: number
35) {
36 const p0 = curvePoints[0];
37 const p1 = curvePoints[1];
38 const p2 = curvePoints[2];
39
40 let d = Infinity;
41 let t;
42 const radiusSquare = radius * radius;
43 let interval = 0.1;
44
45 for (let _t = 0.1; _t <= 0.9; _t += 0.1) {
46 v1[0] = quadraticAt(p0[0], p1[0], p2[0], _t);
47 v1[1] = quadraticAt(p0[1], p1[1], p2[1], _t);
48 const diff = mathAbs(v2DistSquare(v1, center) - radiusSquare);
49 if (diff < d) {
50 d = diff;
51 t = _t;
52 }
53 }
54
55 // Assume the segment is monotone,Find root through Bisection method
56 // At most 32 iteration
57 for (let i = 0; i < 32; i++) {
58 // let prev = t - interval;
59 const next = t + interval;
60 // v1[0] = quadraticAt(p0[0], p1[0], p2[0], prev);
61 // v1[1] = quadraticAt(p0[1], p1[1], p2[1], prev);
62 v2[0] = quadraticAt(p0[0], p1[0], p2[0], t);
63 v2[1] = quadraticAt(p0[1], p1[1], p2[1], t);
64 v3[0] = quadraticAt(p0[0], p1[0], p2[0], next);
65 v3[1] = quadraticAt(p0[1], p1[1], p2[1], next);
66
67 const diff = v2DistSquare(v2, center) - radiusSquare;
68 if (mathAbs(diff) < 1e-2) {
69 break;
70 }
71
72 // let prevDiff = v2DistSquare(v1, center) - radiusSquare;
73 const nextDiff = v2DistSquare(v3, center) - radiusSquare;
74
75 interval /= 2;
76 if (diff < 0) {
77 if (nextDiff >= 0) {
78 t = t + interval;
79 }
80 else {
81 t = t - interval;
82 }
83 }
84 else {
85 if (nextDiff >= 0) {
86 t = t - interval;
87 }
88 else {

Callers 1

adjustEdgeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…