Skip to content

Commit

Permalink
fix(QgsCurve): properly handle area cache when reversing geometry (#5…
Browse files Browse the repository at this point in the history
…9183)

(cherry picked from commit 8f1a6e3)

Co-authored-by: Loïc Bartoletti <loic.bartoletti@oslandia.com>
  • Loading branch information
nyalldawson and lbartoletti authored Oct 24, 2024
1 parent 8f15876 commit 9220e3f
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 @@ -1626,6 +1626,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 @@ -1372,6 +1372,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_qgsgeometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -7413,6 +7413,22 @@ def testConstrainedDelaunayTriangulation(self):
"MultiPolygon (((41.96 29.61, 41.96 30.39, 42 30, 41.96 29.61)),((41.66 31.11, 41.85 30.77, 41.96 30.39, 41.66 31.11)),((41.66 28.89, 41.96 29.61, 41.85 29.23, 41.66 28.89)),((41.41 31.41, 41.96 30.39, 41.96 29.61, 41.41 31.41)),((41.41 31.41, 41.66 31.11, 41.96 30.39, 41.41 31.41)),((41.41 28.59, 41.96 29.61, 41.66 28.89, 41.41 28.59)),((41.41 28.59, 41.41 31.41, 41.96 29.61, 41.41 28.59)),((40.39 31.96, 41.11 31.66, 41.41 31.41, 40.39 31.96)),((40.39 31.96, 40.77 31.85, 41.11 31.66, 40.39 31.96)),((40.39 28.04, 41.41 28.59, 41.11 28.34, 40.39 28.04)),((40.39 28.04, 41.11 28.34, 40.77 28.15, 40.39 28.04)),((39.61 31.96, 40.39 31.96, 41.41 31.41, 39.61 31.96)),((39.61 31.96, 40 32, 40.39 31.96, 39.61 31.96)),((39.61 28.04, 40.39 28.04, 40 28, 39.61 28.04)),((38.89 31.66, 39.23 31.85, 39.61 31.96, 38.89 31.66)),((38.89 28.34, 39.61 28.04, 39.23 28.15, 38.89 28.34)),((38.59 31.41, 41.41 31.41, 41.41 28.59, 38.59 31.41)),((38.59 31.41, 39.61 31.96, 41.41 31.41, 38.59 31.41)),((38.59 31.41, 38.89 31.66, 39.61 31.96, 38.59 31.41)),((38.59 28.59, 41.41 28.59, 40.39 28.04, 38.59 28.59)),((38.59 28.59, 40.39 28.04, 39.61 28.04, 38.59 28.59)),((38.59 28.59, 39.61 28.04, 38.89 28.34, 38.59 28.59)),((38.59 28.59, 38.59 31.41, 41.41 28.59, 38.59 28.59)),((38.04 30.39, 38.59 31.41, 38.59 28.59, 38.04 30.39)),((38.04 30.39, 38.34 31.11, 38.59 31.41, 38.04 30.39)),((38.04 30.39, 38.15 30.77, 38.34 31.11, 38.04 30.39)),((38.04 29.61, 38.59 28.59, 38.34 28.89, 38.04 29.61)),((38.04 29.61, 38.34 28.89, 38.15 29.23, 38.04 29.61)),((38.04 29.61, 38.04 30.39, 38.59 28.59, 38.04 29.61)),((38 30, 38.04 30.39, 38.04 29.61, 38 30)))"
)

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 9220e3f

Please sign in to comment.