26#include "moc_qgsbox3d.cpp"
28using namespace Qt::StringLiterals;
31 : mBounds2d( xmin, ymin, xmax, ymax, false )
42 : mBounds2d( p1.x(), p1.y(), p2.x(), p2.y(), false )
64 : mBounds2d( corner1.x(), corner1.y(), corner2.x(), corner2.y(), false )
65 , mZmin( corner1.z() )
66 , mZmax( corner2.z() )
76 mBounds2d.setXMinimum( x );
81 mBounds2d.setXMaximum( x );
86 mBounds2d.setYMinimum( y );
91 mBounds2d.setYMaximum( y );
111 mZmin = std::numeric_limits<double>::max();
112 mZmax = -std::numeric_limits<double>::max();
117 mBounds2d.normalize();
120 std::swap( mZmin, mZmax );
126 return QgsVector3D( 0.5 * ( mBounds2d.xMinimum() + mBounds2d.xMaximum() ), 0.5 * ( mBounds2d.yMinimum() + mBounds2d.yMaximum() ), 0.5 * ( mZmin + mZmax ) );
132 const double zMin = std::max( mZmin, other.mZmin );
133 const double zMax = std::min( mZmax, other.mZmax );
139 return qgsDoubleNear( mZmin, mZmax ) || ( mZmin > mZmax ) || std::isnan( mZmin ) || std::isnan( mZmax );
149 if ( !mBounds2d.intersects( other.mBounds2d ) )
158 const double z1 = ( mZmin > other.mZmin ? mZmin : other.mZmin );
159 const double z2 = ( mZmax < other.mZmax ? mZmax : other.mZmax );
166 if ( !mBounds2d.contains( other.mBounds2d ) )
175 return ( other.mZmin >= mZmin && other.mZmax <= mZmax );
187 return mBounds2d.contains( p );
193 if ( !mBounds2d.contains( x, y ) )
198 if ( std::isnan( z ) ||
is2d() )
204 return mZmin <= z && z <= mZmax;
221 mBounds2d.setXMinimum( ( mBounds2d.xMinimum() < box.
xMinimum() ) ? mBounds2d.xMinimum() : box.
xMinimum() );
222 mBounds2d.setXMaximum( ( mBounds2d.xMaximum() > box.
xMaximum() ) ? mBounds2d.xMaximum() : box.
xMaximum() );
223 mBounds2d.setYMinimum( ( mBounds2d.yMinimum() < box.
yMinimum() ) ? mBounds2d.yMinimum() : box.
yMinimum() );
224 mBounds2d.setYMaximum( ( mBounds2d.yMaximum() > box.
yMaximum() ) ? mBounds2d.yMaximum() : box.
yMaximum() );
236 *
this =
QgsBox3D( x, y, z, x, y, z );
242 mBounds2d.setXMinimum( ( mBounds2d.xMinimum() ) < x ? mBounds2d.xMinimum() : x );
243 mBounds2d.setXMaximum( ( mBounds2d.xMaximum() ) > x ? mBounds2d.xMaximum() : x );
244 mBounds2d.setYMinimum( ( mBounds2d.yMinimum() ) < y ? mBounds2d.yMinimum() : y );
245 mBounds2d.setYMaximum( ( mBounds2d.yMaximum() ) > y ? mBounds2d.yMaximum() : y );
246 mZmin = ( mZmin < z ) ? mZmin : z;
247 mZmax = ( mZmax > z ) ? mZmax : z;
253 const double dx = std::max( mBounds2d.xMinimum() - point.
x(), std::max( 0., point.
x() - mBounds2d.xMaximum() ) );
254 const double dy = std::max( mBounds2d.yMinimum() - point.
y(), std::max( 0., point.
y() - mBounds2d.yMaximum() ) );
255 if (
is2d() || std::isnan( point.
z() ) )
257 return std::hypot( dx, dy );
261 const double dz = std::max( mZmin - point.
z(), std::max( 0., point.
z() - mZmax ) );
262 return std::hypot( dx, dy, dz );
274 double centerX, centerY, centerZ;
287 scale( scaleFactor, centerX, centerY, centerZ );
290void QgsBox3D::scale(
double scaleFactor,
double centerX,
double centerY,
double centerZ )
306 mBounds2d.grow( delta );
313 return ( std::isnan( mBounds2d.xMinimum() ) && std::isnan( mBounds2d.xMaximum() )
314 && std::isnan( mBounds2d.yMinimum() ) && std::isnan( mBounds2d.xMaximum() )
315 && std::isnan( mZmin ) && std::isnan( mZmax ) )
317 ( mBounds2d.xMinimum() == std::numeric_limits<double>::max() && mBounds2d.yMinimum() == std::numeric_limits<double>::max() && mZmin == std::numeric_limits<double>::max()
318 && mBounds2d.xMaximum() == -std::numeric_limits<double>::max() && mBounds2d.yMaximum() == -std::numeric_limits<double>::max() && mZmax == -std::numeric_limits<double>::max() );
323 return mZmax < mZmin ||
qgsDoubleNear( mZmax, mZmin ) || mBounds2d.isEmpty();
335 precision =
static_cast<int>( std::ceil( -1.0 * std::log10( std::min(
width(),
height() ) ) ) ) + 1;
337 if ( precision > 20 )
347 rep = u
"%1,%2,%3 : %4,%5,%6"_s.arg( mBounds2d.xMinimum(), 0,
'f', precision )
348 .arg( mBounds2d.yMinimum(), 0,
'f', precision )
349 .arg( mZmin, 0,
'f', precision )
350 .arg( mBounds2d.xMaximum(), 0,
'f', precision )
351 .arg( mBounds2d.yMaximum(), 0,
'f', precision )
352 .arg( mZmax, 0,
'f', precision );
362 QgsVector3D( mBounds2d.xMinimum(), mBounds2d.yMinimum(), mZmin ),
363 QgsVector3D( mBounds2d.xMinimum(), mBounds2d.yMaximum(), mZmin ),
364 QgsVector3D( mBounds2d.xMaximum(), mBounds2d.yMinimum(), mZmin ),
365 QgsVector3D( mBounds2d.xMaximum(), mBounds2d.yMaximum(), mZmin ),
367 QgsVector3D( mBounds2d.xMinimum(), mBounds2d.yMinimum(), mZmax ),
368 QgsVector3D( mBounds2d.xMinimum(), mBounds2d.yMaximum(), mZmax ),
369 QgsVector3D( mBounds2d.xMaximum(), mBounds2d.yMinimum(), mZmax ),
370 QgsVector3D( mBounds2d.xMaximum(), mBounds2d.yMaximum(), mZmax )
376 return QgsBox3D( mBounds2d.xMinimum() - v.
x(), mBounds2d.yMinimum() - v.
y(), mZmin - v.
z(), mBounds2d.xMaximum() - v.
x(), mBounds2d.yMaximum() - v.
y(), mZmax - v.
z() );
381 return QgsBox3D( mBounds2d.xMinimum() + v.
x(), mBounds2d.yMinimum() + v.
y(), mZmin + v.
z(), mBounds2d.xMaximum() + v.
x(), mBounds2d.yMaximum() + v.
y(), mZmax + v.
z() );
386 mBounds2d.
set( mBounds2d.xMinimum() - v.
x(), mBounds2d.yMinimum() - v.
y(), mBounds2d.xMaximum() - v.
x(), mBounds2d.yMaximum() - v.
y() );
394 mBounds2d.
set( mBounds2d.xMinimum() + v.
x(), mBounds2d.yMinimum() + v.
y(), 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)