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 27 /** 28 * \ingroup 3d 29 * \brief Axis-aligned bounding box - in world coords. 30 * \note Not available in Python bindings 31 * \since QGIS 3.0 32 */ 33 class _3D_EXPORT QgsAABB 34 { 35 public: 36 //! Constructs bounding box with null coordinates 37 QgsAABB() = default; 38 39 //! Constructs bounding box 40 QgsAABB( float xMin, float yMin, float zMin, float xMax, float yMax, float zMax ); 41 42 //! Returns box width in X axis xExtent()43 float xExtent() const { return xMax - xMin; } 44 //! Returns box width in Y axis yExtent()45 float yExtent() const { return yMax - yMin; } 46 //! Returns box width in Z axis zExtent()47 float zExtent() const { return zMax - zMin; } 48 49 //! Returns center in X axis xCenter()50 float xCenter() const { return ( xMax + xMin ) / 2; } 51 //! Returns center in Y axis yCenter()52 float yCenter() const { return ( yMax + yMin ) / 2; } 53 //! Returns center in Z axis zCenter()54 float zCenter() const { return ( zMax + zMin ) / 2; } 55 56 //! Returns coordinates of the center of the box center()57 QVector3D center() const { return QVector3D( xCenter(), yCenter(), zCenter() ); } 58 //! Returns corner of the box with minimal coordinates minimum()59 QVector3D minimum() const { return QVector3D( xMin, yMin, zMin ); } 60 //! Returns corner of the box with maximal coordinates maximum()61 QVector3D maximum() const { return QVector3D( xMax, yMax, zMax ); } 62 63 //! Determines whether the box intersects some other axis aligned box 64 bool intersects( const QgsAABB &other ) const; 65 66 //! Determines whether given coordinate is inside the box 67 bool intersects( float x, float y, float z ) const; 68 69 //! Returns shortest distance from the box to a point 70 float distanceFromPoint( float x, float y, float z ) const; 71 72 //! Returns shortest distance from the box to a point 73 float distanceFromPoint( QVector3D v ) const; 74 75 //! Returns a list of pairs of vertices (useful for display of bounding boxes) 76 QList<QVector3D> verticesForLines() const; 77 78 float xMin = 0.0f; 79 float yMin = 0.0f; 80 float zMin = 0.0f; 81 float xMax = 0.0f; 82 float yMax = 0.0f; 83 float zMax = 0.0f; 84 }; 85 86 #endif // QGSAABB_H 87