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() ),
127 0.5 * ( mBounds2d.yMinimum() + mBounds2d.yMaximum() ),
128 0.5 * ( mZmin + mZmax ) );
134 const double zMin = std::max( mZmin, other.mZmin );
135 const double zMax = std::min( mZmax, other.mZmax );
142 return qgsDoubleNear( mZmin, mZmax ) || ( mZmin > mZmax ) || std::isnan( mZmin ) || std::isnan( mZmax ) ;
152 if ( !mBounds2d.intersects( other.mBounds2d ) )
161 const double z1 = ( mZmin > other.mZmin ? mZmin : other.mZmin );
162 const double z2 = ( mZmax < other.mZmax ? mZmax : other.mZmax );
169 if ( !mBounds2d.contains( other.mBounds2d ) )
178 return ( other.mZmin >= mZmin && other.mZmax <= mZmax );
190 return mBounds2d.contains( p );
196 if ( !mBounds2d.contains( x, y ) )
201 if ( std::isnan( z ) ||
is2d() )
207 return mZmin <= z && z <= mZmax;
224 mBounds2d.setXMinimum( ( mBounds2d.xMinimum() < box.
xMinimum() ) ? mBounds2d.xMinimum() : box.
xMinimum() );
225 mBounds2d.setXMaximum( ( mBounds2d.xMaximum() > box.
xMaximum() ) ? mBounds2d.xMaximum() : box.
xMaximum() );
226 mBounds2d.setYMinimum( ( mBounds2d.yMinimum() < box.
yMinimum() ) ? mBounds2d.yMinimum() : box.
yMinimum() );
227 mBounds2d.setYMaximum( ( mBounds2d.yMaximum() > box.
yMaximum() ) ? mBounds2d.yMaximum() : box.
yMaximum() );
239 *
this =
QgsBox3D( x, y, z, x, y, z );
245 mBounds2d.setXMinimum( ( mBounds2d.xMinimum() ) < x ? mBounds2d.xMinimum() : x );
246 mBounds2d.setXMaximum( ( mBounds2d.xMaximum() ) > x ? mBounds2d.xMaximum() : x );
247 mBounds2d.setYMinimum( ( mBounds2d.yMinimum() ) < y ? mBounds2d.yMinimum() : y );
248 mBounds2d.setYMaximum( ( mBounds2d.yMaximum() ) > y ? mBounds2d.yMaximum() : y );
249 mZmin = ( mZmin < z ) ? mZmin : z;
250 mZmax = ( mZmax > z ) ? mZmax : z;
256 const double dx = std::max( mBounds2d.xMinimum() - point.
x(), std::max( 0., point.
x() - mBounds2d.xMaximum() ) );
257 const double dy = std::max( mBounds2d.yMinimum() - point.
y(), std::max( 0., point.
y() - mBounds2d.yMaximum() ) );
258 if (
is2d() || std::isnan( point.
z() ) )
260 return std::hypot( dx, dy );
264 const double dz = std::max( mZmin - point.
z(), std::max( 0., point.
z() - mZmax ) );
265 return std::hypot( dx, dy, dz );
271 return mBounds2d == other.mBounds2d &&
279 double centerX, centerY, centerZ;
292 scale( scaleFactor, centerX, centerY, centerZ );
295void QgsBox3D::scale(
double scaleFactor,
double centerX,
double centerY,
double centerZ )
311 mBounds2d.grow( delta );
318 return ( std::isnan( mBounds2d.xMinimum() ) && std::isnan( mBounds2d.xMaximum() )
319 && std::isnan( mBounds2d.yMinimum() ) && std::isnan( mBounds2d.xMaximum() )
320 && std::isnan( mZmin ) && std::isnan( mZmax ) )
322 ( mBounds2d.xMinimum() == std::numeric_limits<double>::max() && mBounds2d.yMinimum() == std::numeric_limits<double>::max() && mZmin == std::numeric_limits<double>::max()
323 && mBounds2d.xMaximum() == -std::numeric_limits<double>::max() && mBounds2d.yMaximum() == -std::numeric_limits<double>::max() && mZmax == -std::numeric_limits<double>::max() );
328 return mZmax < mZmin ||
qgsDoubleNear( mZmax, mZmin ) || mBounds2d.isEmpty();
340 precision =
static_cast<int>( std::ceil( -1.0 * std::log10( std::min(
width(),
height() ) ) ) ) + 1;
342 if ( precision > 20 )
352 rep = u
"%1,%2,%3 : %4,%5,%6"_s
353 .arg( mBounds2d.xMinimum(), 0,
'f', precision )
354 .arg( mBounds2d.yMinimum(), 0,
'f', precision )
355 .arg( mZmin, 0,
'f', precision )
356 .arg( mBounds2d.xMaximum(), 0,
'f', precision )
357 .arg( mBounds2d.yMaximum(), 0,
'f', precision )
358 .arg( mZmax, 0,
'f', precision );
369 QgsVector3D( mBounds2d.xMinimum(), mBounds2d.yMinimum(), mZmin ),
370 QgsVector3D( mBounds2d.xMinimum(), mBounds2d.yMaximum(), mZmin ),
371 QgsVector3D( mBounds2d.xMaximum(), mBounds2d.yMinimum(), mZmin ),
372 QgsVector3D( mBounds2d.xMaximum(), mBounds2d.yMaximum(), mZmin ),
374 QgsVector3D( mBounds2d.xMinimum(), mBounds2d.yMinimum(), mZmax ),
375 QgsVector3D( mBounds2d.xMinimum(), mBounds2d.yMaximum(), mZmax ),
376 QgsVector3D( mBounds2d.xMaximum(), mBounds2d.yMinimum(), mZmax ),
377 QgsVector3D( mBounds2d.xMaximum(), mBounds2d.yMaximum(), mZmax )
383 return QgsBox3D( mBounds2d.xMinimum() - v.
x(), mBounds2d.yMinimum() - v.
y(), mZmin - v.
z(),
384 mBounds2d.xMaximum() - v.
x(), mBounds2d.yMaximum() - v.
y(), mZmax - v.
z() );
389 return QgsBox3D( mBounds2d.xMinimum() + v.
x(), mBounds2d.yMinimum() + v.
y(), mZmin + v.
z(),
390 mBounds2d.xMaximum() + v.
x(), mBounds2d.yMaximum() + v.
y(), mZmax + v.
z() );
395 mBounds2d.
set( mBounds2d.xMinimum() - v.
x(), mBounds2d.yMinimum() - v.
y(),
396 mBounds2d.xMaximum() - v.
x(), mBounds2d.yMaximum() - v.
y() );
404 mBounds2d.
set( mBounds2d.xMinimum() + v.
x(), mBounds2d.yMinimum() + v.
y(),
405 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)