Skip to content
Permalink
Browse files

Cleaner signature for QgsAbstractGeometry::closestSegment

  • Loading branch information
nyalldawson committed Sep 19, 2017
1 parent 1f40f62 commit bb425e4540f775b7c7f15ade844d6df4be968d58
@@ -275,7 +275,7 @@ class QgsAbstractGeometry

virtual double closestSegment( const QgsPoint &pt, QgsPoint &segmentPt /Out/,
QgsVertexId &vertexAfter /Out/,
bool *leftOf /Out/, double epsilon ) const = 0;
bool *leftOf /Out/ = 0, double epsilon = 4 * DBL_EPSILON ) const = 0;
%Docstring
Searches for the closest segment of the geometry to a given point.
\param pt specifies the point to find closest segment to
@@ -99,7 +99,7 @@ class QgsCircularString: QgsCurve

virtual double closestSegment( const QgsPoint &pt, QgsPoint &segmentPt /Out/,
QgsVertexId &vertexAfter /Out/,
bool *leftOf /Out/, double epsilon ) const;
bool *leftOf /Out/ = 0, double epsilon = 4 * DBL_EPSILON ) const;

virtual bool pointAt( int node, QgsPoint &point, QgsVertexId::VertexType &type ) const;

@@ -107,8 +107,8 @@ class QgsCompoundCurve: QgsCurve
virtual bool deleteVertex( QgsVertexId position );

virtual double closestSegment( const QgsPoint &pt, QgsPoint &segmentPt /Out/,
QgsVertexId &vertexAfter /Out/, bool *leftOf /Out/,
double epsilon ) const;
QgsVertexId &vertexAfter /Out/, bool *leftOf /Out/ = 0,
double epsilon = 4 * DBL_EPSILON ) const;

virtual bool pointAt( int node, QgsPoint &point, QgsVertexId::VertexType &type ) const;

@@ -136,7 +136,7 @@ Adds an interior ring to the geometry (takes ownership)

virtual bool isEmpty() const;

virtual double closestSegment( const QgsPoint &pt, QgsPoint &segmentPt /Out/, QgsVertexId &vertexAfter /Out/, bool *leftOf /Out/, double epsilon ) const;
virtual double closestSegment( const QgsPoint &pt, QgsPoint &segmentPt /Out/, QgsVertexId &vertexAfter /Out/, bool *leftOf /Out/ = 0, double epsilon = 4 * DBL_EPSILON ) const;


virtual bool nextVertex( QgsVertexId &id, QgsPoint &vertex /Out/ ) const;
@@ -107,7 +107,7 @@ Adds a geometry and takes ownership. Returns true in case of success.
virtual int nCoordinates() const;


virtual double closestSegment( const QgsPoint &pt, QgsPoint &segmentPt /Out/, QgsVertexId &vertexAfter /Out/, bool *leftOf /Out/, double epsilon ) const;
virtual double closestSegment( const QgsPoint &pt, QgsPoint &segmentPt /Out/, QgsVertexId &vertexAfter /Out/, bool *leftOf /Out/ = 0, double epsilon = 4 * DBL_EPSILON ) const;

virtual bool nextVertex( QgsVertexId &id, QgsPoint &vertex /Out/ ) const;

@@ -238,7 +238,7 @@ Closes the line string by appending the first point to the end of the line, if i
virtual QgsLineString *reversed() const /Factory/;


virtual double closestSegment( const QgsPoint &pt, QgsPoint &segmentPt /Out/, QgsVertexId &vertexAfter /Out/, bool *leftOf /Out/, double epsilon ) const;
virtual double closestSegment( const QgsPoint &pt, QgsPoint &segmentPt /Out/, QgsVertexId &vertexAfter /Out/, bool *leftOf /Out/ = 0, double epsilon = 4 * DBL_EPSILON ) const;

virtual bool pointAt( int node, QgsPoint &point, QgsVertexId::VertexType &type ) const;

@@ -367,7 +367,7 @@ class QgsPoint: QgsAbstractGeometry

virtual bool deleteVertex( QgsVertexId position );

virtual double closestSegment( const QgsPoint &pt, QgsPoint &segmentPt /Out/, QgsVertexId &vertexAfter /Out/, bool *leftOf /Out/, double epsilon ) const;
virtual double closestSegment( const QgsPoint &pt, QgsPoint &segmentPt /Out/, QgsVertexId &vertexAfter /Out/, bool *leftOf /Out/ = 0, double epsilon = 4 * DBL_EPSILON ) const;

virtual bool nextVertex( QgsVertexId &id, QgsPoint &vertex /Out/ ) const;

@@ -278,7 +278,7 @@ class CORE_EXPORT QgsAbstractGeometry
*/
virtual double closestSegment( const QgsPoint &pt, QgsPoint &segmentPt SIP_OUT,
QgsVertexId &vertexAfter SIP_OUT,
bool *leftOf SIP_OUT, double epsilon ) const = 0;
bool *leftOf SIP_OUT = nullptr, double epsilon = 4 * DBL_EPSILON ) const = 0;

//low-level editing

@@ -701,7 +701,6 @@ void QgsCircularString::deleteVertex( int i )

double QgsCircularString::closestSegment( const QgsPoint &pt, QgsPoint &segmentPt, QgsVertexId &vertexAfter, bool *leftOf, double epsilon ) const
{
Q_UNUSED( epsilon );
double minDist = std::numeric_limits<double>::max();
QgsPoint minDistSegmentPoint;
QgsVertexId minDistVertexAfter;
@@ -925,10 +924,6 @@ double QgsCircularString::vertexAngle( QgsVertexId vId ) const
}
if ( vId.vertex >= numPoints() - 1 )
{
if ( numPoints() < 3 )
{
return 0.0;
}
int a = numPoints() - 3;
int b = numPoints() - 2;
int c = numPoints() - 1;
@@ -93,7 +93,7 @@ class CORE_EXPORT QgsCircularString: public QgsCurve

virtual double closestSegment( const QgsPoint &pt, QgsPoint &segmentPt SIP_OUT,
QgsVertexId &vertexAfter SIP_OUT,
bool *leftOf SIP_OUT, double epsilon ) const override;
bool *leftOf SIP_OUT = nullptr, double epsilon = 4 * DBL_EPSILON ) const override;

bool pointAt( int node, QgsPoint &point, QgsVertexId::VertexType &type ) const override;
void sumUpArea( double &sum SIP_OUT ) const override;
@@ -99,8 +99,8 @@ class CORE_EXPORT QgsCompoundCurve: public QgsCurve
virtual bool deleteVertex( QgsVertexId position ) override;

virtual double closestSegment( const QgsPoint &pt, QgsPoint &segmentPt SIP_OUT,
QgsVertexId &vertexAfter SIP_OUT, bool *leftOf SIP_OUT,
double epsilon ) const override;
QgsVertexId &vertexAfter SIP_OUT, bool *leftOf SIP_OUT = nullptr,
double epsilon = 4 * DBL_EPSILON ) const override;

bool pointAt( int node, QgsPoint &point, QgsVertexId::VertexType &type ) const override;

@@ -111,7 +111,7 @@ class CORE_EXPORT QgsCurvePolygon: public QgsSurface
QgsCoordinateSequence coordinateSequence() const override;
int nCoordinates() const override;
bool isEmpty() const override;
double closestSegment( const QgsPoint &pt, QgsPoint &segmentPt SIP_OUT, QgsVertexId &vertexAfter SIP_OUT, bool *leftOf SIP_OUT, double epsilon ) const override;
double closestSegment( const QgsPoint &pt, QgsPoint &segmentPt SIP_OUT, QgsVertexId &vertexAfter SIP_OUT, bool *leftOf SIP_OUT = nullptr, double epsilon = 4 * DBL_EPSILON ) const override;

bool nextVertex( QgsVertexId &id, QgsPoint &vertex SIP_OUT ) const override;

@@ -96,7 +96,7 @@ class CORE_EXPORT QgsGeometryCollection: public QgsAbstractGeometry
QgsCoordinateSequence coordinateSequence() const override;
int nCoordinates() const override;

double closestSegment( const QgsPoint &pt, QgsPoint &segmentPt SIP_OUT, QgsVertexId &vertexAfter SIP_OUT, bool *leftOf SIP_OUT, double epsilon ) const override;
double closestSegment( const QgsPoint &pt, QgsPoint &segmentPt SIP_OUT, QgsVertexId &vertexAfter SIP_OUT, bool *leftOf SIP_OUT = nullptr, double epsilon = 4 * DBL_EPSILON ) const override;
bool nextVertex( QgsVertexId &id, QgsPoint &vertex SIP_OUT ) const override;

//low-level editing
@@ -207,7 +207,7 @@ class CORE_EXPORT QgsLineString: public QgsCurve

QgsLineString *reversed() const override SIP_FACTORY;

double closestSegment( const QgsPoint &pt, QgsPoint &segmentPt SIP_OUT, QgsVertexId &vertexAfter SIP_OUT, bool *leftOf SIP_OUT, double epsilon ) const override;
double closestSegment( const QgsPoint &pt, QgsPoint &segmentPt SIP_OUT, QgsVertexId &vertexAfter SIP_OUT, bool *leftOf SIP_OUT = nullptr, double epsilon = 4 * DBL_EPSILON ) const override;
bool pointAt( int node, QgsPoint &point, QgsVertexId::VertexType &type ) const override;

QgsPoint centroid() const override;
@@ -395,7 +395,7 @@ class CORE_EXPORT QgsPoint: public QgsAbstractGeometry
bool moveVertex( QgsVertexId position, const QgsPoint &newPos ) override;
bool deleteVertex( QgsVertexId position ) override { Q_UNUSED( position ); return false; }

double closestSegment( const QgsPoint &pt, QgsPoint &segmentPt SIP_OUT, QgsVertexId &vertexAfter SIP_OUT, bool *leftOf SIP_OUT, double epsilon ) const override;
double closestSegment( const QgsPoint &pt, QgsPoint &segmentPt SIP_OUT, QgsVertexId &vertexAfter SIP_OUT, bool *leftOf SIP_OUT = nullptr, double epsilon = 4 * DBL_EPSILON ) const override;
bool nextVertex( QgsVertexId &id, QgsPoint &vertex SIP_OUT ) const override;

/** Angle undefined. Always returns 0.0
@@ -579,6 +579,10 @@ void TestQgsGeometry::point()
std::unique_ptr< QgsPoint >clone( p10.clone() );
QVERIFY( p10 == *clone );

//toCurveType
clone.reset( p10.toCurveType() );
QVERIFY( p10 == *clone );

//assignment
QgsPoint original( QgsWkbTypes::PointZM, 1.0, 2.0, 3.0, -4.0 );
QgsPoint assigned( 6.0, 7.0 );
@@ -742,7 +746,7 @@ void TestQgsGeometry::point()
QgsPoint closest;
QgsVertexId after;
// return error - points have no segments
QVERIFY( p20.closestSegment( QgsPoint( 4.0, 6.0 ), closest, after, 0, 0 ) < 0 );
QVERIFY( p20.closestSegment( QgsPoint( 4.0, 6.0 ), closest, after ) < 0 );

//nextVertex
QgsPoint p21( 3.0, 4.0 );
@@ -2002,68 +2006,68 @@ void TestQgsGeometry::circularString()
QgsCircularString l35;
bool leftOf = false;
p = QgsPoint(); // reset all coords to zero
( void )l35.closestSegment( QgsPoint( 1, 2 ), p, v, 0, 0 ); //empty line, just want no crash
( void )l35.closestSegment( QgsPoint( 1, 2 ), p, v ); //empty line, just want no crash
l35.setPoints( QgsPointSequence() << QgsPoint( 5, 10 ) );
QVERIFY( l35.closestSegment( QgsPoint( 5, 10 ), p, v, 0, 0 ) < 0 );
QVERIFY( l35.closestSegment( QgsPoint( 5, 10 ), p, v ) < 0 );
l35.setPoints( QgsPointSequence() << QgsPoint( 5, 10 ) << QgsPoint( 7, 12 ) << QgsPoint( 5, 15 ) );
QGSCOMPARENEAR( l35.closestSegment( QgsPoint( 4, 11 ), p, v, &leftOf, 0 ), 2.0, 0.0001 );
QGSCOMPARENEAR( l35.closestSegment( QgsPoint( 4, 11 ), p, v, &leftOf ), 2.0, 0.0001 );
QCOMPARE( p, QgsPoint( 5, 10 ) );
QCOMPARE( v, QgsVertexId( 0, 0, 1 ) );
QCOMPARE( leftOf, true );
QGSCOMPARENEAR( l35.closestSegment( QgsPoint( 8, 11 ), p, v, &leftOf, 0 ), 1.583512, 0.0001 );
QGSCOMPARENEAR( l35.closestSegment( QgsPoint( 8, 11 ), p, v, &leftOf ), 1.583512, 0.0001 );
QGSCOMPARENEAR( p.x(), 6.84, 0.01 );
QGSCOMPARENEAR( p.y(), 11.49, 0.01 );
QCOMPARE( v, QgsVertexId( 0, 0, 1 ) );
QCOMPARE( leftOf, false );
QGSCOMPARENEAR( l35.closestSegment( QgsPoint( 5.5, 11.5 ), p, v, &leftOf, 0 ), 1.288897, 0.0001 );
QGSCOMPARENEAR( l35.closestSegment( QgsPoint( 5.5, 11.5 ), p, v, &leftOf ), 1.288897, 0.0001 );
QGSCOMPARENEAR( p.x(), 6.302776, 0.01 );
QGSCOMPARENEAR( p.y(), 10.7, 0.01 );
QCOMPARE( v, QgsVertexId( 0, 0, 1 ) );
QCOMPARE( leftOf, true );
QGSCOMPARENEAR( l35.closestSegment( QgsPoint( 7, 16 ), p, v, &leftOf, 0 ), 3.068288, 0.0001 );
QGSCOMPARENEAR( l35.closestSegment( QgsPoint( 7, 16 ), p, v, &leftOf ), 3.068288, 0.0001 );
QGSCOMPARENEAR( p.x(), 5.981872, 0.01 );
QGSCOMPARENEAR( p.y(), 14.574621, 0.01 );
QCOMPARE( v, QgsVertexId( 0, 0, 2 ) );
QCOMPARE( leftOf, false );
QGSCOMPARENEAR( l35.closestSegment( QgsPoint( 5.5, 13.5 ), p, v, &leftOf, 0 ), 1.288897, 0.0001 );
QGSCOMPARENEAR( l35.closestSegment( QgsPoint( 5.5, 13.5 ), p, v, &leftOf ), 1.288897, 0.0001 );
QGSCOMPARENEAR( p.x(), 6.302776, 0.01 );
QGSCOMPARENEAR( p.y(), 14.3, 0.01 );
QCOMPARE( v, QgsVertexId( 0, 0, 2 ) );
QCOMPARE( leftOf, true );
// point directly on segment
QCOMPARE( l35.closestSegment( QgsPoint( 5, 15 ), p, v, &leftOf, 0 ), 0.0 );
QCOMPARE( l35.closestSegment( QgsPoint( 5, 15 ), p, v, &leftOf ), 0.0 );
QCOMPARE( p, QgsPoint( 5, 15 ) );
QCOMPARE( v, QgsVertexId( 0, 0, 2 ) );

//clockwise string
l35.setPoints( QgsPointSequence() << QgsPoint( 5, 15 ) << QgsPoint( 7, 12 ) << QgsPoint( 5, 10 ) );
QGSCOMPARENEAR( l35.closestSegment( QgsPoint( 4, 11 ), p, v, &leftOf, 0 ), 2, 0.0001 );
QGSCOMPARENEAR( l35.closestSegment( QgsPoint( 4, 11 ), p, v, &leftOf ), 2, 0.0001 );
QGSCOMPARENEAR( p.x(), 5, 0.01 );
QGSCOMPARENEAR( p.y(), 10, 0.01 );
QCOMPARE( v, QgsVertexId( 0, 0, 2 ) );
QCOMPARE( leftOf, false );
QGSCOMPARENEAR( l35.closestSegment( QgsPoint( 8, 11 ), p, v, &leftOf, 0 ), 1.583512, 0.0001 );
QGSCOMPARENEAR( l35.closestSegment( QgsPoint( 8, 11 ), p, v, &leftOf ), 1.583512, 0.0001 );
QGSCOMPARENEAR( p.x(), 6.84, 0.01 );
QGSCOMPARENEAR( p.y(), 11.49, 0.01 );
QCOMPARE( v, QgsVertexId( 0, 0, 2 ) );
QCOMPARE( leftOf, true );
QGSCOMPARENEAR( l35.closestSegment( QgsPoint( 5.5, 11.5 ), p, v, &leftOf, 0 ), 1.288897, 0.0001 );
QGSCOMPARENEAR( l35.closestSegment( QgsPoint( 5.5, 11.5 ), p, v, &leftOf ), 1.288897, 0.0001 );
QGSCOMPARENEAR( p.x(), 6.302776, 0.01 );
QGSCOMPARENEAR( p.y(), 10.7, 0.01 );
QCOMPARE( v, QgsVertexId( 0, 0, 2 ) );
QCOMPARE( leftOf, false );
QGSCOMPARENEAR( l35.closestSegment( QgsPoint( 7, 16 ), p, v, &leftOf, 0 ), 3.068288, 0.0001 );
QGSCOMPARENEAR( l35.closestSegment( QgsPoint( 7, 16 ), p, v, &leftOf ), 3.068288, 0.0001 );
QGSCOMPARENEAR( p.x(), 5.981872, 0.01 );
QGSCOMPARENEAR( p.y(), 14.574621, 0.01 );
QCOMPARE( v, QgsVertexId( 0, 0, 1 ) );
QCOMPARE( leftOf, true );
QGSCOMPARENEAR( l35.closestSegment( QgsPoint( 5.5, 13.5 ), p, v, &leftOf, 0 ), 1.288897, 0.0001 );
QGSCOMPARENEAR( l35.closestSegment( QgsPoint( 5.5, 13.5 ), p, v, &leftOf ), 1.288897, 0.0001 );
QGSCOMPARENEAR( p.x(), 6.302776, 0.01 );
QGSCOMPARENEAR( p.y(), 14.3, 0.01 );
QCOMPARE( v, QgsVertexId( 0, 0, 1 ) );
QCOMPARE( leftOf, false );
// point directly on segment
QCOMPARE( l35.closestSegment( QgsPoint( 5, 15 ), p, v, &leftOf, 0 ), 0.0 );
QCOMPARE( l35.closestSegment( QgsPoint( 5, 15 ), p, v, &leftOf ), 0.0 );
QCOMPARE( p, QgsPoint( 5, 15 ) );
QCOMPARE( v, QgsVertexId( 0, 0, 1 ) );

@@ -3670,30 +3674,30 @@ void TestQgsGeometry::lineString()
QgsLineString l35;
bool leftOf = false;
p = QgsPoint(); // reset all coords to zero
( void )l35.closestSegment( QgsPoint( 1, 2 ), p, v, 0, 0 ); //empty line, just want no crash
( void )l35.closestSegment( QgsPoint( 1, 2 ), p, v ); //empty line, just want no crash
l35.setPoints( QgsPointSequence() << QgsPoint( 5, 10 ) );
QVERIFY( l35.closestSegment( QgsPoint( 5, 10 ), p, v, 0, 0 ) < 0 );
QVERIFY( l35.closestSegment( QgsPoint( 5, 10 ), p, v ) < 0 );
l35.setPoints( QgsPointSequence() << QgsPoint( 5, 10 ) << QgsPoint( 10, 10 ) );
QGSCOMPARENEAR( l35.closestSegment( QgsPoint( 4, 11 ), p, v, &leftOf, 0 ), 2.0, 4 * DBL_EPSILON );
QGSCOMPARENEAR( l35.closestSegment( QgsPoint( 4, 11 ), p, v, &leftOf ), 2.0, 4 * DBL_EPSILON );
QCOMPARE( p, QgsPoint( 5, 10 ) );
QCOMPARE( v, QgsVertexId( 0, 0, 1 ) );
QCOMPARE( leftOf, true );
QGSCOMPARENEAR( l35.closestSegment( QgsPoint( 8, 11 ), p, v, &leftOf, 0 ), 1.0, 4 * DBL_EPSILON );
QGSCOMPARENEAR( l35.closestSegment( QgsPoint( 8, 11 ), p, v, &leftOf ), 1.0, 4 * DBL_EPSILON );
QCOMPARE( p, QgsPoint( 8, 10 ) );
QCOMPARE( v, QgsVertexId( 0, 0, 1 ) );
QCOMPARE( leftOf, true );
QGSCOMPARENEAR( l35.closestSegment( QgsPoint( 8, 9 ), p, v, &leftOf, 0 ), 1.0, 4 * DBL_EPSILON );
QGSCOMPARENEAR( l35.closestSegment( QgsPoint( 8, 9 ), p, v, &leftOf ), 1.0, 4 * DBL_EPSILON );
QCOMPARE( p, QgsPoint( 8, 10 ) );
QCOMPARE( v, QgsVertexId( 0, 0, 1 ) );
QCOMPARE( leftOf, false );
QGSCOMPARENEAR( l35.closestSegment( QgsPoint( 11, 9 ), p, v, &leftOf, 0 ), 2.0, 4 * DBL_EPSILON );
QGSCOMPARENEAR( l35.closestSegment( QgsPoint( 11, 9 ), p, v, &leftOf ), 2.0, 4 * DBL_EPSILON );
QCOMPARE( p, QgsPoint( 10, 10 ) );
QCOMPARE( v, QgsVertexId( 0, 0, 1 ) );
QCOMPARE( leftOf, false );
l35.setPoints( QgsPointSequence() << QgsPoint( 5, 10 )
<< QgsPoint( 10, 10 )
<< QgsPoint( 10, 15 ) );
QGSCOMPARENEAR( l35.closestSegment( QgsPoint( 11, 12 ), p, v, &leftOf, 0 ), 1.0, 4 * DBL_EPSILON );
QGSCOMPARENEAR( l35.closestSegment( QgsPoint( 11, 12 ), p, v, &leftOf ), 1.0, 4 * DBL_EPSILON );
QCOMPARE( p, QgsPoint( 10, 12 ) );
QCOMPARE( v, QgsVertexId( 0, 0, 2 ) );
QCOMPARE( leftOf, false );
@@ -6829,7 +6833,7 @@ void TestQgsGeometry::multiPoint()
QgsPoint closest;
QgsVertexId after;
// return error - points have no segments
QVERIFY( boundaryMP.closestSegment( QgsPoint( 0.5, 0.5 ), closest, after, 0, 0 ) < 0 );
QVERIFY( boundaryMP.closestSegment( QgsPoint( 0.5, 0.5 ), closest, after ) < 0 );
}

void TestQgsGeometry::multiLineString()

0 comments on commit bb425e4

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