QGIS API Documentation 3.41.0-Master (3c143d501a8)
Loading...
Searching...
No Matches
qgsprofilepoint.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsprofilepoint.h
3 ---------------
4 begin : April 2022
5 copyright : (C) 2022 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#ifndef QGSPROFILEPOINT_H
18#define QGSPROFILEPOINT_H
19
20#include "qgis_core.h"
21#include "qgis_sip.h"
22#include "qgis.h"
23
30class CORE_EXPORT QgsProfilePoint
31{
32 public:
33
37 QgsProfilePoint() = default;
38
42 QgsProfilePoint( double distance, double elevation ) SIP_HOLDGIL
43 : mDistance( distance )
44 , mElevation( elevation )
45 , mIsEmpty( false )
46 {}
47
53 void setDistance( double distance ) SIP_HOLDGIL
54 {
55 mDistance = distance;
56 mIsEmpty = false;
57 }
58
64 void setElevation( double elevation ) SIP_HOLDGIL
65 {
66 mElevation = elevation;
67 mIsEmpty = false;
68 }
69
75 double distance() const SIP_HOLDGIL
76 {
77 return mDistance;
78 }
79
85 double elevation() const SIP_HOLDGIL
86 {
87 return mElevation;
88 }
89
95 bool isEmpty() const SIP_HOLDGIL { return mIsEmpty; }
96
98 {
99 if ( isEmpty() && other.isEmpty() )
100 return true;
101 if ( isEmpty() && !other.isEmpty() )
102 return false;
103 if ( ! isEmpty() && other.isEmpty() )
104 return false;
105
106 bool equal = true;
107 equal &= qgsDoubleNear( other.mDistance, mDistance, 1E-8 );
108 equal &= qgsDoubleNear( other.mElevation, mElevation, 1E-8 );
109
110 return equal;
111 }
112
113 bool operator!=( const QgsProfilePoint &other ) const SIP_HOLDGIL
114 {
115 if ( isEmpty() && other.isEmpty() )
116 return false;
117 if ( isEmpty() && !other.isEmpty() )
118 return true;
119 if ( ! isEmpty() && other.isEmpty() )
120 return true;
121
122 bool equal = true;
123 equal &= qgsDoubleNear( other.mDistance, mDistance, 1E-8 );
124 equal &= qgsDoubleNear( other.mElevation, mElevation, 1E-8 );
125
126 return !equal;
127 }
128
129#ifdef SIP_RUN
130 SIP_PYOBJECT __repr__();
131 % MethodCode
132 const QString str = sipCpp->isEmpty()
133 ? QStringLiteral( "<QgsProfilePoint: EMPTY>" )
134 : QStringLiteral( "<QgsProfilePoint: %1, %2>" ).arg( sipCpp->distance() ).arg( sipCpp->elevation() );
135 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
136 % End
137
138 int __len__();
139 % MethodCode
140 sipRes = 2;
141 % End
142
143 SIP_PYOBJECT __getitem__( int );
144 % MethodCode
145 if ( a0 == 0 )
146 {
147 sipRes = Py_BuildValue( "d", sipCpp->distance() );
148 }
149 else if ( a0 == 1 )
150 {
151 sipRes = Py_BuildValue( "d", sipCpp->elevation() );
152 }
153 else
154 {
155 QString msg = QString( "Bad index: %1" ).arg( a0 );
156 PyErr_SetString( PyExc_IndexError, msg.toLatin1().constData() );
157 }
158 % End
159
160#endif
161
162 private:
163
164 double mDistance = 0;
165 double mElevation = 0;
166 bool mIsEmpty = true;
167};
168
169#endif // QGSPROFILEPOINT_H
Encapsulates a point on a distance-elevation profile.
QgsProfilePoint()=default
Constructor for an empty point.
void setDistance(double distance)
Sets the distance of the point.
bool operator==(const QgsProfilePoint &other)
QgsProfilePoint(double distance, double elevation)
Create a point at the specified distance and elevation coordinates.
bool operator!=(const QgsProfilePoint &other) const
double elevation() const
Returns the elevation of the point.
double distance() const
Returns the distance of the point.
bool isEmpty() const
Returns true if the point is empty.
void setElevation(double elevation)
Sets the elevation of the point.
#define str(x)
Definition qgis.cpp:39
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
Definition qgis.h:6024
#define SIP_HOLDGIL
Definition qgis_sip.h:171