diff --git a/modules/modes/rotate.js b/modules/modes/rotate.js index 11821a002..2c4c58333 100644 --- a/modules/modes/rotate.js +++ b/modules/modes/rotate.js @@ -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();