Skip to content

Commit 9629501

Browse files
committedSep 16, 2012
Improved QgsClipper test, and ran prepare-commit
1 parent 883dcab commit 9629501

File tree

3 files changed

+41
-21
lines changed

3 files changed

+41
-21
lines changed
 

‎python/core/qgsrectangle.sip

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class QgsRectangle
1010
%TypeHeaderCode
1111
#include <qgsrectangle.h>
1212
%End
13-
13+
1414
public:
1515
//! Constructor
1616
QgsRectangle(double xmin=0, double ymin=0, double xmax=0, double ymax=0);

‎src/core/qgsrectangle.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ QString QgsRectangle::asWktCoordinates() const
196196
QString QgsRectangle::asWktPolygon() const
197197
{
198198
QString rep =
199-
QString("POLYGON((") +
199+
QString( "POLYGON((" ) +
200200
QString::number( xmin, 'f', 16 ) + " " +
201201
QString::number( ymin, 'f', 16 ) + ", " +
202202
QString::number( xmax, 'f', 16 ) + " " +
@@ -207,7 +207,7 @@ QString QgsRectangle::asWktPolygon() const
207207
QString::number( ymax, 'f', 16 ) + ", " +
208208
QString::number( xmin, 'f', 16 ) + " " +
209209
QString::number( ymin, 'f', 16 ) +
210-
QString("))");
210+
QString( "))" );
211211

212212
return rep;
213213
}
@@ -216,7 +216,7 @@ QString QgsRectangle::asWktPolygon() const
216216
//@note added in 2.0
217217
QRectF QgsRectangle::toRectF() const
218218
{
219-
return QRectF( (qreal)xmin, (qreal)ymin, (qreal)xmax - xmin, (qreal)ymax - ymin );
219+
return QRectF(( qreal )xmin, ( qreal )ymin, ( qreal )xmax - xmin, ( qreal )ymax - ymin );
220220
}
221221

222222
// Return a string representation of the rectangle with automatic or high precision

‎tests/src/core/testqgsclipper.cpp

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,36 +34,56 @@ class TestQgsClipper: public QObject
3434
void init() {};// will be called before each testfunction is executed.
3535
void cleanup() {};// will be called after every testfunction.
3636
void basic();
37+
private:
38+
bool TestQgsClipper::checkBoundingBox( QPolygonF polygon, QgsRectangle clipRect );
3739
};
3840

3941
void TestQgsClipper::initTestCase()
4042
{
41-
//
42-
// Runs once before any tests are run
43-
//
44-
// init QGIS's paths - true means that all path will be inited from prefix
45-
// QgsApplication::init();
46-
// QgsApplication::initQgis();
47-
// QgsApplication::showSettings();
43+
4844
}
4945

5046
void TestQgsClipper::basic()
5147
{
52-
// CQgsClipper is static only
53-
//QgsClipper snipsnip;
48+
// QgsClipper is static only
5449

5550
QPolygonF polygon;
56-
polygon << QPointF(10.4, 20.5) << QPointF(20.2, 30.2);
57-
58-
QgsRectangle clipRect(10, 10, 25, 30 );
59-
51+
polygon << QPointF( 10.4, 20.5 ) << QPointF( 20.2, 30.2 );
52+
53+
QgsRectangle clipRect( 10, 10, 25, 30 );
54+
6055
QgsClipper::trimPolygon( polygon, clipRect );
61-
62-
QRectF bBox( polygon.boundingRect() );
63-
QgsRectangle boundingRect( bBox.bottomLeft().x(), bBox.bottomLeft().y(), bBox.topRight().x(), bBox.topRight().y() );
6456

65-
QVERIFY( clipRect.contains( boundingRect ) );
57+
// Check nothing sticks out.
58+
QVERIFY( checkBoundingBox( polygon , clipRect ) );
59+
// Check that it didn't clip too much
60+
QgsRectangle clipRectInner( clipRect );
61+
clipRectInner.scale( 0.999 );
62+
QVERIFY( ! checkBoundingBox( polygon , clipRectInner ) );
63+
64+
// A more complex example
65+
polygon.clear();
66+
polygon << QPointF( 1.0, 9.0 ) << QPointF( 11.0, 11.0 ) << QPointF( 9.0, 1.0 );
67+
clipRect.set( 0.0, 0.0, 10.0, 10.0 );
68+
69+
QgsClipper::trimPolygon( polygon, clipRect );
70+
71+
// We should have 5 vertices now?
72+
QCOMPARE( polygon.size(), 5 );
73+
// Check nothing sticks out.
74+
QVERIFY( checkBoundingBox( polygon , clipRect ) );
75+
// Check that it didn't clip too much
76+
clipRectInner = clipRect;
77+
clipRectInner.scale( 0.999 );
78+
QVERIFY( ! checkBoundingBox( polygon , clipRectInner ) );
6679
};
6780

81+
bool TestQgsClipper::checkBoundingBox( QPolygonF polygon, QgsRectangle clipRect )
82+
{
83+
QgsRectangle bBox( polygon.boundingRect() );
84+
85+
return clipRect.contains( bBox );
86+
}
87+
6888
QTEST_MAIN( TestQgsClipper )
6989
#include "moc_testqgsclipper.cxx"

0 commit comments

Comments
 (0)
Please sign in to comment.