24#include "moc_qgsbox3d.cpp"
27 : mBounds2d( xmin, ymin, xmax, ymax, false )
38 : mBounds2d( p1.x(), p1.y(), p2.x(), p2.y(), false )
60 : mBounds2d( corner1.x(), corner1.y(), corner2.x(), corner2.y(), false )
61 , mZmin( corner1.z() )
62 , mZmax( corner2.z() )
72 mBounds2d.setXMinimum( x );
77 mBounds2d.setXMaximum( x );
82 mBounds2d.setYMinimum( y );
87 mBounds2d.setYMaximum( y );
107 mZmin = std::numeric_limits<double>::max();
108 mZmax = -std::numeric_limits<double>::max();
113 mBounds2d.normalize();
116 std::swap( mZmin, mZmax );
122 return QgsVector3D( 0.5 * ( mBounds2d.xMinimum() + mBounds2d.xMaximum() ),
123 0.5 * ( mBounds2d.yMinimum() + mBounds2d.yMaximum() ),
124 0.5 * ( mZmin + mZmax ) );
130 const double zMin = std::max( mZmin, other.mZmin );
131 const double zMax = std::min( mZmax, other.mZmax );
138 return qgsDoubleNear( mZmin, mZmax ) || ( mZmin > mZmax ) || std::isnan( mZmin ) || std::isnan( mZmax ) ;
148 if ( !mBounds2d.intersects( other.mBounds2d ) )
157 const double z1 = ( mZmin > other.mZmin ? mZmin : other.mZmin );
158 const double z2 = ( mZmax < other.mZmax ? mZmax : other.mZmax );
165 if ( !mBounds2d.contains( other.mBounds2d ) )
174 return ( other.mZmin >= mZmin && other.mZmax <= mZmax );
186 return mBounds2d.contains( p );
192 if ( !mBounds2d.contains( x, y ) )
197 if ( std::isnan( z ) ||
is2d() )
203 return mZmin <= z && z <= mZmax;
220 mBounds2d.setXMinimum( ( mBounds2d.xMinimum() < box.
xMinimum() ) ? mBounds2d.xMinimum() : box.
xMinimum() );
221 mBounds2d.setXMaximum( ( mBounds2d.xMaximum() > box.
xMaximum() ) ? mBounds2d.xMaximum() : box.
xMaximum() );
222 mBounds2d.setYMinimum( ( mBounds2d.yMinimum() < box.
yMinimum() ) ? mBounds2d.yMinimum() : box.
yMinimum() );
223 mBounds2d.setYMaximum( ( mBounds2d.yMaximum() > box.
yMaximum() ) ? mBounds2d.yMaximum() : box.
yMaximum() );
235 *
this =
QgsBox3D( x, y, z, x, y, z );
241 mBounds2d.setXMinimum( ( mBounds2d.xMinimum() ) < x ? mBounds2d.xMinimum() : x );
242 mBounds2d.setXMaximum( ( mBounds2d.xMaximum() ) > x ? mBounds2d.xMaximum() : x );
243 mBounds2d.setYMinimum( ( mBounds2d.yMinimum() ) < y ? mBounds2d.yMinimum() : y );
244 mBounds2d.setYMaximum( ( mBounds2d.yMaximum() ) > y ? mBounds2d.yMaximum() : y );
245 mZmin = ( mZmin < z ) ? mZmin : z;
246 mZmax = ( mZmax > z ) ? mZmax : z;
252 const double dx = std::max( mBounds2d.xMinimum() - point.
x(), std::max( 0., point.
x() - mBounds2d.xMaximum() ) );
253 const double dy = std::max( mBounds2d.yMinimum() - point.
y(), std::max( 0., point.
y() - mBounds2d.yMaximum() ) );
254 if (
is2d() || std::isnan( point.
z() ) )
256 return std::hypot( dx, dy );
260 const double dz = std::max( mZmin - point.
z(), std::max( 0., point.
z() - mZmax ) );
261 return std::hypot( dx, dy, dz );
267 return mBounds2d == other.mBounds2d &&
275 double centerX, centerY, centerZ;
288 scale( scaleFactor, centerX, centerY, centerZ );
291void QgsBox3D::scale(
double scaleFactor,
double centerX,
double centerY,
double centerZ )
307 mBounds2d.grow( delta );
314 return ( std::isnan( mBounds2d.xMinimum() ) && std::isnan( mBounds2d.xMaximum() )
315 && std::isnan( mBounds2d.yMinimum() ) && std::isnan( mBounds2d.xMaximum() )
316 && std::isnan( mZmin ) && std::isnan( mZmax ) )
318 ( mBounds2d.xMinimum() == std::numeric_limits<double>::max() && mBounds2d.yMinimum() == std::numeric_limits<double>::max() && mZmin == std::numeric_limits<double>::max()
319 && mBounds2d.xMaximum() == -std::numeric_limits<double>::max() && mBounds2d.yMaximum() == -std::numeric_limits<double>::max() && mZmax == -std::numeric_limits<double>::max() );
324 return mZmax < mZmin ||
qgsDoubleNear( mZmax, mZmin ) || mBounds2d.isEmpty();
336 precision =
static_cast<int>( std::ceil( -1.0 * std::log10( std::min(
width(),
height() ) ) ) ) + 1;
338 if ( precision > 20 )
344 rep = QStringLiteral(
"Null" );
346 rep = QStringLiteral(
"Empty" );
348 rep = QStringLiteral(
"%1,%2,%3 : %4,%5,%6" )
349 .arg( mBounds2d.xMinimum(), 0,
'f', precision )
350 .arg( mBounds2d.yMinimum(), 0,
'f', precision )
351 .arg( mZmin, 0,
'f', precision )
352 .arg( mBounds2d.xMaximum(), 0,
'f', precision )
353 .arg( mBounds2d.yMaximum(), 0,
'f', precision )
354 .arg( mZmax, 0,
'f', precision );
365 QgsVector3D( mBounds2d.xMinimum(), mBounds2d.yMinimum(), mZmin ),
366 QgsVector3D( mBounds2d.xMinimum(), mBounds2d.yMaximum(), mZmin ),
367 QgsVector3D( mBounds2d.xMaximum(), mBounds2d.yMinimum(), mZmin ),
368 QgsVector3D( mBounds2d.xMaximum(), mBounds2d.yMaximum(), mZmin ),
370 QgsVector3D( mBounds2d.xMinimum(), mBounds2d.yMinimum(), mZmax ),
371 QgsVector3D( mBounds2d.xMinimum(), mBounds2d.yMaximum(), mZmax ),
372 QgsVector3D( mBounds2d.xMaximum(), mBounds2d.yMinimum(), mZmax ),
373 QgsVector3D( mBounds2d.xMaximum(), mBounds2d.yMaximum(), mZmax )
379 return QgsBox3D( mBounds2d.xMinimum() - v.
x(), mBounds2d.yMinimum() - v.
y(), mZmin - v.
z(),
380 mBounds2d.xMaximum() - v.
x(), mBounds2d.yMaximum() - v.
y(), mZmax - v.
z() );
385 return QgsBox3D( mBounds2d.xMinimum() + v.
x(), mBounds2d.yMinimum() + v.
y(), mZmin + v.
z(),
386 mBounds2d.xMaximum() + v.
x(), mBounds2d.yMaximum() + v.
y(), mZmax + v.
z() );
391 mBounds2d.
set( mBounds2d.xMinimum() - v.
x(), mBounds2d.yMinimum() - v.
y(),
392 mBounds2d.xMaximum() - v.
x(), mBounds2d.yMaximum() - v.
y() );
400 mBounds2d.
set( mBounds2d.xMinimum() + v.
x(), mBounds2d.yMinimum() + v.
y(),
401 mBounds2d.xMaximum() + v.
x(), mBounds2d.yMaximum() + v.
y() );
double yMaximum() const
Returns the maximum y value.
QgsBox3D operator-(const QgsVector3D &v) const
Returns a box offset from this one in the direction of the reversed vector.
QString toString(int precision=16) const
Returns a string representation of form xmin,ymin,zmin : xmax,ymax,zmax Coordinates will be truncated...
void scale(double scaleFactor, const QgsPoint ¢er=QgsPoint())
Scale the rectangle around a center QgsPoint.
void setZMinimum(double z)
Sets the minimum z value.
void setYMaximum(double y)
Sets the maximum y value.
bool is3D() const
Returns true if the box can be considered a 3-dimensional box, i.e.
void setZMaximum(double z)
Sets the maximum z value.
bool intersects(const QgsBox3D &other) const
Returns true if box intersects with another box.
double xMinimum() const
Returns the minimum x value.
bool contains(const QgsBox3D &other) const
Returns true when box contains other box.
double zMaximum() const
Returns the maximum z value.
QgsVector3D center() const
Returns the center of the box as a vector.
double xMaximum() const
Returns the maximum x value.
void normalize()
Normalize the box so it has non-negative width/height/depth.
void setXMaximum(double x)
Sets the maximum x value.
void combineWith(const QgsBox3D &box)
Expands the bbox so that it covers both the original rectangle and the given rectangle.
bool is2d() const
Returns true if the box can be considered a 2-dimensional box, i.e.
Q_DECL_DEPRECATED double distanceTo(const QVector3D &point) const
Returns the smallest distance between the box and the point point (returns 0 if the point is inside t...
QVector< QgsVector3D > corners() const
Returns an array of all box corners as 3D vectors.
QgsBox3D operator+(const QgsVector3D &v) const
Returns a box offset from this one in the direction of the vector.
void set(double xMin, double yMin, double zMin, double xMax, double yMax, double zMax, bool normalize=true)
Sets the box from a set of (x,y,z) minimum and maximum coordinates.
QgsBox3D(double xmin=std::numeric_limits< double >::quiet_NaN(), double ymin=std::numeric_limits< double >::quiet_NaN(), double zmin=std::numeric_limits< double >::quiet_NaN(), double xmax=std::numeric_limits< double >::quiet_NaN(), double ymax=std::numeric_limits< double >::quiet_NaN(), double zmax=std::numeric_limits< double >::quiet_NaN(), bool normalize=true)
Constructor for QgsBox3D which accepts the ranges of x/y/z coordinates.
double width() const
Returns the width of the box.
QgsBox3D & operator+=(const QgsVector3D &v)
Moves this box in the direction of the vector.
QgsBox3D intersect(const QgsBox3D &other) const
Returns the intersection of this box and another 3D box.
void setNull()
Mark a box as being null (holding no spatial information).
void setYMinimum(double y)
Sets the minimum y value.
void grow(double delta)
Grows the box in place by the specified amount in all dimensions.
double zMinimum() const
Returns the minimum z value.
double yMinimum() const
Returns the minimum y value.
double height() const
Returns the height of the box.
QgsBox3D & operator-=(const QgsVector3D &v)
Moves this box in the direction of the reversed vector.
void setXMinimum(double x)
Sets the minimum x value.
bool isNull() const
Test if the box is null (holding no spatial information).
bool operator==(const QgsBox3D &other) const
bool isEmpty() const
Returns true if the box is empty.
Point geometry type, with support for z-dimension and m-values.
A rectangle specified with double values.
QgsRectangle intersect(const QgsRectangle &rect) const
Returns the intersection with the given rectangle.
A 3D vector (similar to QVector3D) with the difference that it uses double precision instead of singl...
double y() const
Returns Y coordinate.
double z() const
Returns Z coordinate.
double x() const
Returns X coordinate.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference).
#define QgsDebugMsgLevel(str, level)