@@ -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
3941void 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
5046void 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+
6888QTEST_MAIN ( TestQgsClipper )
6989#include " moc_testqgsclipper.cxx"
0 commit comments