Skip to content

Commit 6b07b9b

Browse files
committed
Extend geometry unit test coverage
1 parent f6d7120 commit 6b07b9b

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

src/core/geometry/qgspoint.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ QString QgsPoint::asJSON( int precision ) const
276276

277277
void QgsPoint::draw( QPainter &p ) const
278278
{
279-
p.drawRect( mX - 2, mY - 2, 4, 4 );
279+
p.drawRect( QRectF( mX - 2, mY - 2, 4, 4 ) );
280280
}
281281

282282
void QgsPoint::clear()

tests/src/core/testqgsgeometry.cpp

+31-1
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,7 @@ void TestQgsGeometry::point()
611611

612612
//bad WKT
613613
QVERIFY( !p14.fromWkt( "Polygon()" ) );
614+
QVERIFY( !p14.fromWkt( "Point(1 )" ) );
614615

615616
//asGML2
616617
QgsPoint exportPoint( 1, 2 );
@@ -626,6 +627,9 @@ void TestQgsGeometry::point()
626627
QCOMPARE( elemToString( exportPoint.asGML3( doc ) ), expectedGML3 );
627628
QString expectedGML3prec3( QStringLiteral( "<Point xmlns=\"gml\"><pos xmlns=\"gml\" srsDimension=\"2\">0.333 0.667</pos></Point>" ) );
628629
QCOMPARE( elemToString( exportPointFloat.asGML3( doc, 3 ) ), expectedGML3prec3 );
630+
QgsPoint exportPointZ( 1, 2, 3 );
631+
QString expectedGML2Z( QStringLiteral( "<Point xmlns=\"gml\"><pos xmlns=\"gml\" srsDimension=\"3\">1 2 3</pos></Point>" ) );
632+
QGSCOMPAREGML( elemToString( exportPointZ.asGML3( doc, 3 ) ), expectedGML2Z );
629633

630634
//asJSON
631635
QString expectedJson( QStringLiteral( "{\"type\": \"Point\", \"coordinates\": [1, 2]}" ) );
@@ -4010,9 +4014,15 @@ void TestQgsGeometry::ellipse()
40104014
QGSCOMPARENEARPOINT( q.at( 1 ), pts.at( 1 ), 2 );
40114015
QGSCOMPARENEARPOINT( q.at( 2 ), pts.at( 2 ), 2 );
40124016
QGSCOMPARENEARPOINT( q.at( 3 ), pts.at( 3 ), 2 );
4017+
4018+
QVERIFY( QgsEllipse( QgsPoint( 0, 0 ), 5, 2, 0 ).points( 2 ).isEmpty() ); // segments too low
4019+
40134020
// linestring
40144021
QgsLineString *l = new QgsLineString();
40154022

4023+
l = QgsEllipse( QgsPoint( 0, 0 ), 5, 2, 0 ).toLineString( 2 );
4024+
QVERIFY( l->isEmpty() ); // segments too low
4025+
40164026
l = QgsEllipse( QgsPoint( 0, 0 ), 5, 2, 0 ).toLineString( 4 );
40174027
QCOMPARE( l->numPoints(), 4 );
40184028
QgsPointSequence pts_l;
@@ -4022,6 +4032,9 @@ void TestQgsGeometry::ellipse()
40224032
// polygon
40234033
QgsPolygonV2 *p1 = new QgsPolygonV2();
40244034

4035+
p1 = QgsEllipse( QgsPoint( 0, 0 ), 5, 2, 0 ).toPolygon( 2 );
4036+
QVERIFY( p1->isEmpty() ); // segments too low
4037+
40254038
p1 = QgsEllipse( QgsPoint( 0, 0 ), 5, 2, 0 ).toPolygon( 4 );
40264039
q = QgsEllipse( QgsPoint( 0, 0 ), 5, 2, 0 ).quadrant();
40274040
QCOMPARE( p1->vertexAt( QgsVertexId( 0, 0, 0 ) ), q.at( 0 ) );
@@ -4420,6 +4433,18 @@ void TestQgsGeometry::regularPolygon()
44204433
QCOMPARE( rp8.interiorAngle(), 60.0 );
44214434
QCOMPARE( rp8.centralAngle(), 120.0 );
44224435

4436+
//points
4437+
rp8 = QgsRegularPolygon(); // empty
4438+
QgsPointSequence points = rp8.points();
4439+
QVERIFY( points.isEmpty() );
4440+
rp8 = QgsRegularPolygon( QgsPoint(), QgsPoint( 0, 5 ), 3, QgsRegularPolygon::InscribedCircle );
4441+
points = rp8.points();
4442+
QCOMPARE( points.count(), 3 );
4443+
QCOMPARE( points.at( 0 ), QgsPoint( 0, 5 ) );
4444+
QGSCOMPARENEAR( points.at( 1 ).x(), 4.33, 0.01 );
4445+
QGSCOMPARENEAR( points.at( 1 ).y(), -2.4999, 0.01 );
4446+
QGSCOMPARENEAR( points.at( 2 ).x(), -4.33, 0.01 );
4447+
QGSCOMPARENEAR( points.at( 2 ).y(), -2.4999, 0.01 );
44234448

44244449
//test conversions
44254450
// circle
@@ -4435,13 +4460,17 @@ void TestQgsGeometry::regularPolygon()
44354460

44364461
QgsRegularPolygon rp10 = QgsRegularPolygon( QgsPoint( 0, 0 ), QgsPoint( 0, 4 ), 4 );
44374462
QList<QgsTriangle> rp10_tri = rp10.triangulate();
4438-
QCOMPARE( rp10_tri.length(), ( int )rp10.numberSides() );
4463+
QCOMPARE( rp10_tri.length(), static_cast< int >( rp10.numberSides() ) );
44394464
QVERIFY( rp10_tri.at( 0 ) == QgsTriangle( QgsPoint( 0, 0 ), QgsPoint( 0, 4 ), rp10.center() ) );
44404465
QVERIFY( rp10_tri.at( 1 ) == QgsTriangle( QgsPoint( 0, 4 ), QgsPoint( 4, 4 ), rp10.center() ) );
44414466
QVERIFY( rp10_tri.at( 2 ) == QgsTriangle( QgsPoint( 4, 4 ), QgsPoint( 4, 0 ), rp10.center() ) );
44424467
QVERIFY( rp10_tri.at( 3 ) == QgsTriangle( QgsPoint( 4, 0 ), QgsPoint( 0, 0 ), rp10.center() ) );
44434468

4469+
QVERIFY( QgsRegularPolygon().triangulate().isEmpty() );
4470+
44444471
// polygon
4472+
QVERIFY( QgsRegularPolygon().toPolygon()->isEmpty() );
4473+
44454474
QgsPointSequence ptsPol;
44464475
std::unique_ptr< QgsPolygonV2 > pol( new QgsPolygonV2() );
44474476
pol.reset( rp10.toPolygon() );
@@ -4457,6 +4486,7 @@ void TestQgsGeometry::regularPolygon()
44574486
QVERIFY( ptsPol.at( 4 ) == QgsPoint( 0, 0 ) );
44584487
ptsPol.pop_back();
44594488

4489+
QVERIFY( QgsRegularPolygon( QgsPoint(), QgsPoint( 0, 5 ), 1, QgsRegularPolygon::InscribedCircle ).toLineString()->isEmpty() );
44604490
std::unique_ptr< QgsLineString > l( new QgsLineString() );
44614491
l.reset( rp10.toLineString() );
44624492
QCOMPARE( l->numPoints(), 4 );

tests/src/python/test_qgsbox3d.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def testToRectangle(self):
155155
rect = box.toRectangle()
156156
self.assertEqual(rect, QgsRectangle(5, 6, 11, 13))
157157

158-
def is2d(self):
158+
def testIs2d(self):
159159
box = QgsBox3d(5.0, 6.0, 7.0, 11.0, 13.0, 15.0)
160160
self.assertFalse(box.is2d())
161161
box = QgsBox3d(5.0, 6.0, 7.0, 11.0, 13.0, 7.0)

0 commit comments

Comments
 (0)