Skip to content

Commit 72f5adf

Browse files
committed
Add default value to epsilon.
Change example for python.
1 parent 89fb854 commit 72f5adf

File tree

4 files changed

+20
-24
lines changed

4 files changed

+20
-24
lines changed

python/core/geometry/qgsgeometryutils.sip

+7-8
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class QgsGeometryUtils
9898
:rtype: bool
9999
%End
100100

101-
static bool segmentIntersection( const QgsPoint &p1, const QgsPoint &p2, const QgsPoint &q1, const QgsPoint &q2, QgsPoint &intersectionPoint /Out/, bool &isIntersection /Out/, double tolerance, bool acceptImproperIntersection = false );
101+
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 );
102102
%Docstring
103103
Compute the intersection between two segments
104104
\param p1 First segment start point
@@ -112,24 +112,23 @@ class QgsGeometryUtils
112112
:return: Whether the segments intersect
113113
* Example:
114114
\code{.py}
115-
epsilon = 1e-8
116-
ret = QgsGeometryUtils.segmentIntersection( QgsPoint( 0, 0 ), QgsPoint( 0, 1 ), QgsPoint( 1, 1 ), QgsPoint( 1, 0 ), epsilon )
115+
ret = QgsGeometryUtils.segmentIntersection( QgsPoint( 0, 0 ), QgsPoint( 0, 1 ), QgsPoint( 1, 1 ), QgsPoint( 1, 0 ) )
117116
ret[0], ret[1].asWkt(), ret[2]
118117
# Whether the segments intersect, the intersection point, is intersect
119118
# (False, 'Point (0 0)', False)
120-
ret = QgsGeometryUtils.segmentIntersection( QgsPoint( 0, 0 ), QgsPoint( 0, 5 ), QgsPoint( 0, 5 ), QgsPoint( 1, 5 ), epsilon )
119+
ret = QgsGeometryUtils.segmentIntersection( QgsPoint( 0, 0 ), QgsPoint( 0, 5 ), QgsPoint( 0, 5 ), QgsPoint( 1, 5 ) )
121120
ret[0], ret[1].asWkt(), ret[2]
122121
# (False, 'Point (0 5)', True)
123-
ret = QgsGeometryUtils.segmentIntersection( QgsPoint( 0, 0 ), QgsPoint( 0, 5 ), QgsPoint( 0, 5 ), QgsPoint( 1, 5 ), epsilon, True )
122+
ret = QgsGeometryUtils.segmentIntersection( QgsPoint( 0, 0 ), QgsPoint( 0, 5 ), QgsPoint( 0, 5 ), QgsPoint( 1, 5 ), acceptImproperIntersection=True )
124123
ret[0], ret[1].asWkt(), ret[2]
125124
# (True, 'Point (0 5)', True)
126-
ret = QgsGeometryUtils.segmentIntersection( QgsPoint( 0, 0 ), QgsPoint( 0, 5 ), QgsPoint( 0, 2 ), QgsPoint( 1, 5 ), epsilon )
125+
ret = QgsGeometryUtils.segmentIntersection( QgsPoint( 0, 0 ), QgsPoint( 0, 5 ), QgsPoint( 0, 2 ), QgsPoint( 1, 5 ) )
127126
ret[0], ret[1].asWkt(), ret[2]
128127
# (False, 'Point (0 2)', True)
129-
ret = QgsGeometryUtils.segmentIntersection( QgsPoint( 0, 0 ), QgsPoint( 0, 5 ), QgsPoint( 0, 2 ), QgsPoint( 1, 5 ), epsilon, True )
128+
ret = QgsGeometryUtils.segmentIntersection( QgsPoint( 0, 0 ), QgsPoint( 0, 5 ), QgsPoint( 0, 2 ), QgsPoint( 1, 5 ), acceptImproperIntersection=True )
130129
ret[0], ret[1].asWkt(), ret[2]
131130
# (True, 'Point (0 2)', True)
132-
ret = QgsGeometryUtils.segmentIntersection( QgsPoint( 0, -5 ), QgsPoint( 0, 5 ), QgsPoint( 2, 0 ), QgsPoint( -1, 0 ), epsilon )
131+
ret = QgsGeometryUtils.segmentIntersection( QgsPoint( 0, -5 ), QgsPoint( 0, 5 ), QgsPoint( 2, 0 ), QgsPoint( -1, 0 ) )
133132
ret[0], ret[1].asWkt(), ret[2]
134133
# (True, 'Point (0 0)', True)
135134
\endcode

src/app/qgsmaptoolcircle2tangentspoint.cpp

+5-7
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,9 @@ void QgsMapToolCircle2TangentsPoint::cadCanvasReleaseEvent( QgsMapMouseEvent *e
6363
if ( mPoints.size() == 4 )
6464
{
6565
bool isIntersect = false;
66-
const double epsilon = 1e-8;
6766
QgsPoint ptInter;
6867
QgsGeometryUtils::segmentIntersection( mPoints.at( 0 ), mPoints.at( 1 ),
69-
mPoints.at( 2 ), mPoints.at( 3 ), ptInter, isIntersect, epsilon );
68+
mPoints.at( 2 ), mPoints.at( 3 ), ptInter, isIntersect );
7069
if ( !isIntersect )
7170
{
7271
QgisApp::instance()->messageBar()->pushMessage( tr( "Error" ), tr( "Segments are parallels" ),
@@ -173,19 +172,18 @@ void QgsMapToolCircle2TangentsPoint::getPossibleCenter( )
173172
QgsGeometry line2p = line2.offsetCurve( + mRadius, 8, QgsGeometry::JoinStyleBevel, 5 );
174173

175174
bool isIntersect = false;
176-
const double epsilon = 1e-8;
177175
QgsPoint inter;
178176
QgsGeometryUtils::segmentIntersection( QgsPoint( line1m.asPolyline().at( 0 ) ), QgsPoint( line1m.asPolyline().at( 1 ) ),
179-
QgsPoint( line2m.asPolyline().at( 0 ) ), QgsPoint( line2m.asPolyline().at( 1 ) ), inter, isIntersect, epsilon );
177+
QgsPoint( line2m.asPolyline().at( 0 ) ), QgsPoint( line2m.asPolyline().at( 1 ) ), inter, isIntersect );
180178
mCenters.append( QgsPointXY( inter ) );
181179
QgsGeometryUtils::segmentIntersection( QgsPoint( line1m.asPolyline().at( 0 ) ), QgsPoint( line1m.asPolyline().at( 1 ) ),
182-
QgsPoint( line2p.asPolyline().at( 0 ) ), QgsPoint( line2p.asPolyline().at( 1 ) ), inter, isIntersect, epsilon );
180+
QgsPoint( line2p.asPolyline().at( 0 ) ), QgsPoint( line2p.asPolyline().at( 1 ) ), inter, isIntersect );
183181
mCenters.append( QgsPointXY( inter ) );
184182
QgsGeometryUtils::segmentIntersection( QgsPoint( line1p.asPolyline().at( 0 ) ), QgsPoint( line1p.asPolyline().at( 1 ) ),
185-
QgsPoint( line2m.asPolyline().at( 0 ) ), QgsPoint( line2m.asPolyline().at( 1 ) ), inter, isIntersect, epsilon );
183+
QgsPoint( line2m.asPolyline().at( 0 ) ), QgsPoint( line2m.asPolyline().at( 1 ) ), inter, isIntersect );
186184
mCenters.append( QgsPointXY( inter ) );
187185
QgsGeometryUtils::segmentIntersection( QgsPoint( line1p.asPolyline().at( 0 ) ), QgsPoint( line1p.asPolyline().at( 1 ) ),
188-
QgsPoint( line2p.asPolyline().at( 0 ) ), QgsPoint( line2p.asPolyline().at( 1 ) ), inter, isIntersect, epsilon );
186+
QgsPoint( line2p.asPolyline().at( 0 ) ), QgsPoint( line2p.asPolyline().at( 1 ) ), inter, isIntersect );
189187
mCenters.append( QgsPointXY( inter ) );
190188
}
191189
}

src/core/geometry/qgsgeometryutils.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ bool QgsGeometryUtils::lineIntersection( const QgsPoint &p1, QgsVector v, const
251251
return true;
252252
}
253253

254-
bool QgsGeometryUtils::segmentIntersection( const QgsPoint &p1, const QgsPoint &p2, const QgsPoint &q1, const QgsPoint &q2, QgsPoint &intersectionPoint, bool &isIntersection, double tolerance, bool acceptImproperIntersection )
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
{
256256
isIntersection = false;
257257

src/core/geometry/qgsgeometryutils.h

+7-8
Original file line numberDiff line numberDiff line change
@@ -113,29 +113,28 @@ class CORE_EXPORT QgsGeometryUtils
113113
* \returns Whether the segments intersect
114114
* * Example:
115115
* \code{.py}
116-
* epsilon = 1e-8
117-
* ret = QgsGeometryUtils.segmentIntersection( QgsPoint( 0, 0 ), QgsPoint( 0, 1 ), QgsPoint( 1, 1 ), QgsPoint( 1, 0 ), epsilon )
116+
* ret = QgsGeometryUtils.segmentIntersection( QgsPoint( 0, 0 ), QgsPoint( 0, 1 ), QgsPoint( 1, 1 ), QgsPoint( 1, 0 ) )
118117
* ret[0], ret[1].asWkt(), ret[2]
119118
* # Whether the segments intersect, the intersection point, is intersect
120119
* # (False, 'Point (0 0)', False)
121-
* ret = QgsGeometryUtils.segmentIntersection( QgsPoint( 0, 0 ), QgsPoint( 0, 5 ), QgsPoint( 0, 5 ), QgsPoint( 1, 5 ), epsilon )
120+
* ret = QgsGeometryUtils.segmentIntersection( QgsPoint( 0, 0 ), QgsPoint( 0, 5 ), QgsPoint( 0, 5 ), QgsPoint( 1, 5 ) )
122121
* ret[0], ret[1].asWkt(), ret[2]
123122
* # (False, 'Point (0 5)', True)
124-
* ret = QgsGeometryUtils.segmentIntersection( QgsPoint( 0, 0 ), QgsPoint( 0, 5 ), QgsPoint( 0, 5 ), QgsPoint( 1, 5 ), epsilon, True )
123+
* ret = QgsGeometryUtils.segmentIntersection( QgsPoint( 0, 0 ), QgsPoint( 0, 5 ), QgsPoint( 0, 5 ), QgsPoint( 1, 5 ), acceptImproperIntersection=True )
125124
* ret[0], ret[1].asWkt(), ret[2]
126125
* # (True, 'Point (0 5)', True)
127-
* ret = QgsGeometryUtils.segmentIntersection( QgsPoint( 0, 0 ), QgsPoint( 0, 5 ), QgsPoint( 0, 2 ), QgsPoint( 1, 5 ), epsilon )
126+
* ret = QgsGeometryUtils.segmentIntersection( QgsPoint( 0, 0 ), QgsPoint( 0, 5 ), QgsPoint( 0, 2 ), QgsPoint( 1, 5 ) )
128127
* ret[0], ret[1].asWkt(), ret[2]
129128
* # (False, 'Point (0 2)', True)
130-
* ret = QgsGeometryUtils.segmentIntersection( QgsPoint( 0, 0 ), QgsPoint( 0, 5 ), QgsPoint( 0, 2 ), QgsPoint( 1, 5 ), epsilon, True )
129+
* ret = QgsGeometryUtils.segmentIntersection( QgsPoint( 0, 0 ), QgsPoint( 0, 5 ), QgsPoint( 0, 2 ), QgsPoint( 1, 5 ), acceptImproperIntersection=True )
131130
* ret[0], ret[1].asWkt(), ret[2]
132131
* # (True, 'Point (0 2)', True)
133-
* ret = QgsGeometryUtils.segmentIntersection( QgsPoint( 0, -5 ), QgsPoint( 0, 5 ), QgsPoint( 2, 0 ), QgsPoint( -1, 0 ), epsilon )
132+
* ret = QgsGeometryUtils.segmentIntersection( QgsPoint( 0, -5 ), QgsPoint( 0, 5 ), QgsPoint( 2, 0 ), QgsPoint( -1, 0 ) )
134133
* ret[0], ret[1].asWkt(), ret[2]
135134
* # (True, 'Point (0 0)', True)
136135
* \endcode
137136
*/
138-
static bool segmentIntersection( const QgsPoint &p1, const QgsPoint &p2, const QgsPoint &q1, const QgsPoint &q2, QgsPoint &intersectionPoint SIP_OUT, bool &isIntersection SIP_OUT, double tolerance, bool acceptImproperIntersection = false );
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 );
139138

140139
/**
141140
* \brief Project the point on a segment

0 commit comments

Comments
 (0)