Skip to content
Permalink
Browse files

- init variables

- fix equality
- add tests
  • Loading branch information
lbartoletti committed Dec 14, 2017
1 parent 03d8565 commit fb3aac8ef27e44e9794fc238dc2677da0bf878d9
@@ -257,7 +257,7 @@ namespace QgsGeometryCheckerUtils
{
QList<QgsPoint> intersections;
QgsPoint inter;
bool intersection;
bool intersection = false;
for ( int i = 0, n = line1->vertexCount() - 1; i < n; ++i )
{
for ( int j = 0, m = line2->vertexCount() - 1; j < m; ++j )
@@ -114,7 +114,7 @@ void QgsGeometrySelfIntersectionCheck::fixError( QgsGeometryCheckError *error, i
QgsPoint p2 = geom->vertexAt( QgsVertexId( vidx.part, vidx.ring, ( inter.segment1 + 1 ) % nVerts ) );
QgsPoint q2 = geom->vertexAt( QgsVertexId( vidx.part, vidx.ring, ( inter.segment2 + 1 ) % nVerts ) );
QgsPoint s;
bool intersection;
bool intersection = false;
if ( !QgsGeometryUtils::segmentIntersection( p1, p2, q1, q2, s, intersection, mContext->tolerance ) )
{
error->setObsolete();
@@ -62,7 +62,7 @@ void QgsMapToolCircle2TangentsPoint::cadCanvasReleaseEvent( QgsMapMouseEvent *e
}
if ( mPoints.size() == 4 )
{
bool isIntersect;
bool isIntersect = false;
const double epsilon = 1e-8;
QgsPoint ptInter;
QgsGeometryUtils::segmentIntersection( mPoints.at( 0 ), mPoints.at( 1 ),
@@ -172,7 +172,7 @@ void QgsMapToolCircle2TangentsPoint::getPossibleCenter( )
QgsGeometry line2m = line2.offsetCurve( - mRadius, 8, QgsGeometry::JoinStyleBevel, 5 );
QgsGeometry line2p = line2.offsetCurve( + mRadius, 8, QgsGeometry::JoinStyleBevel, 5 );

bool isIntersect;
bool isIntersect = false;
const double epsilon = 1e-8;
QgsPoint inter;
QgsGeometryUtils::segmentIntersection( QgsPoint( line1m.asPolyline().at( 0 ) ), QgsPoint( line1m.asPolyline().at( 1 ) ),
@@ -182,7 +182,7 @@ QgsCircle QgsCircle::fromCenterPoint( const QgsPoint &center, const QgsPoint &pt
QgsCircle QgsCircle::from3Tangents( const QgsPoint &pt1_tg1, const QgsPoint &pt2_tg1, const QgsPoint &pt1_tg2, const QgsPoint &pt2_tg2, const QgsPoint &pt1_tg3, const QgsPoint &pt2_tg3, double epsilon )
{
QgsPoint p1, p2, p3;
bool isIntersect;
bool isIntersect = false;
QgsGeometryUtils::segmentIntersection( pt1_tg1, pt2_tg1, pt1_tg2, pt2_tg2, p1, isIntersect, epsilon );
if ( !isIntersect )
return QgsCircle();
@@ -282,7 +282,7 @@ bool QgsGeometryUtils::segmentIntersection( const QgsPoint &p1, const QgsPoint &
}
else if ( ( p2 == q1 ) || ( p2 == q2 ) )
{
intersectionPoint == p2;
intersectionPoint = p2;
return true;
}

@@ -340,7 +340,7 @@ QVector<QgsGeometryUtils::SelfIntersection> QgsGeometryUtils::getSelfIntersectio
QgsPoint pl = geom->vertexAt( QgsVertexId( part, ring, l ) );

QgsPoint inter;
bool intersection;
bool intersection = false;
if ( !QgsGeometryUtils::segmentIntersection( pi, pj, pk, pl, inter, intersection, tolerance ) ) continue;

SelfIntersection s;
@@ -495,7 +495,7 @@ QVector<QgsLineString> QgsTriangle::bisectors( double lengthTolerance ) const
QgsLineString bis3;
QgsPoint incenter = inscribedCenter();
QgsPoint out;
bool intersection;
bool intersection = false;

QgsGeometryUtils::segmentIntersection( vertexAt( 0 ), incenter, vertexAt( 1 ), vertexAt( 2 ), out, intersection, lengthTolerance );
bis1.setPoints( QgsPointSequence() << vertexAt( 0 ) << out );
@@ -651,9 +651,20 @@ void TestQgsGeometryUtils::testClosestPoint()
void TestQgsGeometryUtils::testSegmentIntersection()
{
const double epsilon = 1e-8;
bool intersection, isIntersect;
bool intersection = false, isIntersect = false;
QgsPoint inter;
// null
intersection = QgsGeometryUtils::segmentIntersection( QgsPoint( 5, 5 ), QgsPoint( 5, 5 ), QgsPoint( 1, 1 ), QgsPoint( 1, 0 ), inter, isIntersect, epsilon );
QVERIFY( !intersection );
QVERIFY( !isIntersect );
QVERIFY( inter == QgsPoint() );
inter = QgsPoint();
intersection = QgsGeometryUtils::segmentIntersection( QgsPoint( 0, 0 ), QgsPoint( 0, 1 ), QgsPoint( 5, 5 ), QgsPoint( 5, 5 ), inter, isIntersect, epsilon, true );
QVERIFY( !intersection );
QVERIFY( !isIntersect );
QVERIFY( inter == QgsPoint() );
// parallel
inter = QgsPoint();
intersection = QgsGeometryUtils::segmentIntersection( QgsPoint( 0, 0 ), QgsPoint( 0, 1 ), QgsPoint( 1, 1 ), QgsPoint( 1, 0 ), inter, isIntersect, epsilon );
QVERIFY( !intersection );
QVERIFY( !isIntersect );
@@ -689,6 +700,36 @@ void TestQgsGeometryUtils::testSegmentIntersection()
QVERIFY( intersection );
QVERIFY( isIntersect );
QVERIFY( inter == QgsPoint( 0, 5 ) );
inter = QgsPoint();
intersection = QgsGeometryUtils::segmentIntersection( QgsPoint( 0, 5 ), QgsPoint( 0, 0 ), QgsPoint( 0, 5 ), QgsPoint( 1, 5 ), inter, isIntersect, epsilon );
QVERIFY( !intersection );
QVERIFY( isIntersect );
QVERIFY( inter == QgsPoint( 0, 5 ) );
inter = QgsPoint();
intersection = QgsGeometryUtils::segmentIntersection( QgsPoint( 0, 5 ), QgsPoint( 0, 0 ), QgsPoint( 0, 5 ), QgsPoint( 1, 5 ), inter, isIntersect, epsilon, true );
QVERIFY( intersection );
QVERIFY( isIntersect );
QVERIFY( inter == QgsPoint( 0, 5 ) );
inter = QgsPoint();
intersection = QgsGeometryUtils::segmentIntersection( QgsPoint( 0, 0 ), QgsPoint( 0, 5 ), QgsPoint( 1, 5 ), QgsPoint( 0, 5 ), inter, isIntersect, epsilon );
QVERIFY( !intersection );
QVERIFY( isIntersect );
QVERIFY( inter == QgsPoint( 0, 5 ) );
inter = QgsPoint();
intersection = QgsGeometryUtils::segmentIntersection( QgsPoint( 0, 0 ), QgsPoint( 0, 5 ), QgsPoint( 1, 5 ), QgsPoint( 0, 5 ), inter, isIntersect, epsilon, true );
QVERIFY( intersection );
QVERIFY( isIntersect );
QVERIFY( inter == QgsPoint( 0, 5 ) );
inter = QgsPoint();
intersection = QgsGeometryUtils::segmentIntersection( QgsPoint( 0, 5 ), QgsPoint( 0, 0 ), QgsPoint( 1, 5 ), QgsPoint( 0, 5 ), inter, isIntersect, epsilon );
QVERIFY( !intersection );
QVERIFY( isIntersect );
QVERIFY( inter == QgsPoint( 0, 5 ) );
inter = QgsPoint();
intersection = QgsGeometryUtils::segmentIntersection( QgsPoint( 0, 5 ), QgsPoint( 0, 0 ), QgsPoint( 1, 5 ), QgsPoint( 0, 5 ), inter, isIntersect, epsilon, true );
QVERIFY( intersection );
QVERIFY( isIntersect );
QVERIFY( inter == QgsPoint( 0, 5 ) );
// colinear
inter = QgsPoint();
intersection = QgsGeometryUtils::segmentIntersection( QgsPoint( 0, 0 ), QgsPoint( 0, 5 ), QgsPoint( 0, 5 ), QgsPoint( 0, 6 ), inter, isIntersect, epsilon );

0 comments on commit fb3aac8

Please sign in to comment.
You can’t perform that action at this time.