-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add QgsLineSegment2D class, for simple 2d line segments which
consist of just a 2D start and end point
- Loading branch information
1 parent
01f036c
commit c6a50fe
Showing
6 changed files
with
487 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,179 @@ | ||
/************************************************************************ | ||
* This file has been generated automatically from * | ||
* * | ||
* src/core/geometry/qgslinesegment.h * | ||
* * | ||
* Do not edit manually ! Edit header and run scripts/sipify.pl again * | ||
************************************************************************/ | ||
|
||
|
||
class QgsLineSegment2D | ||
{ | ||
%Docstring | ||
Represents a single 2D line segment, consisting of a 2D start and end vertex only. | ||
|
||
.. versionadded:: 3.2 | ||
%End | ||
|
||
%TypeHeaderCode | ||
#include "qgslinesegment.h" | ||
%End | ||
public: | ||
|
||
QgsLineSegment2D( const QgsPointXY &start, const QgsPointXY &end ); | ||
%Docstring | ||
Constructor for a QgsLineSegment2D from the specified ``start`` point to | ||
the ``end`` point. | ||
%End | ||
|
||
double length() const; | ||
%Docstring | ||
Returns the length of the segment. | ||
|
||
.. seealso:: :py:func:`lengthSquared` | ||
%End | ||
|
||
double lengthSquared() const; | ||
%Docstring | ||
Returns the squared length of the segment. | ||
|
||
.. seealso:: :py:func:`length` | ||
%End | ||
|
||
double startX() const; | ||
%Docstring | ||
Returns the segment's start x-coordinate. | ||
|
||
.. seealso:: :py:func:`start` | ||
|
||
.. seealso:: :py:func:`startY` | ||
%End | ||
|
||
double startY() const; | ||
%Docstring | ||
Returns the segment's start y-coordinate. | ||
|
||
.. seealso:: :py:func:`start` | ||
|
||
.. seealso:: :py:func:`startX` | ||
%End | ||
|
||
double endX() const; | ||
%Docstring | ||
Returns the segment's end x-coordinate. | ||
|
||
.. seealso:: :py:func:`end` | ||
|
||
.. seealso:: :py:func:`endY` | ||
%End | ||
|
||
double endY() const; | ||
%Docstring | ||
Returns the segment's end y-coordinate. | ||
|
||
.. seealso:: :py:func:`end` | ||
|
||
.. seealso:: :py:func:`endX` | ||
%End | ||
|
||
QgsPointXY start() const; | ||
%Docstring | ||
Returns the segment's start point. | ||
|
||
.. seealso:: :py:func:`end` | ||
|
||
.. seealso:: :py:func:`startX` | ||
|
||
.. seealso:: :py:func:`startY` | ||
%End | ||
|
||
QgsPointXY end() const; | ||
%Docstring | ||
Returns the segment's end point. | ||
|
||
.. seealso:: :py:func:`start` | ||
|
||
.. seealso:: :py:func:`endX` | ||
|
||
.. seealso:: :py:func:`endY` | ||
%End | ||
|
||
void setStartX( double x ); | ||
%Docstring | ||
Sets the segment's start ``x`` coordinate. | ||
|
||
.. seealso:: :py:func:`setEndX` | ||
|
||
.. seealso:: :py:func:`setStart` | ||
|
||
.. seealso:: :py:func:`setStartY` | ||
%End | ||
|
||
void setStartY( double y ); | ||
%Docstring | ||
Sets the segment's start ``y`` coordinate. | ||
|
||
.. seealso:: :py:func:`setEndY` | ||
|
||
.. seealso:: :py:func:`setStart` | ||
|
||
.. seealso:: :py:func:`setStartX` | ||
%End | ||
|
||
void setEndX( double x ); | ||
%Docstring | ||
Sets the segment's end ``x`` coordinate. | ||
|
||
.. seealso:: :py:func:`setStartX` | ||
|
||
.. seealso:: :py:func:`setEnd` | ||
|
||
.. seealso:: :py:func:`setEndY` | ||
%End | ||
|
||
void setEndY( double y ); | ||
%Docstring | ||
Sets the segment's end ``y`` coordinate. | ||
|
||
.. seealso:: :py:func:`setStartY` | ||
|
||
.. seealso:: :py:func:`setEnd` | ||
|
||
.. seealso:: :py:func:`setEndX` | ||
%End | ||
|
||
void setStart( const QgsPointXY &start ); | ||
%Docstring | ||
Sets the segment's ``start`` point. | ||
|
||
.. seealso:: :py:func:`setStartX` | ||
|
||
.. seealso:: :py:func:`setStartY` | ||
|
||
.. seealso:: :py:func:`setEnd` | ||
%End | ||
|
||
void setEnd( const QgsPointXY &end ); | ||
%Docstring | ||
Sets the segment's ``end`` point. | ||
|
||
.. seealso:: :py:func:`setEndX` | ||
|
||
.. seealso:: :py:func:`setEndY` | ||
|
||
.. seealso:: :py:func:`setStart` | ||
%End | ||
|
||
bool operator==( const QgsLineSegment2D &other ) const; | ||
|
||
bool operator!=( const QgsLineSegment2D &other ) const; | ||
|
||
}; | ||
|
||
/************************************************************************ | ||
* This file has been generated automatically from * | ||
* * | ||
* src/core/geometry/qgslinesegment.h * | ||
* * | ||
* Do not edit manually ! Edit header and run scripts/sipify.pl again * | ||
************************************************************************/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,198 @@ | ||
/*************************************************************************** | ||
qgslinesegment.h | ||
----------------- | ||
begin : April 2018 | ||
copyright : (C) 2018 by Nyall Dawson | ||
email : nyall dot dawson at gmail dot com | ||
***************************************************************************/ | ||
#ifndef QGSLINESEGMENT_H | ||
#define QGSLINESEGMENT_H | ||
|
||
#include "qgis_core.h" | ||
#include "qgspointxy.h" | ||
|
||
/** | ||
* \ingroup core | ||
* Represents a single 2D line segment, consisting of a 2D start and end vertex only. | ||
* \since QGIS 3.2 | ||
*/ | ||
class CORE_EXPORT QgsLineSegment2D | ||
{ | ||
|
||
public: | ||
|
||
/** | ||
* Constructor for a QgsLineSegment2D from the specified \a start point to | ||
* the \a end point. | ||
*/ | ||
QgsLineSegment2D( const QgsPointXY &start, const QgsPointXY &end ) | ||
: mStart( start ) | ||
, mEnd( end ) | ||
{} | ||
|
||
/** | ||
* Returns the length of the segment. | ||
* \see lengthSquared() | ||
*/ | ||
double length() const | ||
{ | ||
return std::sqrt( ( mStart.x() - mEnd.x() ) * ( mStart.x() - mEnd.x() ) + ( mStart.y() - mEnd.y() ) * ( mStart.y() - mEnd.y() ) ); | ||
} | ||
|
||
/** | ||
* Returns the squared length of the segment. | ||
* \see length() | ||
*/ | ||
double lengthSquared() const | ||
{ | ||
return ( mStart.x() - mEnd.x() ) * ( mStart.x() - mEnd.x() ) + ( mStart.y() - mEnd.y() ) * ( mStart.y() - mEnd.y() ); | ||
} | ||
|
||
/** | ||
* Returns the segment's start x-coordinate. | ||
* \see start() | ||
* \see startY() | ||
*/ | ||
double startX() const | ||
{ | ||
return mStart.x(); | ||
} | ||
|
||
/** | ||
* Returns the segment's start y-coordinate. | ||
* \see start() | ||
* \see startX() | ||
*/ | ||
double startY() const | ||
{ | ||
return mStart.y(); | ||
} | ||
|
||
/** | ||
* Returns the segment's end x-coordinate. | ||
* \see end() | ||
* \see endY() | ||
*/ | ||
double endX() const | ||
{ | ||
return mEnd.x(); | ||
} | ||
|
||
/** | ||
* Returns the segment's end y-coordinate. | ||
* \see end() | ||
* \see endX() | ||
*/ | ||
double endY() const | ||
{ | ||
return mEnd.y(); | ||
} | ||
|
||
/** | ||
* Returns the segment's start point. | ||
* \see end() | ||
* \see startX() | ||
* \see startY() | ||
*/ | ||
QgsPointXY start() const | ||
{ | ||
return mStart; | ||
} | ||
|
||
/** | ||
* Returns the segment's end point. | ||
* \see start() | ||
* \see endX() | ||
* \see endY() | ||
*/ | ||
QgsPointXY end() const | ||
{ | ||
return mEnd; | ||
} | ||
|
||
/** | ||
* Sets the segment's start \a x coordinate. | ||
* \see setEndX() | ||
* \see setStart() | ||
* \see setStartY() | ||
*/ | ||
void setStartX( double x ) | ||
{ | ||
mStart.setX( x ); | ||
} | ||
|
||
/** | ||
* Sets the segment's start \a y coordinate. | ||
* \see setEndY() | ||
* \see setStart() | ||
* \see setStartX() | ||
*/ | ||
void setStartY( double y ) | ||
{ | ||
mStart.setY( y ); | ||
} | ||
|
||
/** | ||
* Sets the segment's end \a x coordinate. | ||
* \see setStartX() | ||
* \see setEnd() | ||
* \see setEndY() | ||
*/ | ||
void setEndX( double x ) | ||
{ | ||
mEnd.setX( x ); | ||
} | ||
|
||
/** | ||
* Sets the segment's end \a y coordinate. | ||
* \see setStartY() | ||
* \see setEnd() | ||
* \see setEndX() | ||
*/ | ||
void setEndY( double y ) | ||
{ | ||
mEnd.setY( y ); | ||
} | ||
|
||
/** | ||
* Sets the segment's \a start point. | ||
* \see setStartX() | ||
* \see setStartY() | ||
* \see setEnd() | ||
*/ | ||
void setStart( const QgsPointXY &start ) | ||
{ | ||
mStart = start; | ||
} | ||
|
||
/** | ||
* Sets the segment's \a end point. | ||
* \see setEndX() | ||
* \see setEndY() | ||
* \see setStart() | ||
*/ | ||
void setEnd( const QgsPointXY &end ) | ||
{ | ||
mEnd = end; | ||
} | ||
|
||
//! Equality operator | ||
bool operator==( const QgsLineSegment2D &other ) const | ||
{ | ||
return mStart == other.mStart && mEnd == other.mEnd; | ||
} | ||
|
||
//! Inequality operator | ||
bool operator!=( const QgsLineSegment2D &other ) const | ||
{ | ||
return mStart != other.mStart || mEnd != other.mEnd; | ||
} | ||
|
||
private: | ||
|
||
QgsPointXY mStart; | ||
QgsPointXY mEnd; | ||
|
||
}; | ||
|
||
#endif // QGSLINESEGMENT_H |
Oops, something went wrong.