QGIS API Documentation 3.99.0-Master (357b655ed83)
Loading...
Searching...
No Matches
qgssphere.h
Go to the documentation of this file.
1/***************************************************************************
2 qgssphere.h
3 --------------
4 begin : July 2023
5 copyright : (C) 2023 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 QGSSPHERE_H
19#define QGSSPHERE_H
20
21#include <limits>
22
23#include "qgis.h"
24#include "qgis_core.h"
25#include "qgis_sip.h"
26
27#include <QString>
28
29using namespace Qt::StringLiterals;
30
31class QgsPoint;
32class QgsCircle;
33class QgsBox3D;
34class QgsVector3D;
35
45class CORE_EXPORT QgsSphere
46{
47
48 public:
49
54
58 QgsSphere( double x, double y, double z, double radius ) SIP_HOLDGIL;
59
60 bool operator==( const QgsSphere &other ) const
61 {
62 return qgsDoubleNear( mCenterX, other.mCenterX ) && qgsDoubleNear( mCenterY, other.mCenterY ) && qgsDoubleNear( mCenterZ, other.mCenterZ ) && qgsDoubleNear( mRadius, other.mRadius );
63 }
64 bool operator!=( const QgsSphere &other ) const { return !( *this == other ); }
65
69 bool isNull() const SIP_HOLDGIL;
70
74 bool isEmpty() const SIP_HOLDGIL;
75
84 QgsPoint center() const SIP_HOLDGIL;
85
94 QgsVector3D centerVector() const SIP_HOLDGIL;
95
104 double centerX() const { return mCenterX; }
105
114 double centerY() const { return mCenterY; }
115
124 double centerZ() const { return mCenterZ; }
125
130 void setCenter( const QgsPoint &center ) SIP_HOLDGIL;
131
136 void setCenter( double x, double y, double z ) SIP_HOLDGIL { mCenterX = x; mCenterY = y; mCenterZ = z; }
137
144 double radius() const SIP_HOLDGIL { return mRadius; }
145
151 void setRadius( double radius ) SIP_HOLDGIL{ mRadius = radius; }
152
158 double diameter() const SIP_HOLDGIL { return mRadius * 2; }
159
163 double volume() const SIP_HOLDGIL;
164
168 double surfaceArea() const SIP_HOLDGIL;
169
173 QgsCircle toCircle() const SIP_HOLDGIL;
174
178 QgsBox3D boundingBox() const SIP_HOLDGIL;
179
180#ifdef SIP_RUN
181 SIP_PYOBJECT __repr__();
182 % MethodCode
183 QString str;
184 if ( sipCpp->isNull() )
185 {
186 str = u"<QgsSphere: null>"_s.arg( sipCpp->centerX() ).arg( sipCpp->centerY() ).arg( sipCpp->centerZ() ).arg( sipCpp->radius() );
187 }
188 else
189 {
190 str = u"<QgsSphere: (%1, %2, %3) radius %4>"_s.arg( sipCpp->centerX() ).arg( sipCpp->centerY() ).arg( sipCpp->centerZ() ).arg( sipCpp->radius() );
191 }
192 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
193 % End
194#endif
195
196 private:
197 double mCenterX = std::numeric_limits< double >::quiet_NaN();
198 double mCenterY = std::numeric_limits< double >::quiet_NaN();
199 double mCenterZ = std::numeric_limits< double >::quiet_NaN();
200 double mRadius = 0;
201
202};
203
204#endif // QGSSPHERE_H
A 3-dimensional box composed of x, y, z coordinates.
Definition qgsbox3d.h:45
Circle geometry type.
Definition qgscircle.h:46
Point geometry type, with support for z-dimension and m-values.
Definition qgspoint.h:53
QgsSphere()=default
Constructor for an invalid QgsSphere.
double centerY() const
Returns the y-coordinate of the center of the sphere.
Definition qgssphere.h:114
double radius() const
Returns the radius of the sphere.
Definition qgssphere.h:144
double diameter() const
Returns the diameter of the sphere.
Definition qgssphere.h:158
void setCenter(double x, double y, double z)
Sets the center point of the sphere to (x, y, z).
Definition qgssphere.h:136
bool operator!=(const QgsSphere &other) const
Definition qgssphere.h:64
double centerZ() const
Returns the z-coordinate of the center of the sphere.
Definition qgssphere.h:124
void setRadius(double radius)
Sets the radius of the sphere.
Definition qgssphere.h:151
double centerX() const
Returns the x-coordinate of the center of the sphere.
Definition qgssphere.h:104
A 3D vector (similar to QVector3D) with the difference that it uses double precision instead of singl...
Definition qgsvector3d.h:33
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference).
Definition qgis.h:6935
#define SIP_HOLDGIL
Definition qgis_sip.h:179