mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-27 00:33:48 -05:00
Add reverse method to QgsLineSegment2D
This commit is contained in:
parent
646b4af057
commit
8f1d1a31c9
@ -175,6 +175,11 @@ If the return value is 0, then the test was unsuccessful (e.g. due to testing a
|
||||
on the line, or exactly in line with the segment) and the result is undefined.
|
||||
|
||||
.. seealso:: :py:func:`QgsGeometryUtils.leftOfLine`
|
||||
%End
|
||||
|
||||
void reverse();
|
||||
%Docstring
|
||||
Reverses the line segment, so that the start and end points are flipped.
|
||||
%End
|
||||
|
||||
bool operator==( const QgsLineSegment2D &other ) const;
|
||||
|
@ -189,6 +189,14 @@ class CORE_EXPORT QgsLineSegment2D
|
||||
*/
|
||||
int pointLeftOfLine( const QgsPointXY &point ) const;
|
||||
|
||||
/**
|
||||
* Reverses the line segment, so that the start and end points are flipped.
|
||||
*/
|
||||
void reverse()
|
||||
{
|
||||
std::swap( mStart, mEnd );
|
||||
}
|
||||
|
||||
//! Equality operator
|
||||
bool operator==( const QgsLineSegment2D &other ) const
|
||||
{
|
||||
|
@ -112,6 +112,12 @@ class TestQgsLineSegment2D(unittest.TestCase):
|
||||
self.assertEqual(segment.pointLeftOfLine(QgsPointXY(1.5, -6)), -1)
|
||||
self.assertEqual(segment.pointLeftOfLine(QgsPointXY(5, 8)), 0)
|
||||
|
||||
def testReverse(self):
|
||||
segment = QgsLineSegment2D(QgsPointXY(1, 2), QgsPointXY(3, 4))
|
||||
segment.reverse()
|
||||
self.assertEqual(segment.start(), QgsPointXY(3, 4))
|
||||
self.assertEqual(segment.end(), QgsPointXY(1, 2))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
Loading…
x
Reference in New Issue
Block a user