Skip to content
Permalink
Browse files

Add QgsLineSegment2D class, for simple 2d line segments which

consist of just a 2D start and end point
  • Loading branch information
nyalldawson committed Apr 23, 2018
1 parent 01f036c commit c6a50fe772192db51d9120265ed72b1d24c579f1
@@ -271,6 +271,7 @@
%Include geometry/qgsgeometrycollection.sip
%Include geometry/qgsgeometryengine.sip
%Include geometry/qgsgeometryutils.sip
%Include geometry/qgslinesegment.sip
%Include geometry/qgslinestring.sip
%Include geometry/qgsmulticurve.sip
%Include geometry/qgsmultilinestring.sip
@@ -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 *
************************************************************************/
@@ -1111,6 +1111,7 @@ SET(QGIS_CORE_HDRS
geometry/qgsgeometryutils.h
geometry/qgsgeos.h
geometry/qgsinternalgeometryengine.h
geometry/qgslinesegment.h
geometry/qgslinestring.h
geometry/qgsmulticurve.h
geometry/qgsmultilinestring.h
@@ -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

0 comments on commit c6a50fe

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