Prevent orthogonalization of <3 node ways. Fixes #776

This commit is contained in:
Tom MacWright
2013-03-18 15:44:15 -04:00
parent 84e5cae90e
commit 29b6f34403
2 changed files with 6 additions and 4 deletions
+4 -3
View File
@@ -27,7 +27,8 @@ iD.actions.Orthogonalize = function(wayId, projection) {
points = best;
for (i = 0; i < points.length - 1; i++) {
graph = graph.replace(graph.entity(nodes[i].id).move(projection.invert(points[i])));
graph = graph.replace(graph.entity(nodes[i].id)
.move(projection.invert(points[i])));
}
return graph;
@@ -42,7 +43,7 @@ iD.actions.Orthogonalize = function(wayId, projection) {
p = normalizePoint(p, 1.0);
q = normalizePoint(q, 1.0);
var dotp = p[0] *q[0] + p[1] *q[1];
var dotp = p[0] * q[0] + p[1] * q[1];
// nasty hack to deal with almost-straight segments (angle is closer to 180 than to 90/270).
if (dotp < -0.707106781186547) {
dotp += 1.0;
@@ -87,7 +88,7 @@ iD.actions.Orthogonalize = function(wayId, projection) {
function normalizePoint(point, thickness) {
var vector = [0, 0];
var length = Math.sqrt(point[0] * point[0] + point[1] * point[1]);
var length = Math.sqrt(point[0] * point[0] + point[1] * point[1]);
if (length !== 0) {
vector[0] = point[0] / length;
vector[1] = point[1] / length;
+2 -1
View File
@@ -9,7 +9,8 @@ iD.operations.Orthogonalize = function(selection, context) {
operation.available = function() {
return selection.length === 1 &&
context.entity(entityId).type === 'way';
context.entity(entityId).type === 'way' &&
_.uniq(context.entity(entityId).nodes).length > 3;
};
operation.enabled = function() {