QGIS API Documentation
4.3.0-Master (4ecdf0f3f59)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
core
geometry
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
24
class
QgsLineString
;
25
31
class
CORE_EXPORT
QgsLineSegment2D
32
{
33
public
:
34
// clang-format off
39
QgsLineSegment2D
(
const
QgsPointXY
&
start
,
const
QgsPointXY
&
end
)
SIP_HOLDGIL
40
// clang-format on
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
67
double
lengthSquared
() const
SIP_HOLDGIL
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
118
QgsPointXY
start
() const
SIP_HOLDGIL
119
{
120
return
mStart;
121
}
122
129
QgsPointXY
end
() const
SIP_HOLDGIL
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
216
void
reverse
()
SIP_HOLDGIL
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
QgsLineSegment2D::endY
double endY() const
Returns the segment's end y-coordinate.
Definition
qgslinesegment.h:107
QgsLineSegment2D::QgsLineSegment2D
QgsLineSegment2D(const QgsPointXY &start, const QgsPointXY &end)
Constructor for a QgsLineSegment2D from the specified start point to the end point.
Definition
qgslinesegment.h:39
QgsLineSegment2D::QgsLineSegment2D
QgsLineSegment2D(double x1, double y1, double x2, double y2)
Constructor for a QgsLineSegment2D from the point (x1, y2) to (x2, y2).
Definition
qgslinesegment.h:49
QgsLineSegment2D::setEnd
void setEnd(const QgsPointXY &end)
Sets the segment's end point.
Definition
qgslinesegment.h:195
QgsLineSegment2D::end
QgsPointXY end() const
Returns the segment's end point.
Definition
qgslinesegment.h:129
QgsLineSegment2D::endX
double endX() const
Returns the segment's end x-coordinate.
Definition
qgslinesegment.h:97
QgsLineSegment2D::setStart
void setStart(const QgsPointXY &start)
Sets the segment's start point.
Definition
qgslinesegment.h:184
QgsLineSegment2D::setStartX
void setStartX(double x)
Sets the segment's start x coordinate.
Definition
qgslinesegment.h:140
QgsLineSegment2D::start
QgsPointXY start() const
Returns the segment's start point.
Definition
qgslinesegment.h:118
QgsLineSegment2D::operator!=
bool operator!=(const QgsLineSegment2D &other) const
Definition
qgslinesegment.h:228
QgsLineSegment2D::operator==
bool operator==(const QgsLineSegment2D &other) const
Definition
qgslinesegment.h:223
QgsLineSegment2D::lengthSquared
double lengthSquared() const
Returns the squared length of the segment.
Definition
qgslinesegment.h:67
QgsLineSegment2D::setEndY
void setEndY(double y)
Sets the segment's end y coordinate.
Definition
qgslinesegment.h:173
QgsLineSegment2D::setStartY
void setStartY(double y)
Sets the segment's start y coordinate.
Definition
qgslinesegment.h:151
QgsLineSegment2D::setEndX
void setEndX(double x)
Sets the segment's end x coordinate.
Definition
qgslinesegment.h:162
QgsLineSegment2D::startX
double startX() const
Returns the segment's start x-coordinate.
Definition
qgslinesegment.h:77
QgsLineSegment2D::reverse
void reverse()
Reverses the line segment, so that the start and end points are flipped.
Definition
qgslinesegment.h:216
QgsLineSegment2D::startY
double startY() const
Returns the segment's start y-coordinate.
Definition
qgslinesegment.h:87
QgsLineSegment2D::length
double length() const
Returns the length of the segment.
Definition
qgslinesegment.h:58
QgsLineString
Line string geometry type, with support for z-dimension and m-values.
Definition
qgslinestring.h:49
QgsPointXY
Represents a 2D point.
Definition
qgspointxy.h:62
SIP_HOLDGIL
#define SIP_HOLDGIL
Definition
qgis_sip.h:183
qgspointxy.h
Generated on
for QGIS API Documentation by
1.17.0