fix(mode/rotate): polygonHull sometimes returns array of length 2 which polygonCentroid cannot handle

This commit is contained in:
hack.ily
2019-10-27 23:51:51 -07:00
committed by Bryan Housel
parent dd10f4f891
commit b5fac6396e
+18 -8
View File
@@ -69,14 +69,7 @@ export function modeRotate(context, entityIDs) {
var nodes = utilGetAllNodes(entityIDs, context.graph());
var points = nodes.map(function(n) { return projection(n.loc); });
if (points.length === 1) { // degenerate case
_pivot = points[0];
} else if (points.length === 2) {
_pivot = geoVecInterp(points[0], points[1], 0.5);
} else {
_pivot = d3_polygonCentroid(d3_polygonHull(points));
}
_pivot = getPivot(points);
_prevAngle = undefined;
}
@@ -94,6 +87,23 @@ export function modeRotate(context, entityIDs) {
_prevGraph = context.graph();
}
function getPivot(points) {
var _pivot;
if (points.length === 1) {
_pivot = points[0];
} else if (points.length === 2) {
_pivot = geoVecInterp(points[0], points[1], 0.5);
} else {
var polygonHull = d3_polygonHull(points);
if(polygonHull.length === 2) {
_pivot = geoVecInterp(points[0], points[1], 0.5);
} else {
_pivot = d3_polygonCentroid(d3_polygonHull(points));
}
}
return _pivot;
}
function finish() {
d3_event.stopPropagation();