mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-24 09:04:02 +02:00
fix(mode/rotate): polygonHull sometimes returns array of length 2 which polygonCentroid cannot handle
This commit is contained in:
+18
-8
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user