Skip to content

Commit 9305e22

Browse files
vcloarecnyalldawson
authored andcommittedSep 20, 2020
add tests and fix another issue
1 parent b5cdddf commit 9305e22

File tree

2 files changed

+65
-5
lines changed

2 files changed

+65
-5
lines changed
 

‎src/analysis/interpolation/qgsdualedgetriangulation.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -513,16 +513,21 @@ int QgsDualEdgeTriangulation::baseEdgeOfPoint( int point )
513513
{
514514
unsigned int actedge = mEdgeInside;//starting edge
515515

516-
if ( mPointVector.count() < 4 || point == -1 )//at the beginning, mEdgeInside is not defined yet
516+
if ( mPointVector.count() < 4 || point == -1 || mDimension == 1 ) //at the beginning, mEdgeInside is not defined yet
517517
{
518-
//first find pointingedge(an edge pointing to p1)
518+
int fromVirtualPoint = -1;
519+
//first find pointingedge(an edge pointing to p1, priority to edge that no come from virtual point)
519520
for ( int i = 0; i < mHalfEdge.count(); i++ )
520521
{
521-
if ( mHalfEdge[i]->getPoint() == point )//we found it
522+
if ( mHalfEdge[i]->getPoint() == point )//we found one
522523
{
523-
return i;
524+
if ( mHalfEdge[mHalfEdge[i]->getDual()]->getPoint() != -1 )
525+
return i;
526+
else
527+
fromVirtualPoint = i;
524528
}
525529
}
530+
return fromVirtualPoint;
526531
}
527532

528533
int control = 0;
@@ -1373,7 +1378,9 @@ int QgsDualEdgeTriangulation::insertForcedSegment( int p1, int p2, QgsInterpolat
13731378
}
13741379

13751380
//test, if the forced segment is a multiple of actEdge and if the direction is the same
1376-
else if ( /*lines are parallel*/( mPointVector[p2]->y() - mPointVector[p1]->y() ) / ( mPointVector[mHalfEdge[actEdge]->getPoint()]->y() - mPointVector[p1]->y() ) == ( mPointVector[p2]->x() - mPointVector[p1]->x() ) / ( mPointVector[mHalfEdge[actEdge]->getPoint()]->x() - mPointVector[p1]->x() ) && ( ( mPointVector[p2]->y() - mPointVector[p1]->y() ) >= 0 ) == ( ( mPointVector[mHalfEdge[actEdge]->getPoint()]->y() - mPointVector[p1]->y() ) > 0 ) && ( ( mPointVector[p2]->x() - mPointVector[p1]->x() ) >= 0 ) == ( ( mPointVector[mHalfEdge[actEdge]->getPoint()]->x() - mPointVector[p1]->x() ) > 0 ) )
1381+
else if ( /*lines are parallel*/( mPointVector[p2]->y() - mPointVector[p1]->y() ) / ( mPointVector[mHalfEdge[actEdge]->getPoint()]->y() - mPointVector[p1]->y() ) == ( mPointVector[p2]->x() - mPointVector[p1]->x() ) / ( mPointVector[mHalfEdge[actEdge]->getPoint()]->x() - mPointVector[p1]->x() )
1382+
&& ( ( mPointVector[p2]->y() - mPointVector[p1]->y() ) >= 0 ) == ( ( mPointVector[mHalfEdge[actEdge]->getPoint()]->y() - mPointVector[p1]->y() ) > 0 )
1383+
&& ( ( mPointVector[p2]->x() - mPointVector[p1]->x() ) >= 0 ) == ( ( mPointVector[mHalfEdge[actEdge]->getPoint()]->x() - mPointVector[p1]->x() ) > 0 ) )
13771384
{
13781385
//mark actedge and Dual(actedge) as forced, reset p1 and start the method from the beginning
13791386
mHalfEdge[actEdge]->setForced( true );

‎tests/src/analysis/testqgstriangulation.cpp

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class TestQgsTriangulation : public QObject
3636
void dualEdge();
3737

3838
void meshTriangulation();
39+
void meshTriangulationWithOnlyBreakLine();
3940

4041
private:
4142
};
@@ -239,5 +240,57 @@ void TestQgsTriangulation::meshTriangulation()
239240
QVERIFY( QgsMesh::compareFaces( mesh.face( 5 ), QgsMeshFace( {2, 4, 3} ) ) );
240241
}
241242

243+
void TestQgsTriangulation::meshTriangulationWithOnlyBreakLine()
244+
{
245+
QgsMeshTriangulation meshTri;
246+
247+
QgsVectorLayer *mLayerLineZ = new QgsVectorLayer( QStringLiteral( "LineStringZ" ),
248+
QStringLiteral( "break line Z" ),
249+
QStringLiteral( "memory" ) );
250+
251+
QStringList wktLines;
252+
253+
wktLines << QStringLiteral( "LineStringZ (315377.05605000001378357 5839566.94189499784260988 24.94718200000000152, 315374.77223399997455999 5839565.11973000038415194 24.04360499999999945)" )
254+
<< QStringLiteral( "LineStringZ (315369.53268400009255856 5839567.42751600034534931 25.41215299999999999, 315369.31927300000097603 5839570.36336500104516745 25.47851700000000008)" )
255+
<< QStringLiteral( "LineStringZ (315369.31927300000097603 5839570.36336500104516745 25.47851700000000008, 315377.62744900002144277 5839568.60983499884605408 24.98952099999999987)" )
256+
<< QStringLiteral( "LineStringZ (315369.53268400009255856 5839567.42751600034534931 25.41215299999999999, 315377.05605000001378357 5839566.94189499784260988 24.94718200000000152)" )
257+
<< QStringLiteral( "LineStringZ (315374.77223399997455999 5839565.11973000038415194 24.04360499999999945, 315370.67597402411047369 5839565.22503056097775698 24.04360499999999945)" )
258+
<< QStringLiteral( "LineStringZ (315370.67597402411047369 5839565.22503056097775698 24.04360499999999945, 315369.53268400009255856 5839567.42751600034534931 25.41215299999999999)" )
259+
<< QStringLiteral( "LineStringZ (315369.31927300000097603 5839570.36336500104516745 25.47851700000000008, 315371.93385799997486174 5839571.38528699986636639 24.06699300000000008)" )
260+
<< QStringLiteral( "LineStringZ (315371.93385799997486174 5839571.38528699986636639 24.06699300000000008, 315376.77400700020371005 5839570.69979299977421761 24.0794150000000009)" )
261+
<< QStringLiteral( "LineStringZ (315376.77400700020371005 5839570.69979299977421761 24.0794150000000009, 315377.62744900002144277 5839568.60983499884605408 24.98952099999999987)" )
262+
<< QStringLiteral( "LineStringZ (315377.62744900002144277 5839568.60983499884605408 24.98952099999999987, 315377.05605000001378357 5839566.94189499784260988 24.94718200000000152)" );
263+
264+
QgsFeatureList flist;
265+
for ( const QString &wkt : wktLines )
266+
{
267+
QgsFeature feat;
268+
feat.setGeometry( QgsGeometry::fromWkt( wkt ) );
269+
flist << feat;
270+
}
271+
272+
mLayerLineZ->dataProvider()->addFeatures( flist );
273+
274+
QgsCoordinateTransformContext transformContext;
275+
QgsCoordinateTransform transform( mLayerLineZ->crs(),
276+
QgsCoordinateReferenceSystem(),
277+
transformContext );
278+
279+
QgsFeatureIterator fIt = mLayerLineZ->getFeatures();
280+
meshTri.addBreakLines( fIt, -1, transform );
281+
282+
QgsMesh mesh = meshTri.triangulatedMesh();
283+
284+
QCOMPARE( mesh.vertexCount(), 8 );
285+
QCOMPARE( mesh.faceCount(), 6 );
286+
287+
QVERIFY( QgsMesh::compareFaces( mesh.face( 0 ), QgsMeshFace( {2, 0, 4} ) ) );
288+
QVERIFY( QgsMesh::compareFaces( mesh.face( 1 ), QgsMeshFace( {0, 2, 1} ) ) );
289+
QVERIFY( QgsMesh::compareFaces( mesh.face( 2 ), QgsMeshFace( {1, 2, 5} ) ) );
290+
QVERIFY( QgsMesh::compareFaces( mesh.face( 3 ), QgsMeshFace( {2, 4, 3} ) ) );
291+
QVERIFY( QgsMesh::compareFaces( mesh.face( 4 ), QgsMeshFace( {4, 6, 3} ) ) );
292+
QVERIFY( QgsMesh::compareFaces( mesh.face( 5 ), QgsMeshFace( {4, 7, 6} ) ) );
293+
}
294+
242295
QGSTEST_MAIN( TestQgsTriangulation )
243296
#include "testqgstriangulation.moc"

0 commit comments

Comments
 (0)
Please sign in to comment.