Skip to content

Commit 4ff72de

Browse files
authoredDec 22, 2017
Merge pull request #5858 from lbartoletti/segment_intersection
Segment intersection
2 parents 36c4ac4 + 313417d commit 4ff72de

File tree

12 files changed

+292
-98
lines changed

12 files changed

+292
-98
lines changed
 

‎doc/api_break.dox

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1465,7 +1465,8 @@ QgsGeometryUtils {#qgis_api_break_3_0_QgsGeometryUtils}
14651465

14661466
- componentType enum has been renamed to ComponentType and its members were CamelCased too: VERTEX, RING and PART become Vertex, Ring and Part, respectively.
14671467
- adjacentVertices was removed - use QgsAbstractGeometry.adjacentVertices instead.
1468-
1468+
- segmentIntersection takes an optional boolean parameter "acceptImproperIntersection" returning true even if the intersection is improper.
1469+
Takes another boolean argument "isIntersection" returning if there is an intersection or not. The "inter" parameter has been renamed "intersectionPoint".
14691470

14701471
QgsGPSConnectionRegistry {#qgis_api_break_3_0_QgsGPSConnectionRegistry}
14711472
------------------------

‎python/core/geometry/qgsgeometryutils.sip

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,18 +100,42 @@ Returns the squared distance between a point and a line.
100100
:return: Whether the lines intersect
101101
%End
102102

103-
static bool segmentIntersection( const QgsPoint &p1, const QgsPoint &p2, const QgsPoint &q1, const QgsPoint &q2, QgsPoint &inter /Out/, double tolerance );
103+
static bool segmentIntersection( const QgsPoint &p1, const QgsPoint &p2, const QgsPoint &q1, const QgsPoint &q2, QgsPoint &intersectionPoint /Out/, bool &isIntersection /Out/, const double tolerance = 1e-8, bool acceptImproperIntersection = false );
104104
%Docstring
105105
Compute the intersection between two segments
106106

107107
:param p1: First segment start point
108108
:param p2: First segment end point
109109
:param q1: Second segment start point
110110
:param q2: Second segment end point
111-
:param inter: Output parameter, the intersection point
111+
:param intersectionPoint: Output parameter, the intersection point
112+
:param isIntersection: Output parameter, return true if an intersection is found
112113
:param tolerance: The tolerance to use
114+
:param acceptImproperIntersection: By default, this method returns true only if segments have proper intersection. If set true, returns also true if segments have improper intersection (end of one segment on other segment ; continuous segments).
113115

114116
:return: Whether the segments intersect
117+
* Example:
118+
\code{.py}
119+
ret = QgsGeometryUtils.segmentIntersection( QgsPoint( 0, 0 ), QgsPoint( 0, 1 ), QgsPoint( 1, 1 ), QgsPoint( 1, 0 ) )
120+
ret[0], ret[1].asWkt(), ret[2]
121+
# Whether the segments intersect, the intersection point, is intersect
122+
# (False, 'Point (0 0)', False)
123+
ret = QgsGeometryUtils.segmentIntersection( QgsPoint( 0, 0 ), QgsPoint( 0, 5 ), QgsPoint( 0, 5 ), QgsPoint( 1, 5 ) )
124+
ret[0], ret[1].asWkt(), ret[2]
125+
# (False, 'Point (0 5)', True)
126+
ret = QgsGeometryUtils.segmentIntersection( QgsPoint( 0, 0 ), QgsPoint( 0, 5 ), QgsPoint( 0, 5 ), QgsPoint( 1, 5 ), acceptImproperIntersection=True )
127+
ret[0], ret[1].asWkt(), ret[2]
128+
# (True, 'Point (0 5)', True)
129+
ret = QgsGeometryUtils.segmentIntersection( QgsPoint( 0, 0 ), QgsPoint( 0, 5 ), QgsPoint( 0, 2 ), QgsPoint( 1, 5 ) )
130+
ret[0], ret[1].asWkt(), ret[2]
131+
# (False, 'Point (0 2)', True)
132+
ret = QgsGeometryUtils.segmentIntersection( QgsPoint( 0, 0 ), QgsPoint( 0, 5 ), QgsPoint( 0, 2 ), QgsPoint( 1, 5 ), acceptImproperIntersection=True )
133+
ret[0], ret[1].asWkt(), ret[2]
134+
# (True, 'Point (0 2)', True)
135+
ret = QgsGeometryUtils.segmentIntersection( QgsPoint( 0, -5 ), QgsPoint( 0, 5 ), QgsPoint( 2, 0 ), QgsPoint( -1, 0 ) )
136+
ret[0], ret[1].asWkt(), ret[2]
137+
# (True, 'Point (0 0)', True)
138+
\endcode
115139
%End
116140

117141
static QgsPoint projPointOnSegment( const QgsPoint &p, const QgsPoint &s1, const QgsPoint &s2 );

‎src/analysis/vector/geometry_checker/qgsgeometrycheckerutils.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ namespace QgsGeometryCheckerUtils
257257
{
258258
QList<QgsPoint> intersections;
259259
QgsPoint inter;
260+
bool intersection = false;
260261
for ( int i = 0, n = line1->vertexCount() - 1; i < n; ++i )
261262
{
262263
for ( int j = 0, m = line2->vertexCount() - 1; j < m; ++j )
@@ -265,7 +266,7 @@ namespace QgsGeometryCheckerUtils
265266
QgsPoint p2 = line1->vertexAt( QgsVertexId( 0, 0, i + 1 ) );
266267
QgsPoint q1 = line2->vertexAt( QgsVertexId( 0, 0, j ) );
267268
QgsPoint q2 = line2->vertexAt( QgsVertexId( 0, 0, j + 1 ) );
268-
if ( QgsGeometryUtils::segmentIntersection( p1, p2, q1, q2, inter, tol ) )
269+
if ( QgsGeometryUtils::segmentIntersection( p1, p2, q1, q2, inter, intersection, tol ) )
269270
{
270271
intersections.append( inter );
271272
}

‎src/analysis/vector/geometry_checker/qgsgeometryselfintersectioncheck.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ void QgsGeometrySelfIntersectionCheck::fixError( QgsGeometryCheckError *error, i
114114
QgsPoint p2 = geom->vertexAt( QgsVertexId( vidx.part, vidx.ring, ( inter.segment1 + 1 ) % nVerts ) );
115115
QgsPoint q2 = geom->vertexAt( QgsVertexId( vidx.part, vidx.ring, ( inter.segment2 + 1 ) % nVerts ) );
116116
QgsPoint s;
117-
if ( !QgsGeometryUtils::segmentIntersection( p1, p2, q1, q2, s, mContext->tolerance ) )
117+
bool intersection = false;
118+
if ( !QgsGeometryUtils::segmentIntersection( p1, p2, q1, q2, s, intersection, mContext->tolerance ) )
118119
{
119120
error->setObsolete();
120121
return;

‎src/app/qgsmaptoolcircle2tangentspoint.cpp

Lines changed: 20 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "qgslinestring.h"
2626
#include "qgsmultipolygon.h"
2727
#include "qgsspinbox.h"
28+
#include "qgsgeometryutils.h"
2829
#include <memory>
2930
#include <QMouseEvent>
3031

@@ -61,9 +62,11 @@ void QgsMapToolCircle2TangentsPoint::cadCanvasReleaseEvent( QgsMapMouseEvent *e
6162
}
6263
if ( mPoints.size() == 4 )
6364
{
64-
QgsPointXY ptInter = intersect( QgsPointXY( mPoints.at( 0 ) ), QgsPointXY( mPoints.at( 1 ) ),
65-
QgsPointXY( mPoints.at( 2 ) ), QgsPointXY( mPoints.at( 3 ) ) );
66-
if ( ptInter == QgsPointXY() )
65+
bool isIntersect = false;
66+
QgsPoint ptInter;
67+
QgsGeometryUtils::segmentIntersection( mPoints.at( 0 ), mPoints.at( 1 ),
68+
mPoints.at( 2 ), mPoints.at( 3 ), ptInter, isIntersect );
69+
if ( !isIntersect )
6770
{
6871
QgisApp::instance()->messageBar()->pushMessage( tr( "Error" ), tr( "Segments are parallels" ),
6972
QgsMessageBar::CRITICAL, QgisApp::instance()->messageTimeout() );
@@ -144,64 +147,6 @@ void QgsMapToolCircle2TangentsPoint::cadCanvasMoveEvent( QgsMapMouseEvent *e )
144147
}
145148
}
146149

147-
QgsPointXY QgsMapToolCircle2TangentsPoint::intersect( QgsPointXY seg1_pt1, QgsPointXY seg1_pt2, QgsPointXY seg2_pt1, QgsPointXY seg2_pt2 )
148-
{
149-
/*
150-
* Public domain function by Darel Rex Finley, 2006
151-
* http://alienryderflex.com/intersect/
152-
*/
153-
QgsPointXY ptInter;
154-
155-
double Ax = seg1_pt1.x();
156-
double Ay = seg1_pt1.y();
157-
double Bx = seg1_pt2.x();
158-
double By = seg1_pt2.y();
159-
160-
double Cx = seg2_pt1.x();
161-
double Cy = seg2_pt1.y();
162-
double Dx = seg2_pt2.x();
163-
double Dy = seg2_pt2.y();
164-
165-
if ( ( ( Ax == Bx ) && ( Ay == By ) ) || ( ( Cx == Dx ) && ( Cy == Dy ) ) )
166-
return ptInter;
167-
168-
// (1) Translate the system so that point A is on the origin.
169-
Bx -= Ax;
170-
By -= Ay;
171-
Cx -= Ax;
172-
Cy -= Ay;
173-
Dx -= Ax;
174-
Dy -= Ay;
175-
176-
// Discover the length of segment A-B
177-
double distAB = sqrt( Bx * Bx + By * By );
178-
179-
// (2) Rotate the system so that point B is on the positive X axis.
180-
double theCos = Bx / distAB;
181-
double theSin = By / distAB;
182-
double newX = Cx * theCos + Cy * theSin;
183-
Cy = Cy * theCos - Cx * theSin;
184-
Cx = newX;
185-
newX = Dx * theCos + Dy * theSin;
186-
Dy = Dy * theCos - Dx * theSin;
187-
Dx = newX;
188-
189-
// Fail if the lines are parallel.
190-
if ( Cy == Dy )
191-
return ptInter;
192-
193-
// (3) Discover the position of the intersection point along line A-B.
194-
double ABpos = Dx + ( Cx - Dx ) * Dy / ( Dy - Cy );
195-
196-
// (4) Apply the discovered position to line A-B
197-
// in the original coordinate system.
198-
ptInter.setX( Ax + ABpos * theCos );
199-
ptInter.setY( Ay + ABpos * theSin );
200-
201-
// Success
202-
return ptInter;
203-
}
204-
205150
void QgsMapToolCircle2TangentsPoint::getPossibleCenter( )
206151
{
207152

@@ -226,20 +171,20 @@ void QgsMapToolCircle2TangentsPoint::getPossibleCenter( )
226171
QgsGeometry line2m = line2.offsetCurve( - mRadius, 8, QgsGeometry::JoinStyleBevel, 5 );
227172
QgsGeometry line2p = line2.offsetCurve( + mRadius, 8, QgsGeometry::JoinStyleBevel, 5 );
228173

229-
QgsPointXY p1 = intersect( line1m.asPolyline().at( 0 ), line1m.asPolyline().at( 1 ),
230-
line2m.asPolyline().at( 0 ), line2m.asPolyline().at( 1 ) );
231-
QgsPointXY p2 = intersect( line1m.asPolyline().at( 0 ), line1m.asPolyline().at( 1 ),
232-
line2p.asPolyline().at( 0 ), line2p.asPolyline().at( 1 ) );
233-
QgsPointXY p3 = intersect( line1p.asPolyline().at( 0 ), line1p.asPolyline().at( 1 ),
234-
line2m.asPolyline().at( 0 ), line2m.asPolyline().at( 1 ) );
235-
QgsPointXY p4 = intersect( line1p.asPolyline().at( 0 ), line1p.asPolyline().at( 1 ),
236-
line2p.asPolyline().at( 0 ), line2p.asPolyline().at( 1 ) );
237-
238-
mCenters.append( p1 );
239-
mCenters.append( p2 );
240-
mCenters.append( p3 );
241-
mCenters.append( p4 );
242-
174+
bool isIntersect = false;
175+
QgsPoint inter;
176+
QgsGeometryUtils::segmentIntersection( QgsPoint( line1m.asPolyline().at( 0 ) ), QgsPoint( line1m.asPolyline().at( 1 ) ),
177+
QgsPoint( line2m.asPolyline().at( 0 ) ), QgsPoint( line2m.asPolyline().at( 1 ) ), inter, isIntersect );
178+
mCenters.append( QgsPointXY( inter ) );
179+
QgsGeometryUtils::segmentIntersection( QgsPoint( line1m.asPolyline().at( 0 ) ), QgsPoint( line1m.asPolyline().at( 1 ) ),
180+
QgsPoint( line2p.asPolyline().at( 0 ) ), QgsPoint( line2p.asPolyline().at( 1 ) ), inter, isIntersect );
181+
mCenters.append( QgsPointXY( inter ) );
182+
QgsGeometryUtils::segmentIntersection( QgsPoint( line1p.asPolyline().at( 0 ) ), QgsPoint( line1p.asPolyline().at( 1 ) ),
183+
QgsPoint( line2m.asPolyline().at( 0 ) ), QgsPoint( line2m.asPolyline().at( 1 ) ), inter, isIntersect );
184+
mCenters.append( QgsPointXY( inter ) );
185+
QgsGeometryUtils::segmentIntersection( QgsPoint( line1p.asPolyline().at( 0 ) ), QgsPoint( line1p.asPolyline().at( 1 ) ),
186+
QgsPoint( line2p.asPolyline().at( 0 ) ), QgsPoint( line2p.asPolyline().at( 1 ) ), inter, isIntersect );
187+
mCenters.append( QgsPointXY( inter ) );
243188
}
244189
}
245190

‎src/app/qgsmaptoolcircle2tangentspoint.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@ class QgsMapToolCircle2TangentsPoint: public QgsMapToolAddCircle
3838
void radiusSpinBoxChanged( int radius );
3939

4040
private:
41-
//! Return the point where segments are intersected. Method from QgsGeometryUtils doesn't work for special cases used by this tool.
42-
QgsPointXY intersect( QgsPointXY seg1_pt1, QgsPointXY seg1_pt2, QgsPointXY seg2_pt1, QgsPointXY seg2_pt2 );
43-
4441
//! Compute 4 possible centers
4542
void getPossibleCenter();
4643

‎src/core/geometry/qgscircle.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,16 @@ QgsCircle QgsCircle::fromCenterPoint( const QgsPoint &center, const QgsPoint &pt
182182
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 )
183183
{
184184
QgsPoint p1, p2, p3;
185-
QgsGeometryUtils::segmentIntersection( pt1_tg1, pt2_tg1, pt1_tg2, pt2_tg2, p1, epsilon );
186-
QgsGeometryUtils::segmentIntersection( pt1_tg1, pt2_tg1, pt1_tg3, pt2_tg3, p2, epsilon );
187-
QgsGeometryUtils::segmentIntersection( pt1_tg2, pt2_tg2, pt1_tg3, pt2_tg3, p3, epsilon );
185+
bool isIntersect = false;
186+
QgsGeometryUtils::segmentIntersection( pt1_tg1, pt2_tg1, pt1_tg2, pt2_tg2, p1, isIntersect, epsilon );
187+
if ( !isIntersect )
188+
return QgsCircle();
189+
QgsGeometryUtils::segmentIntersection( pt1_tg1, pt2_tg1, pt1_tg3, pt2_tg3, p2, isIntersect, epsilon );
190+
if ( !isIntersect )
191+
return QgsCircle();
192+
QgsGeometryUtils::segmentIntersection( pt1_tg2, pt2_tg2, pt1_tg3, pt2_tg3, p3, isIntersect, epsilon );
193+
if ( !isIntersect )
194+
return QgsCircle();
188195

189196
return QgsTriangle( p1, p2, p3 ).inscribedCircle();
190197
}

‎src/core/geometry/qgsgeometryutils.cpp

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -251,28 +251,62 @@ bool QgsGeometryUtils::lineIntersection( const QgsPoint &p1, QgsVector v1, const
251251
return true;
252252
}
253253

254-
bool QgsGeometryUtils::segmentIntersection( const QgsPoint &p1, const QgsPoint &p2, const QgsPoint &q1, const QgsPoint &q2, QgsPoint &inter, double tolerance )
254+
bool QgsGeometryUtils::segmentIntersection( const QgsPoint &p1, const QgsPoint &p2, const QgsPoint &q1, const QgsPoint &q2, QgsPoint &intersectionPoint, bool &isIntersection, const double tolerance, bool acceptImproperIntersection )
255255
{
256+
isIntersection = false;
257+
256258
QgsVector v( p2.x() - p1.x(), p2.y() - p1.y() );
257259
QgsVector w( q2.x() - q1.x(), q2.y() - q1.y() );
258260
double vl = v.length();
259261
double wl = w.length();
260262

261-
if ( qgsDoubleNear( vl, 0, 0.000000000001 ) || qgsDoubleNear( wl, 0, 0.000000000001 ) )
263+
if ( qgsDoubleNear( vl, 0.0, tolerance ) || qgsDoubleNear( wl, 0.0, tolerance ) )
262264
{
263265
return false;
264266
}
265267
v = v / vl;
266268
w = w / wl;
267269

268-
if ( !QgsGeometryUtils::lineIntersection( p1, v, q1, w, inter ) )
270+
if ( !QgsGeometryUtils::lineIntersection( p1, v, q1, w, intersectionPoint ) )
271+
{
269272
return false;
273+
}
274+
275+
isIntersection = true;
276+
if ( acceptImproperIntersection )
277+
{
278+
if ( ( p1 == q1 ) || ( p1 == q2 ) )
279+
{
280+
intersectionPoint = p1;
281+
return true;
282+
}
283+
else if ( ( p2 == q1 ) || ( p2 == q2 ) )
284+
{
285+
intersectionPoint = p2;
286+
return true;
287+
}
288+
289+
double x, y;
290+
if (
291+
// intersectionPoint = p1
292+
qgsDoubleNear( QgsGeometryUtils::sqrDistToLine( p1.x(), p1.y(), q1.x(), q1.y(), q2.x(), q2.y(), x, y, tolerance ), 0.0, tolerance ) ||
293+
// intersectionPoint = p2
294+
qgsDoubleNear( QgsGeometryUtils::sqrDistToLine( p2.x(), p2.y(), q1.x(), q1.y(), q2.x(), q2.y(), x, y, tolerance ), 0.0, tolerance ) ||
295+
// intersectionPoint = q1
296+
qgsDoubleNear( QgsGeometryUtils::sqrDistToLine( q1.x(), q1.y(), p1.x(), p1.y(), p2.x(), p2.y(), x, y, tolerance ), 0.0, tolerance ) ||
297+
// intersectionPoint = q2
298+
qgsDoubleNear( QgsGeometryUtils::sqrDistToLine( q2.x(), q2.y(), p1.x(), p1.y(), p2.x(), p2.y(), x, y, tolerance ), 0.0, tolerance )
299+
)
300+
{
301+
return true;
302+
}
303+
}
270304

271-
double lambdav = QgsVector( inter.x() - p1.x(), inter.y() - p1.y() ) * v;
305+
double lambdav = QgsVector( intersectionPoint.x() - p1.x(), intersectionPoint.y() - p1.y() ) * v;
272306
if ( lambdav < 0. + tolerance || lambdav > vl - tolerance )
273307
return false;
274308

275-
double lambdaw = QgsVector( inter.x() - q1.x(), inter.y() - q1.y() ) * w;
309+
double lambdaw = QgsVector( intersectionPoint.x() - q1.x(), intersectionPoint.y() - q1.y() ) * w;
276310
return !( lambdaw < 0. + tolerance || lambdaw >= wl - tolerance );
277311
}
278312

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

301335
QgsPoint inter;
302-
if ( !QgsGeometryUtils::segmentIntersection( pi, pj, pk, pl, inter, tolerance ) ) continue;
336+
bool intersection = false;
337+
if ( !QgsGeometryUtils::segmentIntersection( pi, pj, pk, pl, inter, intersection, tolerance ) ) continue;
303338

304339
SelfIntersection s;
305340
s.segment1 = i;

‎src/core/geometry/qgsgeometryutils.h

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,35 @@ class CORE_EXPORT QgsGeometryUtils
106106
* \param p2 First segment end point
107107
* \param q1 Second segment start point
108108
* \param q2 Second segment end point
109-
* \param inter Output parameter, the intersection point
109+
* \param intersectionPoint Output parameter, the intersection point
110+
* \param isIntersection Output parameter, return true if an intersection is found
110111
* \param tolerance The tolerance to use
112+
* \param acceptImproperIntersection By default, this method returns true only if segments have proper intersection. If set true, returns also true if segments have improper intersection (end of one segment on other segment ; continuous segments).
111113
* \returns Whether the segments intersect
114+
* * Example:
115+
* \code{.py}
116+
* ret = QgsGeometryUtils.segmentIntersection( QgsPoint( 0, 0 ), QgsPoint( 0, 1 ), QgsPoint( 1, 1 ), QgsPoint( 1, 0 ) )
117+
* ret[0], ret[1].asWkt(), ret[2]
118+
* # Whether the segments intersect, the intersection point, is intersect
119+
* # (False, 'Point (0 0)', False)
120+
* ret = QgsGeometryUtils.segmentIntersection( QgsPoint( 0, 0 ), QgsPoint( 0, 5 ), QgsPoint( 0, 5 ), QgsPoint( 1, 5 ) )
121+
* ret[0], ret[1].asWkt(), ret[2]
122+
* # (False, 'Point (0 5)', True)
123+
* ret = QgsGeometryUtils.segmentIntersection( QgsPoint( 0, 0 ), QgsPoint( 0, 5 ), QgsPoint( 0, 5 ), QgsPoint( 1, 5 ), acceptImproperIntersection=True )
124+
* ret[0], ret[1].asWkt(), ret[2]
125+
* # (True, 'Point (0 5)', True)
126+
* ret = QgsGeometryUtils.segmentIntersection( QgsPoint( 0, 0 ), QgsPoint( 0, 5 ), QgsPoint( 0, 2 ), QgsPoint( 1, 5 ) )
127+
* ret[0], ret[1].asWkt(), ret[2]
128+
* # (False, 'Point (0 2)', True)
129+
* ret = QgsGeometryUtils.segmentIntersection( QgsPoint( 0, 0 ), QgsPoint( 0, 5 ), QgsPoint( 0, 2 ), QgsPoint( 1, 5 ), acceptImproperIntersection=True )
130+
* ret[0], ret[1].asWkt(), ret[2]
131+
* # (True, 'Point (0 2)', True)
132+
* ret = QgsGeometryUtils.segmentIntersection( QgsPoint( 0, -5 ), QgsPoint( 0, 5 ), QgsPoint( 2, 0 ), QgsPoint( -1, 0 ) )
133+
* ret[0], ret[1].asWkt(), ret[2]
134+
* # (True, 'Point (0 0)', True)
135+
* \endcode
112136
*/
113-
static bool segmentIntersection( const QgsPoint &p1, const QgsPoint &p2, const QgsPoint &q1, const QgsPoint &q2, QgsPoint &inter SIP_OUT, double tolerance );
137+
static bool segmentIntersection( const QgsPoint &p1, const QgsPoint &p2, const QgsPoint &q1, const QgsPoint &q2, QgsPoint &intersectionPoint SIP_OUT, bool &isIntersection SIP_OUT, const double tolerance = 1e-8, bool acceptImproperIntersection = false );
114138

115139
/**
116140
* \brief Project the point on a segment

‎src/core/geometry/qgstriangle.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -495,14 +495,15 @@ QVector<QgsLineString> QgsTriangle::bisectors( double lengthTolerance ) const
495495
QgsLineString bis3;
496496
QgsPoint incenter = inscribedCenter();
497497
QgsPoint out;
498+
bool intersection = false;
498499

499-
QgsGeometryUtils::segmentIntersection( vertexAt( 0 ), incenter, vertexAt( 1 ), vertexAt( 2 ), out, lengthTolerance );
500+
QgsGeometryUtils::segmentIntersection( vertexAt( 0 ), incenter, vertexAt( 1 ), vertexAt( 2 ), out, intersection, lengthTolerance );
500501
bis1.setPoints( QgsPointSequence() << vertexAt( 0 ) << out );
501502

502-
QgsGeometryUtils::segmentIntersection( vertexAt( 1 ), incenter, vertexAt( 0 ), vertexAt( 2 ), out, lengthTolerance );
503+
QgsGeometryUtils::segmentIntersection( vertexAt( 1 ), incenter, vertexAt( 0 ), vertexAt( 2 ), out, intersection, lengthTolerance );
503504
bis2.setPoints( QgsPointSequence() << vertexAt( 1 ) << out );
504505

505-
QgsGeometryUtils::segmentIntersection( vertexAt( 2 ), incenter, vertexAt( 0 ), vertexAt( 1 ), out, lengthTolerance );
506+
QgsGeometryUtils::segmentIntersection( vertexAt( 2 ), incenter, vertexAt( 0 ), vertexAt( 1 ), out, intersection, lengthTolerance );
506507
bis3.setPoints( QgsPointSequence() << vertexAt( 2 ) << out );
507508

508509
bis.append( bis1 );
@@ -529,7 +530,8 @@ QgsPoint QgsTriangle::orthocenter( double lengthTolerance ) const
529530
return QgsPoint();
530531
QVector<QgsLineString> alt = altitudes();
531532
QgsPoint ortho;
532-
QgsGeometryUtils::segmentIntersection( alt.at( 0 ).pointN( 0 ), alt.at( 0 ).pointN( 1 ), alt.at( 1 ).pointN( 0 ), alt.at( 1 ).pointN( 1 ), ortho, lengthTolerance );
533+
bool intersection;
534+
QgsGeometryUtils::segmentIntersection( alt.at( 0 ).pointN( 0 ), alt.at( 0 ).pointN( 1 ), alt.at( 1 ).pointN( 0 ), alt.at( 1 ).pointN( 1 ), ortho, intersection, lengthTolerance );
533535

534536
return ortho;
535537
}

0 commit comments

Comments
 (0)
Please sign in to comment.