Skip to content

Commit

Permalink
Merge pull request #49743 from agiudiceandrea/backport-49715-to-relea…
Browse files Browse the repository at this point in the history
…se-3_26

[Backport release-3_26] Fix crash caused by the Orthogonalize processing algorithm (Fix #49621)
lbartoletti authored Aug 11, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents 53bb26d + 00080c5 commit 108c6c5
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/core/geometry/qgsinternalgeometryengine.cpp
Original file line number Diff line number Diff line change
@@ -526,6 +526,10 @@ QgsVector calcMotion( const QgsPoint &a, const QgsPoint &b, const QgsPoint &c,
dotProduct += 1.0;

QgsVector new_v = p + q;
if ( qgsDoubleNear( new_v.length(), 0.0 ) )
{
return QgsVector( 0, 0 );
}
// 0.1 magic number from JOSM implementation - think this is to limit each iterative step
return new_v.normalized() * ( 0.1 * dotProduct * scale );
}
9 changes: 9 additions & 0 deletions tests/src/python/test_qgsgeometry.py
Original file line number Diff line number Diff line change
@@ -5166,6 +5166,15 @@ def testOrthogonalize(self):
self.assertTrue(compareWkt(result, exp, 0.00001),
"orthogonalize: mismatch Expected:\n{}\nGot:\n{}\n".format(exp, result))

# already orthogonal polygon with a vertex on a "straight line" (https://github.com/qgis/QGIS/issues/49621)
polygon = QgsGeometry.fromWkt(
'Polygon ((0 0, 5 0, 10 0, 10 10, 0 10, 0 0))')
o = polygon.orthogonalize()
exp = 'Polygon ((0 0, 5 0, 10 0, 10 10, 0 10, 0 0))'
result = o.asWkt()
self.assertTrue(compareWkt(result, exp, 0.00001),
"orthogonalize: mismatch Expected:\n{}\nGot:\n{}\n".format(exp, result))

def testPolygonize(self):
o = QgsGeometry.polygonize([])
self.assertFalse(o)

0 comments on commit 108c6c5

Please sign in to comment.