mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-17 00:04:02 -04:00
Finished unit tests
This commit is contained in:
parent
878dfddd3b
commit
5172a339ca
@ -15,6 +15,7 @@
|
||||
%Include qgscachedfeatureiterator.sip
|
||||
%Include qgscacheindex.sip
|
||||
%Include qgscacheindexfeatureid.sip
|
||||
%Include qgscadutils.sip
|
||||
%Include qgsclipper.sip
|
||||
%Include qgscolorramp.sip
|
||||
%Include qgscolorscheme.sip
|
||||
|
@ -24,6 +24,7 @@
|
||||
class QgsSnappingUtils;
|
||||
|
||||
/**
|
||||
* \ingroup core
|
||||
* The QgsCadUtils class provides routines for CAD editing.
|
||||
*
|
||||
* \since QGIS 3.0
|
||||
@ -58,15 +59,15 @@ class CORE_EXPORT QgsCadUtils
|
||||
double mapUnitsPerPixel;
|
||||
|
||||
//! Constraint for X coordinate
|
||||
AlignMapPointConstraint xConstraint;
|
||||
QgsCadUtils::AlignMapPointConstraint xConstraint;
|
||||
//! Constraint for Y coordinate
|
||||
AlignMapPointConstraint yConstraint;
|
||||
QgsCadUtils::AlignMapPointConstraint yConstraint;
|
||||
//! Constraint for distance
|
||||
AlignMapPointConstraint distanceConstraint;
|
||||
QgsCadUtils::AlignMapPointConstraint distanceConstraint;
|
||||
//! Constraint for angle
|
||||
AlignMapPointConstraint angleConstraint;
|
||||
QgsCadUtils::AlignMapPointConstraint angleConstraint;
|
||||
//! Constraint for soft lock to a common angle
|
||||
AlignMapPointConstraint commonAngleConstraint;
|
||||
QgsCadUtils::AlignMapPointConstraint commonAngleConstraint;
|
||||
|
||||
//! List of recent CAD points in map coordinates. These are used to turn relative constraints to absolute.
|
||||
//! First point is the most recent point. Currently using only "previous" point (index 1) and "penultimate"
|
||||
@ -97,7 +98,7 @@ class CORE_EXPORT QgsCadUtils
|
||||
* Returns a structure containing aligned map point, whether the constraints are valid and
|
||||
* some extra information.
|
||||
*/
|
||||
static AlignMapPointOutput alignMapPoint( const QgsPointXY &originalMapPoint, const AlignMapPointContext &ctx );
|
||||
static QgsCadUtils::AlignMapPointOutput alignMapPoint( const QgsPointXY &originalMapPoint, const QgsCadUtils::AlignMapPointContext &ctx );
|
||||
|
||||
};
|
||||
|
||||
|
@ -240,18 +240,98 @@ void TestQgsCadUtils::testCommonAngle()
|
||||
|
||||
void TestQgsCadUtils::testDistance()
|
||||
{
|
||||
// TODO:
|
||||
QgsCadUtils::AlignMapPointContext context( baseContext() );
|
||||
|
||||
// without distance constraint
|
||||
QgsCadUtils::AlignMapPointOutput res0 = QgsCadUtils::alignMapPoint( QgsPointXY( 45, 20 ), context );
|
||||
QVERIFY( res0.valid );
|
||||
QCOMPARE( res0.softLockCommonAngle, -1 );
|
||||
QCOMPARE( res0.finalMapPoint, QgsPointXY( 45, 20 ) );
|
||||
|
||||
// dist
|
||||
// dist+x / dist+y
|
||||
context.distanceConstraint = QgsCadUtils::AlignMapPointConstraint( true, true, 5 );
|
||||
QgsCadUtils::AlignMapPointOutput res1 = QgsCadUtils::alignMapPoint( QgsPointXY( 45, 20 ), context );
|
||||
QVERIFY( res1.valid );
|
||||
QCOMPARE( res1.finalMapPoint, QgsPointXY( 35, 20 ) );
|
||||
|
||||
// dist+x
|
||||
double d = 5 * sqrt( 2 ) / 2.; // sine/cosine of 45 times radius of our distance constraint
|
||||
double expectedX1 = 30 + d;
|
||||
double expectedY1 = 20 + d;
|
||||
context.xConstraint = QgsCadUtils::AlignMapPointConstraint( true, false, expectedX1 );
|
||||
QgsCadUtils::AlignMapPointOutput res2 = QgsCadUtils::alignMapPoint( QgsPointXY( 45, 25 ), context );
|
||||
QVERIFY( res2.valid );
|
||||
QCOMPARE( res2.finalMapPoint, QgsPointXY( expectedX1, expectedY1 ) );
|
||||
|
||||
// dist+x invalid
|
||||
context.xConstraint = QgsCadUtils::AlignMapPointConstraint( true, false, 1000 );
|
||||
QgsCadUtils::AlignMapPointOutput res2x = QgsCadUtils::alignMapPoint( QgsPointXY( 45, 25 ), context );
|
||||
QVERIFY( !res2x.valid );
|
||||
|
||||
// dist+y
|
||||
double expectedX2 = 30 + d;
|
||||
double expectedY2 = 20 - d;
|
||||
context.xConstraint = QgsCadUtils::AlignMapPointConstraint();
|
||||
context.yConstraint = QgsCadUtils::AlignMapPointConstraint( true, false, expectedY2 );
|
||||
QgsCadUtils::AlignMapPointOutput res3 = QgsCadUtils::alignMapPoint( QgsPointXY( 45, 15 ), context );
|
||||
QVERIFY( res3.valid );
|
||||
QCOMPARE( res3.finalMapPoint, QgsPointXY( expectedX2, expectedY2 ) );
|
||||
|
||||
// dist+y invalid
|
||||
context.yConstraint = QgsCadUtils::AlignMapPointConstraint( true, false, 1000 );
|
||||
QgsCadUtils::AlignMapPointOutput res3x = QgsCadUtils::alignMapPoint( QgsPointXY( 45, 15 ), context );
|
||||
QVERIFY( !res3x.valid );
|
||||
|
||||
// dist+angle
|
||||
context.yConstraint = QgsCadUtils::AlignMapPointConstraint();
|
||||
context.angleConstraint = QgsCadUtils::AlignMapPointConstraint( true, false, 45 );
|
||||
QgsCadUtils::AlignMapPointOutput res4 = QgsCadUtils::alignMapPoint( QgsPointXY( 25, 15 ), context );
|
||||
QVERIFY( res4.valid );
|
||||
QCOMPARE( res4.finalMapPoint, QgsPointXY( 30 - d, 20 - d ) );
|
||||
}
|
||||
|
||||
void TestQgsCadUtils::testEdge()
|
||||
{
|
||||
// TODO:
|
||||
// x+edge / y+edge
|
||||
QgsCadUtils::AlignMapPointContext context( baseContext() );
|
||||
context.cadPointList = QList<QgsPointXY>() << QgsPointXY() << QgsPointXY( 40, 30 ) << QgsPointXY( 40, 40 );
|
||||
|
||||
QgsPointXY edgePt( 20, 15 ); // in the middle of the triangle polygon's edge
|
||||
|
||||
// x+edge
|
||||
context.xConstraint = QgsCadUtils::AlignMapPointConstraint( true, false, 40 );
|
||||
QgsCadUtils::AlignMapPointOutput res0 = QgsCadUtils::alignMapPoint( edgePt, context );
|
||||
QVERIFY( res0.valid );
|
||||
QCOMPARE( res0.finalMapPoint, QgsPointXY( 40, 5 ) );
|
||||
|
||||
// y+edge
|
||||
context.xConstraint = QgsCadUtils::AlignMapPointConstraint();
|
||||
context.yConstraint = QgsCadUtils::AlignMapPointConstraint( true, false, 30 );
|
||||
QgsCadUtils::AlignMapPointOutput res1 = QgsCadUtils::alignMapPoint( edgePt, context );
|
||||
QVERIFY( res1.valid );
|
||||
//qDebug() << res1.finalMapPoint.toString();
|
||||
QCOMPARE( res1.finalMapPoint, QgsPointXY( -10, 30 ) );
|
||||
|
||||
// angle+edge
|
||||
context.yConstraint = QgsCadUtils::AlignMapPointConstraint();
|
||||
context.angleConstraint = QgsCadUtils::AlignMapPointConstraint( true, false, 90 );
|
||||
QgsCadUtils::AlignMapPointOutput res2 = QgsCadUtils::alignMapPoint( edgePt, context );
|
||||
QVERIFY( res2.valid );
|
||||
QCOMPARE( res2.finalMapPoint, QgsPointXY( 40, 5 ) );
|
||||
|
||||
context.angleConstraint = QgsCadUtils::AlignMapPointConstraint( true, false, 0 );
|
||||
QgsCadUtils::AlignMapPointOutput res3 = QgsCadUtils::alignMapPoint( edgePt, context );
|
||||
QVERIFY( res3.valid );
|
||||
QCOMPARE( res3.finalMapPoint, QgsPointXY( -10, 30 ) );
|
||||
|
||||
// distance+edge
|
||||
context.angleConstraint = QgsCadUtils::AlignMapPointConstraint();
|
||||
context.distanceConstraint = QgsCadUtils::AlignMapPointConstraint( true, false, 50 );
|
||||
QgsCadUtils::AlignMapPointOutput res4 = QgsCadUtils::alignMapPoint( edgePt, context );
|
||||
QVERIFY( res4.valid );
|
||||
qDebug() << res4.finalMapPoint.toString();
|
||||
// there is a tiny numerical error, so exact test with QgsPointXY does not work here
|
||||
QCOMPARE( res4.finalMapPoint.x(), -10. );
|
||||
QCOMPARE( res4.finalMapPoint.y(), 30. );
|
||||
}
|
||||
|
||||
QGSTEST_MAIN( TestQgsCadUtils )
|
||||
|
Loading…
x
Reference in New Issue
Block a user