MCPcopy
hub / github.com/jipegit/OSXAuditor / hull

Function hull

d3-3.2.8/d3.js:4252–4313  ·  view source on GitHub ↗
(data)

Source from the content-addressed store, hash-verified

4250 var x = d3_svg_lineX, y = d3_svg_lineY;
4251 if (arguments.length) return hull(vertices);
4252 function hull(data) {
4253 if (data.length < 3) return [];
4254 var fx = d3_functor(x), fy = d3_functor(y), n = data.length, vertices, plen = n - 1, points = [], stack = [], d, i, j, h = 0, x1, y1, x2, y2, u, v, a, sp;
4255 if (fx === d3_svg_lineX && y === d3_svg_lineY) vertices = data; else for (i = 0,
4256 vertices = []; i < n; ++i) {
4257 vertices.push([ +fx.call(this, d = data[i], i), +fy.call(this, d, i) ]);
4258 }
4259 for (i = 1; i < n; ++i) {
4260 if (vertices[i][1] < vertices[h][1] || vertices[i][1] == vertices[h][1] && vertices[i][0] < vertices[h][0]) h = i;
4261 }
4262 for (i = 0; i < n; ++i) {
4263 if (i === h) continue;
4264 y1 = vertices[i][1] - vertices[h][1];
4265 x1 = vertices[i][0] - vertices[h][0];
4266 points.push({
4267 angle: Math.atan2(y1, x1),
4268 index: i
4269 });
4270 }
4271 points.sort(function(a, b) {
4272 return a.angle - b.angle;
4273 });
4274 a = points[0].angle;
4275 v = points[0].index;
4276 u = 0;
4277 for (i = 1; i < plen; ++i) {
4278 j = points[i].index;
4279 if (a == points[i].angle) {
4280 x1 = vertices[v][0] - vertices[h][0];
4281 y1 = vertices[v][1] - vertices[h][1];
4282 x2 = vertices[j][0] - vertices[h][0];
4283 y2 = vertices[j][1] - vertices[h][1];
4284 if (x1 * x1 + y1 * y1 >= x2 * x2 + y2 * y2) {
4285 points[i].index = -1;
4286 continue;
4287 } else {
4288 points[u].index = -1;
4289 }
4290 }
4291 a = points[i].angle;
4292 u = i;
4293 v = j;
4294 }
4295 stack.push(h);
4296 for (i = 0, j = 0; i < 2; ++j) {
4297 if (points[j].index > -1) {
4298 stack.push(points[j].index);
4299 i++;
4300 }
4301 }
4302 sp = stack.length;
4303 for (;j < plen; ++j) {
4304 if (points[j].index < 0) continue;
4305 while (!d3_geom_hullCCW(stack[sp - 2], stack[sp - 1], points[j].index, vertices)) {
4306 --sp;
4307 }
4308 stack[sp++] = points[j].index;
4309 }

Callers 2

d3.jsFile · 0.85
hull-test.jsFile · 0.85

Calls 2

d3_functorFunction · 0.85
d3_geom_hullCCWFunction · 0.85

Tested by

no test coverage detected