Skip to content
Permalink
Browse files

also fix return for empty parameter point

  • Loading branch information
uclaros authored and nyalldawson committed May 18, 2020
1 parent 0f3a6f0 commit e6fef7af63d4477c8bcee5bacd5b90951af08617
@@ -388,7 +388,7 @@ QgsPointXY QgsGeometry::closestVertex( const QgsPointXY &point, int &atVertex, i
return QgsPointXY();
}

QgsPoint pt( point.x(), point.y() );
QgsPoint pt( point );
QgsVertexId id;

QgsPoint vp = QgsGeometryUtils::closestVertex( *( d->geometry ), pt, id );
@@ -630,7 +630,7 @@ double QgsGeometry::closestVertexWithContext( const QgsPointXY &point, int &atVe
}

QgsVertexId vId;
QgsPoint pt( point.x(), point.y() );
QgsPoint pt( point );
QgsPoint closestPoint = QgsGeometryUtils::closestVertex( *( d->geometry ), pt, vId );
if ( !vId.isValid() )
return -1;
@@ -71,6 +71,9 @@ QgsPoint QgsGeometryUtils::closestVertex( const QgsAbstractGeometry &geom, const
QgsPoint minDistPoint;
id = QgsVertexId(); // set as invalid

if ( geom.isEmpty() || pt.isEmpty() )
return minDistPoint;

QgsVertexId vertexId;
QgsPoint vertex;
while ( geom.nextVertex( vertexId, vertex ) )
@@ -67,6 +67,11 @@ QgsPoint::QgsPoint( const QgsPointXY &p )
, mM( std::numeric_limits<double>::quiet_NaN() )
{
mWkbType = QgsWkbTypes::Point;
if ( p.isEmpty() )
{
mX = std::numeric_limits<double>::quiet_NaN();
mY = std::numeric_limits<double>::quiet_NaN();
}
}

QgsPoint::QgsPoint( QPointF p )
@@ -1193,6 +1193,10 @@ def testClosestVertex(self):
assert abs(dist - exp) < 0.00001, "Expected: %f; Got:%f" % (exp, dist)
self.assertEqual(leftOf, -1)

(point, atVertex, beforeVertex, afterVertex, dist) = polygon.closestVertex(QgsPointXY())
self.assertTrue(point.isEmpty())
self.assertEqual(dist, -1)

(point, atVertex, beforeVertex, afterVertex, dist) = QgsGeometry().closestVertex(QgsPointXY(42, 42))
self.assertTrue(point.isEmpty())

@@ -86,6 +86,10 @@ def test_issue_32443(self):
p = QgsPoint(1, 2, m=4, z=3)
assert p.wkbType() == QgsWkbTypes.PointZM and p.x() == 1 and p.y() == 2 and p.z() == 3 and p.m() == 4

def test_empty_QgsPointXY(self):
p = QgsPoint(QgsPointXY())
assert p.isEmpty()


class TestQgsPoint(unittest.TestCase):

0 comments on commit e6fef7a

Please sign in to comment.
You can’t perform that action at this time.