mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-18 00:06:00 -04:00
Improved QgsClipper test, and ran prepare-commit
This commit is contained in:
parent
883dcab1fe
commit
96295010d3
@ -196,7 +196,7 @@ QString QgsRectangle::asWktCoordinates() const
|
|||||||
QString QgsRectangle::asWktPolygon() const
|
QString QgsRectangle::asWktPolygon() const
|
||||||
{
|
{
|
||||||
QString rep =
|
QString rep =
|
||||||
QString("POLYGON((") +
|
QString( "POLYGON((" ) +
|
||||||
QString::number( xmin, 'f', 16 ) + " " +
|
QString::number( xmin, 'f', 16 ) + " " +
|
||||||
QString::number( ymin, 'f', 16 ) + ", " +
|
QString::number( ymin, 'f', 16 ) + ", " +
|
||||||
QString::number( xmax, 'f', 16 ) + " " +
|
QString::number( xmax, 'f', 16 ) + " " +
|
||||||
@ -207,7 +207,7 @@ QString QgsRectangle::asWktPolygon() const
|
|||||||
QString::number( ymax, 'f', 16 ) + ", " +
|
QString::number( ymax, 'f', 16 ) + ", " +
|
||||||
QString::number( xmin, 'f', 16 ) + " " +
|
QString::number( xmin, 'f', 16 ) + " " +
|
||||||
QString::number( ymin, 'f', 16 ) +
|
QString::number( ymin, 'f', 16 ) +
|
||||||
QString("))");
|
QString( "))" );
|
||||||
|
|
||||||
return rep;
|
return rep;
|
||||||
}
|
}
|
||||||
@ -216,7 +216,7 @@ QString QgsRectangle::asWktPolygon() const
|
|||||||
//@note added in 2.0
|
//@note added in 2.0
|
||||||
QRectF QgsRectangle::toRectF() const
|
QRectF QgsRectangle::toRectF() const
|
||||||
{
|
{
|
||||||
return QRectF( (qreal)xmin, (qreal)ymin, (qreal)xmax - xmin, (qreal)ymax - ymin );
|
return QRectF(( qreal )xmin, ( qreal )ymin, ( qreal )xmax - xmin, ( qreal )ymax - ymin );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return a string representation of the rectangle with automatic or high precision
|
// Return a string representation of the rectangle with automatic or high precision
|
||||||
|
@ -34,36 +34,56 @@ class TestQgsClipper: public QObject
|
|||||||
void init() {};// will be called before each testfunction is executed.
|
void init() {};// will be called before each testfunction is executed.
|
||||||
void cleanup() {};// will be called after every testfunction.
|
void cleanup() {};// will be called after every testfunction.
|
||||||
void basic();
|
void basic();
|
||||||
|
private:
|
||||||
|
bool TestQgsClipper::checkBoundingBox( QPolygonF polygon, QgsRectangle clipRect );
|
||||||
};
|
};
|
||||||
|
|
||||||
void TestQgsClipper::initTestCase()
|
void TestQgsClipper::initTestCase()
|
||||||
{
|
{
|
||||||
//
|
|
||||||
// Runs once before any tests are run
|
|
||||||
//
|
|
||||||
// init QGIS's paths - true means that all path will be inited from prefix
|
|
||||||
// QgsApplication::init();
|
|
||||||
// QgsApplication::initQgis();
|
|
||||||
// QgsApplication::showSettings();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestQgsClipper::basic()
|
void TestQgsClipper::basic()
|
||||||
{
|
{
|
||||||
// CQgsClipper is static only
|
// QgsClipper is static only
|
||||||
//QgsClipper snipsnip;
|
|
||||||
|
|
||||||
QPolygonF polygon;
|
QPolygonF polygon;
|
||||||
polygon << QPointF(10.4, 20.5) << QPointF(20.2, 30.2);
|
polygon << QPointF( 10.4, 20.5 ) << QPointF( 20.2, 30.2 );
|
||||||
|
|
||||||
QgsRectangle clipRect(10, 10, 25, 30 );
|
QgsRectangle clipRect( 10, 10, 25, 30 );
|
||||||
|
|
||||||
QgsClipper::trimPolygon( polygon, clipRect );
|
QgsClipper::trimPolygon( polygon, clipRect );
|
||||||
|
|
||||||
QRectF bBox( polygon.boundingRect() );
|
// Check nothing sticks out.
|
||||||
QgsRectangle boundingRect( bBox.bottomLeft().x(), bBox.bottomLeft().y(), bBox.topRight().x(), bBox.topRight().y() );
|
QVERIFY( checkBoundingBox( polygon , clipRect ) );
|
||||||
|
// Check that it didn't clip too much
|
||||||
|
QgsRectangle clipRectInner( clipRect );
|
||||||
|
clipRectInner.scale( 0.999 );
|
||||||
|
QVERIFY( ! checkBoundingBox( polygon , clipRectInner ) );
|
||||||
|
|
||||||
QVERIFY( clipRect.contains( boundingRect ) );
|
// A more complex example
|
||||||
|
polygon.clear();
|
||||||
|
polygon << QPointF( 1.0, 9.0 ) << QPointF( 11.0, 11.0 ) << QPointF( 9.0, 1.0 );
|
||||||
|
clipRect.set( 0.0, 0.0, 10.0, 10.0 );
|
||||||
|
|
||||||
|
QgsClipper::trimPolygon( polygon, clipRect );
|
||||||
|
|
||||||
|
// We should have 5 vertices now?
|
||||||
|
QCOMPARE( polygon.size(), 5 );
|
||||||
|
// Check nothing sticks out.
|
||||||
|
QVERIFY( checkBoundingBox( polygon , clipRect ) );
|
||||||
|
// Check that it didn't clip too much
|
||||||
|
clipRectInner = clipRect;
|
||||||
|
clipRectInner.scale( 0.999 );
|
||||||
|
QVERIFY( ! checkBoundingBox( polygon , clipRectInner ) );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bool TestQgsClipper::checkBoundingBox( QPolygonF polygon, QgsRectangle clipRect )
|
||||||
|
{
|
||||||
|
QgsRectangle bBox( polygon.boundingRect() );
|
||||||
|
|
||||||
|
return clipRect.contains( bBox );
|
||||||
|
}
|
||||||
|
|
||||||
QTEST_MAIN( TestQgsClipper )
|
QTEST_MAIN( TestQgsClipper )
|
||||||
#include "moc_testqgsclipper.cxx"
|
#include "moc_testqgsclipper.cxx"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user