Skip to content
Permalink
Browse files
Add tests. Thanks to @agiudiceandrea
  • Loading branch information
lbartoletti authored and m-kuhn committed Dec 27, 2021
1 parent 751e135 commit 20be0dec877fa9ae8a339c3e6d88486b4cbd5a03
Showing with 49 additions and 0 deletions.
  1. +49 −0 tests/src/core/testqgsgeometry.cpp
@@ -7306,6 +7306,55 @@ void TestQgsGeometry::triangle()


// lengths and angles
QgsTriangle tr( QgsPoint( 0, 0 ), QgsPoint( 0, 5 ), QgsPoint( 5, 5 ) );

QVector<double> a_tested;
QVector<double> angles = tr.angles();
a_tested.append( M_PI / 4.0 );
a_tested.append( M_PI / 2.0 );
a_tested.append( M_PI / 4.0 );

QGSCOMPARENEAR( a_tested.at( 0 ), angles.at( 0 ), 0.0001 );
QGSCOMPARENEAR( a_tested.at( 1 ), angles.at( 1 ), 0.0001 );
QGSCOMPARENEAR( a_tested.at( 2 ), angles.at( 2 ), 0.0001 );

QVector<double> a_empty = QgsTriangle().angles();
QVERIFY( a_empty.isEmpty() );

// From issue #46370
tr = QgsTriangle( QgsPoint( 0, 0 ), QgsPoint( 1, sqrt( 3 ) ), QgsPoint( 2, 0 ) );
angles = tr.angles();
QGSCOMPARENEAR( angles.at( 0 ), M_PI / 3.0, 0.0001 );
QGSCOMPARENEAR( angles.at( 1 ), M_PI / 3.0, 0.0001 );
QGSCOMPARENEAR( angles.at( 2 ), M_PI / 3.0, 0.0001 );

tr = QgsTriangle( QgsPoint( 2, 0 ), QgsPoint( 1, sqrt( 3 ) ), QgsPoint( 0, 0 ) );
angles = tr.angles();
QGSCOMPARENEAR( angles.at( 0 ), M_PI / 3.0, 0.0001 );
QGSCOMPARENEAR( angles.at( 1 ), M_PI / 3.0, 0.0001 );
QGSCOMPARENEAR( angles.at( 2 ), M_PI / 3.0, 0.0001 );

tr = QgsTriangle( QgsPoint( 0, 0 ), QgsPoint( 0, 3 ), QgsPoint( 4, 0 ) );
angles = tr.angles();
QGSCOMPARENEAR( angles.at( 0 ), M_PI / 2.0, 0.0001 );
QGSCOMPARENEAR( angles.at( 1 ), 0.9272952, 0.0001 );
QGSCOMPARENEAR( angles.at( 2 ), 0.6435011, 0.0001 );
tr = QgsTriangle( QgsPoint( 4, 0 ), QgsPoint( 0, 3 ), QgsPoint( 0, 0 ) );
angles = tr.angles();
QGSCOMPARENEAR( angles.at( 0 ), 0.6435011, 0.0001 );
QGSCOMPARENEAR( angles.at( 1 ), 0.9272952, 0.0001 );
QGSCOMPARENEAR( angles.at( 2 ), M_PI / 2.0, 0.0001 );

tr = QgsTriangle( QgsPoint( 0, 0 ), QgsPoint( 1, 3 ), QgsPoint( 3, 0 ) );
angles = tr.angles();
QGSCOMPARENEAR( angles.at( 0 ), 1.2490457, 0.0001 );
QGSCOMPARENEAR( angles.at( 1 ), 0.9097531, 0.0001 );
QGSCOMPARENEAR( angles.at( 2 ), 0.9827937, 0.0001 );
tr = QgsTriangle( QgsPoint( 3, 0 ), QgsPoint( 1, 3 ), QgsPoint( 0, 0 ) );
angles = tr.angles();
QGSCOMPARENEAR( angles.at( 0 ), 0.9827937, 0.0001 );
QGSCOMPARENEAR( angles.at( 1 ), 0.9097531, 0.0001 );
QGSCOMPARENEAR( angles.at( 2 ), 1.2490457, 0.0001 );
QgsTriangle t7( QgsPoint( 0, 0 ), QgsPoint( 0, 5 ), QgsPoint( 5, 5 ) );

QVector<double> a_tested, a_t7 = t7.angles();

0 comments on commit 20be0de

Please sign in to comment.