QGIS API Documentation 3.29.0-Master (ade4f0cf0f)
qgslinesegment.h
Go to the documentation of this file.
1/***************************************************************************
2 qgslinesegment.h
3 -----------------
4 begin : April 2018
5 copyright : (C) 2018 by Nyall Dawson
6 email : nyall dot dawson at gmail dot com
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18#ifndef QGSLINESEGMENT_H
19#define QGSLINESEGMENT_H
20
21#include "qgis_core.h"
22#include "qgspointxy.h"
23
24class QgsLineString;
25
31class CORE_EXPORT QgsLineSegment2D
32{
33
34 public:
35
41 : mStart( start )
42 , mEnd( end )
43 {}
44
49 QgsLineSegment2D( double x1, double y1, double x2, double y2 ) SIP_HOLDGIL
50 : mStart( QgsPointXY( x1, y1 ) )
51 , mEnd( QgsPointXY( x2, y2 ) )
52 {}
53
58 double length() const SIP_HOLDGIL
59 {
60 return std::sqrt( ( mStart.x() - mEnd.x() ) * ( mStart.x() - mEnd.x() ) + ( mStart.y() - mEnd.y() ) * ( mStart.y() - mEnd.y() ) );
61 }
62
68 {
69 return ( mStart.x() - mEnd.x() ) * ( mStart.x() - mEnd.x() ) + ( mStart.y() - mEnd.y() ) * ( mStart.y() - mEnd.y() );
70 }
71
77 double startX() const SIP_HOLDGIL
78 {
79 return mStart.x();
80 }
81
87 double startY() const SIP_HOLDGIL
88 {
89 return mStart.y();
90 }
91
97 double endX() const SIP_HOLDGIL
98 {
99 return mEnd.x();
100 }
101
107 double endY() const SIP_HOLDGIL
108 {
109 return mEnd.y();
110 }
111
119 {
120 return mStart;
121 }
122
130 {
131 return mEnd;
132 }
133
140 void setStartX( double x ) SIP_HOLDGIL
141 {
142 mStart.setX( x );
143 }
144
151 void setStartY( double y ) SIP_HOLDGIL
152 {
153 mStart.setY( y );
154 }
155
162 void setEndX( double x ) SIP_HOLDGIL
163 {
164 mEnd.setX( x );
165 }
166
173 void setEndY( double y ) SIP_HOLDGIL
174 {
175 mEnd.setY( y );
176 }
177
184 void setStart( const QgsPointXY &start ) SIP_HOLDGIL
185 {
186 mStart = start;
187 }
188
195 void setEnd( const QgsPointXY &end ) SIP_HOLDGIL
196 {
197 mEnd = end;
198 }
199
211 int pointLeftOfLine( const QgsPointXY &point ) const SIP_HOLDGIL;
212
217 {
218 std::swap( mStart, mEnd );
219 }
220
221 // TODO c++20 - replace with = default
222
224 bool operator==( const QgsLineSegment2D &other ) const SIP_HOLDGIL
225 {
226 return mStart == other.mStart && mEnd == other.mEnd;
227 }
228
230 bool operator!=( const QgsLineSegment2D &other ) const SIP_HOLDGIL
231 {
232 return mStart != other.mStart || mEnd != other.mEnd;
233 }
234
235 private:
236
237 QgsPointXY mStart;
238 QgsPointXY mEnd;
239
240};
241
242#endif // QGSLINESEGMENT_H
Represents a single 2D line segment, consisting of a 2D start and end vertex only.
QgsPointXY end() const SIP_HOLDGIL
Returns the segment's end point.
void setStart(const QgsPointXY &start) SIP_HOLDGIL
Sets the segment's start point.
double endX() const SIP_HOLDGIL
Returns the segment's end x-coordinate.
QgsLineSegment2D(double x1, double y1, double x2, double y2) SIP_HOLDGIL
Constructor for a QgsLineSegment2D from the point (x1, y2) to (x2, y2).
void setStartX(double x) SIP_HOLDGIL
Sets the segment's start x coordinate.
double lengthSquared() const SIP_HOLDGIL
Returns the squared length of the segment.
double endY() const SIP_HOLDGIL
Returns the segment's end y-coordinate.
double startX() const SIP_HOLDGIL
Returns the segment's start x-coordinate.
void setEndY(double y) SIP_HOLDGIL
Sets the segment's end y coordinate.
QgsLineSegment2D(const QgsPointXY &start, const QgsPointXY &end) SIP_HOLDGIL
Constructor for a QgsLineSegment2D from the specified start point to the end point.
QgsPointXY start() const SIP_HOLDGIL
Returns the segment's start point.
void reverse() SIP_HOLDGIL
Reverses the line segment, so that the start and end points are flipped.
double length() const SIP_HOLDGIL
Returns the length of the segment.
bool operator==(const QgsLineSegment2D &other) const SIP_HOLDGIL
Equality operator.
void setEndX(double x) SIP_HOLDGIL
Sets the segment's end x coordinate.
void setEnd(const QgsPointXY &end) SIP_HOLDGIL
Sets the segment's end point.
void setStartY(double y) SIP_HOLDGIL
Sets the segment's start y coordinate.
double startY() const SIP_HOLDGIL
Returns the segment's start y-coordinate.
bool operator!=(const QgsLineSegment2D &other) const SIP_HOLDGIL
Inequality operator.
Line string geometry type, with support for z-dimension and m-values.
Definition: qgslinestring.h:45
A class to represent a 2D point.
Definition: qgspointxy.h:59
#define SIP_HOLDGIL
Definition: qgis_sip.h:166