QGIS API Documentation 3.99.0-Master (d270888f95f)
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.h"
21#include "qgis_core.h"
22#include "qgis_sip.h"
23
24#include <QString>
25
26using namespace Qt::StringLiterals;
27
34class CORE_EXPORT QgsProfilePoint
35{
36 public:
37
41 QgsProfilePoint() = default;
42
47 : mDistance( distance )
48 , mElevation( elevation )
49 , mIsEmpty( false )
50 {}
51
58 {
59 mDistance = distance;
60 mIsEmpty = false;
61 }
62
69 {
70 mElevation = elevation;
71 mIsEmpty = false;
72 }
73
79 double distance() const SIP_HOLDGIL
80 {
81 return mDistance;
82 }
83
89 double elevation() const SIP_HOLDGIL
90 {
91 return mElevation;
92 }
93
99 bool isEmpty() const SIP_HOLDGIL { return mIsEmpty; }
100
102 {
103 if ( isEmpty() && other.isEmpty() )
104 return true;
105 if ( isEmpty() && !other.isEmpty() )
106 return false;
107 if ( ! isEmpty() && other.isEmpty() )
108 return false;
109
110 bool equal = true;
111 equal &= qgsDoubleNear( other.mDistance, mDistance, 1E-8 );
112 equal &= qgsDoubleNear( other.mElevation, mElevation, 1E-8 );
113
114 return equal;
115 }
116
117 bool operator!=( const QgsProfilePoint &other ) const SIP_HOLDGIL
118 {
119 if ( isEmpty() && other.isEmpty() )
120 return false;
121 if ( isEmpty() && !other.isEmpty() )
122 return true;
123 if ( ! isEmpty() && other.isEmpty() )
124 return true;
125
126 bool equal = true;
127 equal &= qgsDoubleNear( other.mDistance, mDistance, 1E-8 );
128 equal &= qgsDoubleNear( other.mElevation, mElevation, 1E-8 );
129
130 return !equal;
131 }
132
133#ifdef SIP_RUN
134 SIP_PYOBJECT __repr__();
135 % MethodCode
136 const QString str = sipCpp->isEmpty()
137 ? u"<QgsProfilePoint: EMPTY>"_s
138 : u"<QgsProfilePoint: %1, %2>"_s.arg( sipCpp->distance() ).arg( sipCpp->elevation() );
139 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
140 % End
141
142 int __len__();
143 % MethodCode
144 sipRes = 2;
145 % End
146
147 SIP_PYOBJECT __getitem__( int );
148 % MethodCode
149 if ( a0 == 0 )
150 {
151 sipRes = Py_BuildValue( "d", sipCpp->distance() );
152 }
153 else if ( a0 == 1 )
154 {
155 sipRes = Py_BuildValue( "d", sipCpp->elevation() );
156 }
157 else
158 {
159 QString msg = QString( "Bad index: %1" ).arg( a0 );
160 PyErr_SetString( PyExc_IndexError, msg.toLatin1().constData() );
161 }
162 % End
163
164#endif
165
166 private:
167
168 double mDistance = 0;
169 double mElevation = 0;
170 bool mIsEmpty = true;
171};
172
173#endif // QGSPROFILEPOINT_H
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.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference).
Definition qgis.h:6900
#define SIP_HOLDGIL
Definition qgis_sip.h:179