Skip to content

Commit 6d04ff5

Browse files
lbartolettinyalldawson
authored andcommitted
fix(QgsCurve): properly handle area cache when reversing geometry
(cherry picked from commit 8f1a6e3)
1 parent cc04caf commit 6d04ff5

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

src/core/geometry/qgscircularstring.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -1626,6 +1626,8 @@ QgsCircularString *QgsCircularString::reversed() const
16261626
{
16271627
std::reverse( copy->mM.begin(), copy->mM.end() );
16281628
}
1629+
1630+
copy->mSummedUpArea = -mSummedUpArea;
16291631
return copy;
16301632
}
16311633

src/core/geometry/qgslinestring.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -1372,6 +1372,8 @@ QgsLineString *QgsLineString::reversed() const
13721372
{
13731373
std::reverse( copy->mM.begin(), copy->mM.end() );
13741374
}
1375+
1376+
copy->mSummedUpArea = -mSummedUpArea;
13751377
return copy;
13761378
}
13771379

tests/src/python/test_qgsgeometry.py

+16
Original file line numberDiff line numberDiff line change
@@ -7413,6 +7413,22 @@ def testConstrainedDelaunayTriangulation(self):
74137413
"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)))"
74147414
)
74157415

7416+
def test_orientation(self):
7417+
"""
7418+
test orientation. From https://github.com/qgis/QGIS/issues/58333
7419+
"""
7420+
geom = QgsLineString()
7421+
geom.fromWkt('LineString (1 1, 2 1, 2 2, 1 2, 1 1)')
7422+
self.assertEqual(geom.sumUpArea(), 1.0)
7423+
self.assertEqual(geom.orientation(), Qgis.AngularDirection.CounterClockwise)
7424+
geom.fromWkt('LineString (1 1, 1 2, 2 2, 2 1, 1 1)')
7425+
self.assertEqual(geom.sumUpArea(), -1.0)
7426+
self.assertEqual(geom.orientation(), Qgis.AngularDirection.Clockwise)
7427+
geom = geom.reversed()
7428+
self.assertEqual(geom.asWkt(), 'LineString (1 1, 2 1, 2 2, 1 2, 1 1)')
7429+
self.assertEqual(geom.sumUpArea(), 1.0)
7430+
self.assertEqual(geom.orientation(), Qgis.AngularDirection.CounterClockwise)
7431+
74167432

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

0 commit comments

Comments
 (0)