Skip to content
Permalink
Browse files

Add reverse method to QgsLineSegment2D

  • Loading branch information
nyalldawson committed Apr 23, 2018
1 parent 646b4af commit 8f1d1a31c92c7e02fe1c263a35c12193867b2f3c
@@ -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 @@ def testPointLeftOfLine(self):
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()

0 comments on commit 8f1d1a3

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