QGIS API Documentation  3.8.0-Zanzibar (11aff65)
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 
30 class _3D_EXPORT QgsAABB
31 {
32  public:
34  QgsAABB() = default;
35 
37  QgsAABB( float xMin, float yMin, float zMin, float xMax, float yMax, float zMax );
38 
40  float xExtent() const { return xMax - xMin; }
42  float yExtent() const { return yMax - yMin; }
44  float zExtent() const { return zMax - zMin; }
45 
47  float xCenter() const { return ( xMax + xMin ) / 2; }
49  float yCenter() const { return ( yMax + yMin ) / 2; }
51  float zCenter() const { return ( zMax + zMin ) / 2; }
52 
54  QVector3D center() const { return QVector3D( xCenter(), yCenter(), zCenter() ); }
56  QVector3D minimum() const { return QVector3D( xMin, yMin, zMin ); }
58  QVector3D maximum() const { return QVector3D( xMax, yMax, zMax ); }
59 
61  bool intersects( const QgsAABB &other ) const;
62 
64  bool intersects( float x, float y, float z ) const;
65 
67  float distanceFromPoint( float x, float y, float z ) const;
68 
70  float distanceFromPoint( QVector3D v ) const;
71 
73  QList<QVector3D> verticesForLines() const;
74 
75  float xMin = 0.0f;
76  float yMin = 0.0f;
77  float zMin = 0.0f;
78  float xMax = 0.0f;
79  float yMax = 0.0f;
80  float zMax = 0.0f;
81 };
82 
83 #endif // QGSAABB_H
3 Axis-aligned bounding box - in world coords.
Definition: qgsaabb.h:30
float xCenter() const
Returns center in X axis.
Definition: qgsaabb.h:47
QVector3D center() const
Returns coordinates of the center of the box.
Definition: qgsaabb.h:54
QVector3D maximum() const
Returns corner of the box with maximal coordinates.
Definition: qgsaabb.h:58
float xExtent() const
Returns box width in X axis.
Definition: qgsaabb.h:40
float yExtent() const
Returns box width in Y axis.
Definition: qgsaabb.h:42
QVector3D minimum() const
Returns corner of the box with minimal coordinates.
Definition: qgsaabb.h:56
float zCenter() const
Returns center in Z axis.
Definition: qgsaabb.h:51
float zExtent() const
Returns box width in Z axis.
Definition: qgsaabb.h:44
float yCenter() const
Returns center in Y axis.
Definition: qgsaabb.h:49