Skip to content

Commit

Permalink
fix(QgsCurve): properly handle area cache when reversing geometry
Browse files Browse the repository at this point in the history
  • Loading branch information
lbartoletti authored and nyalldawson committed Oct 22, 2024
1 parent 1779d1b commit 8f1a6e3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/core/geometry/qgscircularstring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1605,6 +1605,8 @@ QgsCircularString *QgsCircularString::reversed() const
{
std::reverse( copy->mM.begin(), copy->mM.end() );
}

copy->mSummedUpArea = -mSummedUpArea;
return copy;
}

Expand Down
2 changes: 2 additions & 0 deletions src/core/geometry/qgslinestring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1464,6 +1464,8 @@ QgsLineString *QgsLineString::reversed() const
{
std::reverse( copy->mM.begin(), copy->mM.end() );
}

copy->mSummedUpArea = -mSummedUpArea;
return copy;
}

Expand Down
16 changes: 16 additions & 0 deletions tests/src/python/test_qgslinestring.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,22 @@ def test_simplify_by_distance(self):
self.assertEqual(p.simplifyByDistance(0).asWkt(),
'LineString (2 0, 2 2, 0 2, 0 0, 2 0)')

def test_orientation(self):
"""
test orientation. From https://github.com/qgis/QGIS/issues/58333
"""
geom = QgsLineString()
geom.fromWkt('LineString (1 1, 2 1, 2 2, 1 2, 1 1)')
self.assertEqual(geom.sumUpArea(), 1.0)
self.assertEqual(geom.orientation(), Qgis.AngularDirection.CounterClockwise)
geom.fromWkt('LineString (1 1, 1 2, 2 2, 2 1, 1 1)')
self.assertEqual(geom.sumUpArea(), -1.0)
self.assertEqual(geom.orientation(), Qgis.AngularDirection.Clockwise)
geom = geom.reversed()
self.assertEqual(geom.asWkt(), 'LineString (1 1, 2 1, 2 2, 1 2, 1 1)')
self.assertEqual(geom.sumUpArea(), 1.0)
self.assertEqual(geom.orientation(), Qgis.AngularDirection.CounterClockwise)


if __name__ == '__main__':
unittest.main()

0 comments on commit 8f1a6e3

Please sign in to comment.