Skip to content

Commit 591c3ab

Browse files
committed
Remove QgsPoint::onSegment() method
This is a completely wrong use of an algorithm that is meant to be used with *integer* values, e.g. when dealing with pixels on screen, but not for coordinates that are floating point numbers. The algorithm has a fixed tolerance of 1 unit. QgsPoint(5,0.9).onSegment(QgsPoint(0,0), QgsPoint(10,0)) would return 2 (i.e. point is on line segment) See the original code: https://github.com/erich666/GraphicsGems/blob/master/gems/PntOnLine.c
1 parent 14ee435 commit 591c3ab

File tree

4 files changed

+6
-42
lines changed

4 files changed

+6
-42
lines changed

doc/api_break.dox

+6
Original file line numberDiff line numberDiff line change
@@ -1702,6 +1702,12 @@ QgsPluginLayerRegistry {#qgis_api_break_3_0_QgsPluginLayerRegistry}
17021702
- This class is no longer a singleton and instance() has been removed. Instead use QgsApplication::pluginLayerRegistry() to access an application-wide registry.
17031703

17041704

1705+
QgsPoint {#qgis_api_break_3_0_QgsPoint}
1706+
--------
1707+
1708+
- onSegment() has been removed. Use sqrDistToSegment() instead for a more precise test.
1709+
1710+
17051711
QgsPointDisplacementRenderer {#qgis_api_break_3_0_QgsPointDisplacementRenderer}
17061712
----------------------------
17071713

python/core/qgspoint.sip

-6
Original file line numberDiff line numberDiff line change
@@ -229,12 +229,6 @@ Inequality operator
229229
Multiply x and y by the given value
230230
%End
231231

232-
int onSegment( const QgsPoint &a, const QgsPoint &b ) const;
233-
%Docstring
234-
3 if point is on open ray b.
235-
:rtype: int
236-
%End
237-
238232

239233
QgsVector operator-( const QgsPoint &p ) const;
240234
%Docstring

src/core/qgspoint.cpp

-30
Original file line numberDiff line numberDiff line change
@@ -329,36 +329,6 @@ void QgsPoint::multiply( double scalar )
329329
mY *= scalar;
330330
}
331331

332-
int QgsPoint::onSegment( const QgsPoint &a, const QgsPoint &b ) const
333-
{
334-
//algorithm from 'graphics GEMS', A. Paeth: 'A Fast 2D Point-on-line test'
335-
if (
336-
qAbs( ( b.y() - a.y() ) * ( mX - a.x() ) - ( mY - a.y() ) * ( b.x() - a.x() ) )
337-
>= qMax( qAbs( b.x() - a.x() ), qAbs( b.y() - a.y() ) )
338-
)
339-
{
340-
return 0;
341-
}
342-
if ( ( b.x() < a.x() && a.x() < mX ) || ( b.y() < a.y() && a.y() < mY ) )
343-
{
344-
return 1;
345-
}
346-
if ( ( mX < a.x() && a.x() < b.x() ) || ( mY < a.y() && a.y() < b.y() ) )
347-
{
348-
return 1;
349-
}
350-
if ( ( a.x() < b.x() && b.x() < mX ) || ( a.y() < b.y() && b.y() < mY ) )
351-
{
352-
return 3;
353-
}
354-
if ( ( mX < b.x() && b.x() < a.x() ) || ( mY < b.y() && b.y() < a.y() ) )
355-
{
356-
return 3;
357-
}
358-
359-
return 2;
360-
}
361-
362332
double QgsPoint::sqrDistToSegment( double x1, double y1, double x2, double y2, QgsPoint &minDistPoint, double epsilon ) const
363333
{
364334
double nx, ny; //normal vector

src/core/qgspoint.h

-6
Original file line numberDiff line numberDiff line change
@@ -225,12 +225,6 @@ class CORE_EXPORT QgsPoint
225225
//! Multiply x and y by the given value
226226
void multiply( double scalar );
227227

228-
//! Test if this point is on the segment defined by points a, b
229-
//! \returns 0 if this point is not on the open ray through a and b,
230-
//! 1 if point is on open ray a, 2 if point is within line segment,
231-
//! 3 if point is on open ray b.
232-
int onSegment( const QgsPoint &a, const QgsPoint &b ) const;
233-
234228
//! Assignment
235229
QgsPoint &operator=( const QgsPoint &other );
236230

0 commit comments

Comments
 (0)