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

Function hull

explainshell/web/static/js/d3.v3.js:3938–4008  ·  view source on GitHub ↗
(data)

Source from the content-addressed store, hash-verified

3936 var x = d3_svg_lineX, y = d3_svg_lineY;
3937 if (arguments.length) return hull(vertices);
3938 function hull(data) {
3939 if (data.length < 3) return [];
3940 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;
3941 if (fx === d3_svg_lineX && y === d3_svg_lineY) vertices = data; else for (i = 0,
3942 vertices = []; i < n; ++i) {
3943 vertices.push([ +fx.call(this, d = data[i], i), +fy.call(this, d, i) ]);
3944 }
3945 for (i = 1; i < n; ++i) {
3946 if (vertices[i][1] < vertices[h][1]) {
3947 h = i;
3948 } else if (vertices[i][1] == vertices[h][1]) {
3949 h = vertices[i][0] < vertices[h][0] ? i : h;
3950 }
3951 }
3952 for (i = 0; i < n; ++i) {
3953 if (i === h) continue;
3954 y1 = vertices[i][1] - vertices[h][1];
3955 x1 = vertices[i][0] - vertices[h][0];
3956 points.push({
3957 angle: Math.atan2(y1, x1),
3958 index: i
3959 });
3960 }
3961 points.sort(function(a, b) {
3962 return a.angle - b.angle;
3963 });
3964 a = points[0].angle;
3965 v = points[0].index;
3966 u = 0;
3967 for (i = 1; i < plen; ++i) {
3968 j = points[i].index;
3969 if (a == points[i].angle) {
3970 x1 = vertices[v][0] - vertices[h][0];
3971 y1 = vertices[v][1] - vertices[h][1];
3972 x2 = vertices[j][0] - vertices[h][0];
3973 y2 = vertices[j][1] - vertices[h][1];
3974 if (x1 * x1 + y1 * y1 >= x2 * x2 + y2 * y2) {
3975 points[i].index = -1;
3976 } else {
3977 points[u].index = -1;
3978 a = points[i].angle;
3979 u = i;
3980 v = j;
3981 }
3982 } else {
3983 a = points[i].angle;
3984 u = i;
3985 v = j;
3986 }
3987 }
3988 stack.push(h);
3989 for (i = 0, j = 0; i < 2; ++j) {
3990 if (points[j].index !== -1) {
3991 stack.push(points[j].index);
3992 i++;
3993 }
3994 }
3995 sp = stack.length;

Callers 1

d3.v3.jsFile · 0.85

Calls 3

d3_functorFunction · 0.85
d3_geom_hullCCWFunction · 0.85
callMethod · 0.45

Tested by

no test coverage detected