QGIS API Documentation  3.37.0-Master (a5b4d9743e8)
qgsaabb.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsaabb.h
3  --------------------------------------
4  Date : July 2017
5  Copyright : (C) 2017 by Martin Dobias
6  Email : wonder dot sk at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #ifndef QGSAABB_H
17 #define QGSAABB_H
18 
19 #include "qgis_3d.h"
20 
21 #include <cmath>
22 #include <QList>
23 #include <QVector3D>
24 
25 #define SIP_NO_FILE
26 
32 class _3D_EXPORT QgsAABB
33 {
34  public:
36  QgsAABB() = default;
37 
39  QgsAABB( float xMin, float yMin, float zMin, float xMax, float yMax, float zMax );
40 
42  float xExtent() const { return xMax - xMin; }
44  float yExtent() const { return yMax - yMin; }
46  float zExtent() const { return zMax - zMin; }
47 
49  float xCenter() const { return ( xMax + xMin ) / 2; }
51  float yCenter() const { return ( yMax + yMin ) / 2; }
53  float zCenter() const { return ( zMax + zMin ) / 2; }
54 
56  QVector3D center() const { return QVector3D( xCenter(), yCenter(), zCenter() ); }
58  QVector3D minimum() const { return QVector3D( xMin, yMin, zMin ); }
60  QVector3D maximum() const { return QVector3D( xMax, yMax, zMax ); }
61 
63  bool intersects( const QgsAABB &other ) const;
64 
66  bool intersects( float x, float y, float z ) const;
67 
69  float distanceFromPoint( float x, float y, float z ) const;
70 
72  float distanceFromPoint( QVector3D v ) const;
73 
75  QList<QVector3D> verticesForLines() const;
76 
78  QString toString() const;
79 
81  bool isEmpty() const
82  {
83  return xMin == xMax && yMin == yMax && zMin == zMax;
84  }
85 
86  float xMin = 0.0f;
87  float yMin = 0.0f;
88  float zMin = 0.0f;
89  float xMax = 0.0f;
90  float yMax = 0.0f;
91  float zMax = 0.0f;
92 };
93 
94 #endif // QGSAABB_H
3
Definition: qgsaabb.h:33
float yExtent() const
Returns box width in Y axis.
Definition: qgsaabb.h:44
QVector3D center() const
Returns coordinates of the center of the box.
Definition: qgsaabb.h:56
float xExtent() const
Returns box width in X axis.
Definition: qgsaabb.h:42
float xCenter() const
Returns center in X axis.
Definition: qgsaabb.h:49
float zExtent() const
Returns box width in Z axis.
Definition: qgsaabb.h:46
bool isEmpty() const
Returns true if xExtent(), yExtent() and zExtent() are all zero, false otherwise.
Definition: qgsaabb.h:81
QVector3D minimum() const
Returns corner of the box with minimal coordinates.
Definition: qgsaabb.h:58
float yCenter() const
Returns center in Y axis.
Definition: qgsaabb.h:51
QgsAABB()=default
Constructs bounding box with null coordinates.
QVector3D maximum() const
Returns corner of the box with maximal coordinates.
Definition: qgsaabb.h:60
float zCenter() const
Returns center in Z axis.
Definition: qgsaabb.h:53