Better orthogonalization of skinny quads. Fixes #1812

This commit is contained in:
Paul Mach
2013-09-21 21:21:36 -07:00
parent 0b17eb344a
commit 76e0ef7c26
2 changed files with 34 additions and 3 deletions

View File

@@ -25,7 +25,7 @@ iD.actions.Orthogonalize = function(wayId, projection) {
.move(projection.invert(points[corner.i])));
} else {
var best;
points = nodes.map(function(n) { return projection(n.loc); });
points = _.uniq(nodes).map(function(n) { return projection(n.loc); });
score = squareness();
for (i = 0; i < 1000; i++) {
@@ -45,7 +45,7 @@ iD.actions.Orthogonalize = function(wayId, projection) {
points = best;
for (i = 0; i < points.length - 1; i++) {
for (i = 0; i < points.length; i++) {
graph = graph.replace(graph.entity(nodes[i].id)
.move(projection.invert(points[i])));
}
@@ -59,7 +59,7 @@ iD.actions.Orthogonalize = function(wayId, projection) {
p = subtractPoints(a, b),
q = subtractPoints(c, b);
var scale = iD.geo.dist(p, [0, 0]) + iD.geo.dist(q, [0, 0]);
var scale = 2*Math.min(iD.geo.dist(p, [0, 0]), iD.geo.dist(q, [0, 0]));
p = normalizePoint(p, 1.0);
q = normalizePoint(q, 1.0);

View File

@@ -27,4 +27,35 @@ describe("iD.actions.Orthogonalize", function () {
expect(graph.entity('-').nodes).to.have.length(4);
});
it("should not shrink skinny quads", function () {
var tests = [[[-77.0339864831478, 38.8616391227204],
[-77.0209775298677, 38.8613609264884],
[-77.0210405781065, 38.8607390721519],
[-77.0339024188294, 38.8610663645859]
],
[[-89.4706683, 40.6261177],
[-89.4706664, 40.6260574],
[-89.4693973, 40.6260830],
[-89.4694012, 40.6261355]
]
];
for (var i = 0; i < tests.length; i++) {
var graph = iD.Graph({
'a': iD.Node({id: 'a', loc: tests[i][0]}),
'b': iD.Node({id: 'b', loc: tests[i][1]}),
'c': iD.Node({id: 'c', loc: tests[i][2]}),
'd': iD.Node({id: 'd', loc: tests[i][3]}),
'-': iD.Way({id: '-', nodes: ['a', 'b', 'c', 'd', 'a']})
}),
initialWidth = iD.geo.dist(graph.entity('a').loc, graph.entity('b').loc),
finalWidth;
graph = iD.actions.Orthogonalize('-', projection)(graph);
finalWidth = iD.geo.dist(graph.entity('a').loc, graph.entity('b').loc);
expect(finalWidth/initialWidth).within(0.90, 1.10);
}
});
});