Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
closestSegmentWithContext() doc and test fix
  • Loading branch information
blazek authored and nyalldawson committed Nov 28, 2017
1 parent 07fd713 commit 2f43deb
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion python/core/geometry/qgsgeometry.sip
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/core/geometry/qgsgeometry.h
Expand Up @@ -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
*/
Expand Down
18 changes: 11 additions & 7 deletions tests/src/python/test_qgsgeometry.py
Expand Up @@ -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))
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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
# | |
Expand All @@ -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
# | | | |
Expand All @@ -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
Expand Down

0 comments on commit 2f43deb

Please sign in to comment.