Skip to content

Commit

Permalink
Expand QgsTriangle test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Sep 19, 2017
1 parent a15340f commit 9b6e79c
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
2 changes: 1 addition & 1 deletion python/core/geometry/qgstriangle.sip
Expand Up @@ -95,7 +95,7 @@ Inherited method not used. You cannot delete or insert a vertex directly. Return

virtual void setExteriorRing( QgsCurve *ring /Transfer/ );

virtual QgsAbstractGeometry *boundary() const /Factory/;
virtual QgsCurve *boundary() const /Factory/;


QgsPoint vertexAt( int atVertex ) const;
Expand Down
2 changes: 1 addition & 1 deletion src/core/geometry/qgstriangle.cpp
Expand Up @@ -346,7 +346,7 @@ void QgsTriangle::setExteriorRing( QgsCurve *ring )
clearCache();
}

QgsAbstractGeometry *QgsTriangle::boundary() const
QgsCurve *QgsTriangle::boundary() const
{
if ( !mExteriorRing )
return nullptr;
Expand Down
2 changes: 1 addition & 1 deletion src/core/geometry/qgstriangle.h
Expand Up @@ -93,7 +93,7 @@ class CORE_EXPORT QgsTriangle : public QgsPolygonV2

virtual void setExteriorRing( QgsCurve *ring SIP_TRANSFER ) override;

virtual QgsAbstractGeometry *boundary() const override SIP_FACTORY;
virtual QgsCurve *boundary() const override SIP_FACTORY;

// inherited: double pointDistanceToBoundary( double x, double y ) const;

Expand Down
33 changes: 33 additions & 0 deletions tests/src/core/testqgsgeometry.cpp
Expand Up @@ -3489,6 +3489,11 @@ void TestQgsGeometry::triangle()
QVERIFY( !t1.exteriorRing() );
QVERIFY( !t1.interiorRing( 0 ) );

// invalid triangles
QgsTriangle invalid( QgsPointXY( 0, 0 ), QgsPointXY( 0, 0 ), QgsPointXY( 10, 10 ) );
QVERIFY( invalid.isEmpty() );
invalid = QgsTriangle( QPointF( 0, 0 ), QPointF( 0, 0 ), QPointF( 10, 10 ) );
QVERIFY( invalid.isEmpty() );
//set exterior ring

//try with no ring
Expand Down Expand Up @@ -3583,6 +3588,14 @@ void TestQgsGeometry::triangle()
t2.setExteriorRing( ext );
QVERIFY( t2.isEmpty() );

ext->setPoints( QgsPointSequence() << QgsPoint( 0, 0 ) << QgsPoint( 0, 10 ) << QgsPoint( 0, 0 ) );
t2.setExteriorRing( ext );
QVERIFY( t2.isEmpty() );

ext->setPoints( QgsPointSequence() << QgsPoint( 0, 0 ) << QgsPoint( 0, 0 ) << QgsPoint( 0, 10 ) << QgsPoint( 0, 0 ) );
t2.setExteriorRing( ext );
QVERIFY( t2.isEmpty() );

// circular ring
QgsCircularString *circularRing = new QgsCircularString();
t2.clear();
Expand Down Expand Up @@ -3906,6 +3919,26 @@ void TestQgsGeometry::triangle()
pt1 = QgsPoint( 0, 0 );
QVERIFY( !t11.moveVertex( id, pt1 ) );

//toCurveType
QgsTriangle t12( QgsPoint( 7, 4 ), QgsPoint( 13, 3 ), QgsPoint( 9, 6 ) );
std::unique_ptr< QgsCurvePolygon > curveType( t12.toCurveType() );
QCOMPARE( curveType->wkbType(), QgsWkbTypes::CurvePolygon );
QCOMPARE( curveType->exteriorRing()->numPoints(), 4 );
QCOMPARE( curveType->exteriorRing()->vertexAt( QgsVertexId( 0, 0, 0 ) ), QgsPoint( 7, 4 ) );
QCOMPARE( curveType->exteriorRing()->vertexAt( QgsVertexId( 0, 0, 1 ) ), QgsPoint( 13, 3 ) );
QCOMPARE( curveType->exteriorRing()->vertexAt( QgsVertexId( 0, 0, 2 ) ), QgsPoint( 9, 6 ) );
QCOMPARE( curveType->exteriorRing()->vertexAt( QgsVertexId( 0, 0, 3 ) ), QgsPoint( 7, 4 ) );
QCOMPARE( curveType->numInteriorRings(), 0 );

// boundary
QVERIFY( !QgsTriangle().boundary() );
std::unique_ptr< QgsCurve > boundary( QgsTriangle( QgsPoint( 7, 4 ), QgsPoint( 13, 3 ), QgsPoint( 9, 6 ) ).boundary() );
QCOMPARE( boundary->wkbType(), QgsWkbTypes::LineString );
QCOMPARE( boundary->numPoints(), 4 );
QCOMPARE( boundary->vertexAt( QgsVertexId( 0, 0, 0 ) ), QgsPoint( 7, 4 ) );
QCOMPARE( boundary->vertexAt( QgsVertexId( 0, 0, 1 ) ), QgsPoint( 13, 3 ) );
QCOMPARE( boundary->vertexAt( QgsVertexId( 0, 0, 2 ) ), QgsPoint( 9, 6 ) );
QCOMPARE( boundary->vertexAt( QgsVertexId( 0, 0, 3 ) ), QgsPoint( 7, 4 ) );
}

void TestQgsGeometry::ellipse()
Expand Down

0 comments on commit 9b6e79c

Please sign in to comment.