QGIS API Documentation 3.99.0-Master (26c88405ac0)
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
27class QgsPoint;
28class QgsCircle;
29class QgsBox3D;
30class QgsVector3D;
31
41class CORE_EXPORT QgsSphere
42{
43
44 public:
45
50
54 QgsSphere( double x, double y, double z, double radius ) SIP_HOLDGIL;
55
56 bool operator==( const QgsSphere &other ) const
57 {
58 return qgsDoubleNear( mCenterX, other.mCenterX ) && qgsDoubleNear( mCenterY, other.mCenterY ) && qgsDoubleNear( mCenterZ, other.mCenterZ ) && qgsDoubleNear( mRadius, other.mRadius );
59 }
60 bool operator!=( const QgsSphere &other ) const { return !( *this == other ); }
61
65 bool isNull() const SIP_HOLDGIL;
66
70 bool isEmpty() const SIP_HOLDGIL;
71
80 QgsPoint center() const SIP_HOLDGIL;
81
90 QgsVector3D centerVector() const SIP_HOLDGIL;
91
100 double centerX() const { return mCenterX; }
101
110 double centerY() const { return mCenterY; }
111
120 double centerZ() const { return mCenterZ; }
121
126 void setCenter( const QgsPoint &center ) SIP_HOLDGIL;
127
132 void setCenter( double x, double y, double z ) SIP_HOLDGIL { mCenterX = x; mCenterY = y; mCenterZ = z; }
133
140 double radius() const SIP_HOLDGIL { return mRadius; }
141
147 void setRadius( double radius ) SIP_HOLDGIL{ mRadius = radius; }
148
154 double diameter() const SIP_HOLDGIL { return mRadius * 2; }
155
159 double volume() const SIP_HOLDGIL;
160
164 double surfaceArea() const SIP_HOLDGIL;
165
169 QgsCircle toCircle() const SIP_HOLDGIL;
170
174 QgsBox3D boundingBox() const SIP_HOLDGIL;
175
176#ifdef SIP_RUN
177 SIP_PYOBJECT __repr__();
178 % MethodCode
179 QString str;
180 if ( sipCpp->isNull() )
181 {
182 str = QStringLiteral( "<QgsSphere: null>" ).arg( sipCpp->centerX() ).arg( sipCpp->centerY() ).arg( sipCpp->centerZ() ).arg( sipCpp->radius() );
183 }
184 else
185 {
186 str = QStringLiteral( "<QgsSphere: (%1, %2, %3) radius %4>" ).arg( sipCpp->centerX() ).arg( sipCpp->centerY() ).arg( sipCpp->centerZ() ).arg( sipCpp->radius() );
187 }
188 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
189 % End
190#endif
191
192 private:
193 double mCenterX = std::numeric_limits< double >::quiet_NaN();
194 double mCenterY = std::numeric_limits< double >::quiet_NaN();
195 double mCenterZ = std::numeric_limits< double >::quiet_NaN();
196 double mRadius = 0;
197
198};
199
200#endif // QGSSPHERE_H
A 3-dimensional box composed of x, y, z coordinates.
Definition qgsbox3d.h:42
Circle geometry type.
Definition qgscircle.h:44
Point geometry type, with support for z-dimension and m-values.
Definition qgspoint.h:49
QgsSphere()=default
Constructor for an invalid QgsSphere.
double centerY() const
Returns the y-coordinate of the center of the sphere.
Definition qgssphere.h:110
double radius() const
Returns the radius of the sphere.
Definition qgssphere.h:140
double diameter() const
Returns the diameter of the sphere.
Definition qgssphere.h:154
void setCenter(double x, double y, double z)
Sets the center point of the sphere to (x, y, z).
Definition qgssphere.h:132
bool operator!=(const QgsSphere &other) const
Definition qgssphere.h:60
double centerZ() const
Returns the z-coordinate of the center of the sphere.
Definition qgssphere.h:120
void setRadius(double radius)
Sets the radius of the sphere.
Definition qgssphere.h:147
double centerX() const
Returns the x-coordinate of the center of the sphere.
Definition qgssphere.h:100
A 3D vector (similar to QVector3D) with the difference that it uses double precision instead of singl...
Definition qgsvector3d.h:30
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference).
Definition qgis.h:6607
#define SIP_HOLDGIL
Definition qgis_sip.h:179