From 2f43deb9dafc514e03ca1f7edf9bc72c58f948fa Mon Sep 17 00:00:00 2001 From: Radim Blazek Date: Tue, 28 Nov 2017 18:38:40 +0100 Subject: [PATCH] closestSegmentWithContext() doc and test fix --- python/core/geometry/qgsgeometry.sip | 2 +- src/core/geometry/qgsgeometry.h | 2 +- tests/src/python/test_qgsgeometry.py | 18 +++++++++++------- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/python/core/geometry/qgsgeometry.sip b/python/core/geometry/qgsgeometry.sip index 3f49356d451d..39466cb81de2 100644 --- a/python/core/geometry/qgsgeometry.sip +++ b/python/core/geometry/qgsgeometry.sip @@ -500,7 +500,7 @@ Returns true if WKB of the geometry is of WKBMulti* type \param minDistPoint Receives the nearest point on the segment \param afterVertex Receives index of the vertex after the closest segment. The vertex before the closest segment is always afterVertex - 1 - \param leftOf Out: Returns if the point lies on the left of right side of the segment ( < 0 means left, > 0 means right ) + \param leftOf Out: Returns if the point lies on the left of right side of the segment ( > 0 means left, < 0 means right ) \param epsilon epsilon for segment snapping :return: The squared Cartesian distance is also returned in sqrDist, negative number on error :rtype: float diff --git a/src/core/geometry/qgsgeometry.h b/src/core/geometry/qgsgeometry.h index 83c267ab31fb..db23213b75bd 100644 --- a/src/core/geometry/qgsgeometry.h +++ b/src/core/geometry/qgsgeometry.h @@ -555,7 +555,7 @@ class CORE_EXPORT QgsGeometry * \param minDistPoint Receives the nearest point on the segment * \param afterVertex Receives index of the vertex after the closest segment. The vertex * before the closest segment is always afterVertex - 1 - * \param leftOf Out: Returns if the point lies on the left of right side of the segment ( < 0 means left, > 0 means right ) + * \param leftOf Out: Returns if the point lies on the left of right side of the segment ( > 0 means left, < 0 means right ) * \param epsilon epsilon for segment snapping * \returns The squared Cartesian distance is also returned in sqrDist, negative number on error */ diff --git a/tests/src/python/test_qgsgeometry.py b/tests/src/python/test_qgsgeometry.py index 7af772a4565a..3b51bd836694 100644 --- a/tests/src/python/test_qgsgeometry.py +++ b/tests/src/python/test_qgsgeometry.py @@ -499,10 +499,11 @@ def testClosestVertex(self): self.assertEqual(afterVertex, 5) self.assertEqual(dist, 1) - (dist, minDistPoint, afterVertex) = polyline.closestSegmentWithContext(QgsPointXY(6, 2)) + (dist, minDistPoint, afterVertex, leftOf) = polyline.closestSegmentWithContext(QgsPointXY(6, 2)) self.assertEqual(dist, 1) self.assertEqual(minDistPoint, QgsPointXY(5, 2)) self.assertEqual(afterVertex, 4) + self.assertTrue(leftOf > 0) (point, atVertex, beforeVertex, afterVertex, dist) = polyline.closestVertex(QgsPointXY(6, 0)) self.assertEqual(point, QgsPointXY(5, 0)) @@ -511,7 +512,7 @@ def testClosestVertex(self): self.assertEqual(afterVertex, 1) self.assertEqual(dist, 1) - (dist, minDistPoint, afterVertex) = polyline.closestSegmentWithContext(QgsPointXY(6, 0)) + (dist, minDistPoint, afterVertex, leftOf) = polyline.closestSegmentWithContext(QgsPointXY(6, 0)) self.assertEqual(dist, 1) self.assertEqual(minDistPoint, QgsPointXY(5, 0)) self.assertEqual(afterVertex, 1) @@ -523,7 +524,7 @@ def testClosestVertex(self): self.assertEqual(afterVertex, 2) self.assertEqual(dist, 1) - (dist, minDistPoint, afterVertex) = polyline.closestSegmentWithContext(QgsPointXY(0, 1)) + (dist, minDistPoint, afterVertex, leftOf) = polyline.closestSegmentWithContext(QgsPointXY(0, 1)) self.assertEqual(dist, 0) self.assertEqual(minDistPoint, QgsPointXY(0, 1)) self.assertEqual(afterVertex, 2) @@ -544,7 +545,7 @@ def testClosestVertex(self): self.assertEqual(afterVertex, 8) self.assertEqual(dist, 1) - (dist, minDistPoint, afterVertex) = polyline.closestSegmentWithContext(QgsPointXY(7, 0)) + (dist, minDistPoint, afterVertex, leftOf) = polyline.closestSegmentWithContext(QgsPointXY(7, 0)) self.assertEqual(dist, 1) self.assertEqual(minDistPoint, QgsPointXY(6, 0)) self.assertEqual(afterVertex, 9) @@ -566,11 +567,12 @@ def testClosestVertex(self): self.assertEqual(afterVertex, 3) assert abs(dist - 0.1) < 0.00001, "Expected: %f; Got:%f" % (dist, 0.1) - (dist, minDistPoint, afterVertex) = polygon.closestSegmentWithContext(QgsPointXY(0.7, 1.1)) + (dist, minDistPoint, afterVertex, leftOf) = polygon.closestSegmentWithContext(QgsPointXY(0.7, 1.1)) self.assertEqual(afterVertex, 2) self.assertEqual(minDistPoint, QgsPointXY(1, 1)) exp = 0.3 ** 2 + 0.1 ** 2 assert abs(dist - exp) < 0.00001, "Expected: %f; Got:%f" % (exp, dist) + self.assertTrue(leftOf > 0) # 3-+-+-2 # | | @@ -592,11 +594,12 @@ def testClosestVertex(self): self.assertEqual(afterVertex, 9) assert abs(dist - 0.02) < 0.00001, "Expected: %f; Got:%f" % (dist, 0.02) - (dist, minDistPoint, afterVertex) = polygon.closestSegmentWithContext(QgsPointXY(1.2, 1.9)) + (dist, minDistPoint, afterVertex, leftOf) = polygon.closestSegmentWithContext(QgsPointXY(1.2, 1.9)) self.assertEqual(afterVertex, 8) self.assertEqual(minDistPoint, QgsPointXY(1.2, 2)) exp = 0.01 assert abs(dist - exp) < 0.00001, "Expected: %f; Got:%f" % (exp, dist) + self.assertTrue(leftOf > 0) # 5-+-4 0-+-9 # | | | | @@ -616,11 +619,12 @@ def testClosestVertex(self): self.assertEqual(afterVertex, 13) assert abs(dist - 0.02) < 0.00001, "Expected: %f; Got:%f" % (dist, 0.02) - (dist, minDistPoint, afterVertex) = polygon.closestSegmentWithContext(QgsPointXY(4.1, 1.1)) + (dist, minDistPoint, afterVertex, leftOf) = polygon.closestSegmentWithContext(QgsPointXY(4.1, 1.1)) self.assertEqual(afterVertex, 12) self.assertEqual(minDistPoint, QgsPointXY(4, 1)) exp = 0.02 assert abs(dist - exp) < 0.00001, "Expected: %f; Got:%f" % (exp, dist) + self.assertTrue(leftOf > 0) def testAdjacentVertex(self): # 2-+-+-+-+-3