MCPcopy Create free account
hub / github.com/plotly/plotly.js / makeClippedPolygon

Function makeClippedPolygon

src/plots/polar/helpers.js:122–170  ·  view source on GitHub ↗
(r, a0, a1, vangles)

Source from the content-addressed store, hash-verified

120}
121
122function makeClippedPolygon(r, a0, a1, vangles) {
123 var len = vangles.length;
124 var vertices = [];
125 var i, j;
126
127 function a2xy(a) {
128 return [r * Math.cos(a), r * Math.sin(a)];
129 }
130
131 function findXY(va0, va1, s) {
132 return findIntersectionXY(va0, va1, s, a2xy(va0));
133 }
134
135 function cycleIndex(ind) {
136 return Lib.mod(ind, len);
137 }
138
139 function isInside(v) {
140 return isAngleInsideSector(v, [a0, a1]);
141 }
142
143 // find index in sector closest to a0
144 // use it to find intersection of v[i0] <-> v[i0-1] edge with sector radius
145 var i0 = findIndexOfMin(vangles, function(v) {
146 return isInside(v) ? angleDist(v, a0) : Infinity;
147 });
148 var xy0 = findXY(vangles[i0], vangles[cycleIndex(i0 - 1)], a0);
149 vertices.push(xy0);
150
151 // fill in in-sector vertices
152 for(i = i0, j = 0; j < len; i++, j++) {
153 var va = vangles[cycleIndex(i)];
154 if(!isInside(va)) break;
155 vertices.push(a2xy(va));
156 }
157
158 // find index in sector closest to a1,
159 // use it to find intersection of v[iN] <-> v[iN+1] edge with sector radius
160 var iN = findIndexOfMin(vangles, function(v) {
161 return isInside(v) ? angleDist(v, a1) : Infinity;
162 });
163 var xyN = findXY(vangles[iN], vangles[cycleIndex(iN + 1)], a1);
164 vertices.push(xyN);
165
166 vertices.push([0, 0]);
167 vertices.push(vertices[0].slice());
168
169 return vertices;
170}
171
172function makePolygon(r, a0, a1, vangles) {
173 return Lib.isFullCircle([a0, a1]) ?

Callers 1

makePolygonFunction · 0.85

Calls 5

isInsideFunction · 0.85
angleDistFunction · 0.85
findXYFunction · 0.85
cycleIndexFunction · 0.85
a2xyFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…