QGIS API Documentation 3.41.0-Master (af5edcb665c)
Loading...
Searching...
No Matches
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 mStart.distance( mEnd );
61 }
62
68 {
69 return mStart.sqrDist( mEnd );
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
223 bool operator==( const QgsLineSegment2D &other ) const SIP_HOLDGIL
224 {
225 return mStart == other.mStart && mEnd == other.mEnd;
226 }
227
228 bool operator!=( const QgsLineSegment2D &other ) const SIP_HOLDGIL
229 {
230 return mStart != other.mStart || mEnd != other.mEnd;
231 }
232
233 private:
234
235 QgsPointXY mStart;
236 QgsPointXY mEnd;
237
238};
239
240#endif // QGSLINESEGMENT_H
Represents a single 2D line segment, consisting of a 2D start and end vertex only.
double endY() const
Returns the segment's end y-coordinate.
QgsLineSegment2D(const QgsPointXY &start, const QgsPointXY &end)
Constructor for a QgsLineSegment2D from the specified start point to the end point.
QgsLineSegment2D(double x1, double y1, double x2, double y2)
Constructor for a QgsLineSegment2D from the point (x1, y2) to (x2, y2).
void setEnd(const QgsPointXY &end)
Sets the segment's end point.
QgsPointXY end() const
Returns the segment's end point.
double endX() const
Returns the segment's end x-coordinate.
void setStart(const QgsPointXY &start)
Sets the segment's start point.
void setStartX(double x)
Sets the segment's start x coordinate.
QgsPointXY start() const
Returns the segment's start point.
bool operator!=(const QgsLineSegment2D &other) const
bool operator==(const QgsLineSegment2D &other) const
double lengthSquared() const
Returns the squared length of the segment.
void setEndY(double y)
Sets the segment's end y coordinate.
void setStartY(double y)
Sets the segment's start y coordinate.
void setEndX(double x)
Sets the segment's end x coordinate.
double startX() const
Returns the segment's start x-coordinate.
void reverse()
Reverses the line segment, so that the start and end points are flipped.
double startY() const
Returns the segment's start y-coordinate.
double length() const
Returns the length of the segment.
Line string geometry type, with support for z-dimension and m-values.
A class to represent a 2D point.
Definition qgspointxy.h:60
#define SIP_HOLDGIL
Definition qgis_sip.h:171