Skip to content

Commit

Permalink
Initial framework for 3D box class
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Apr 12, 2017
1 parent 8637b22 commit 0d843ff
Show file tree
Hide file tree
Showing 6 changed files with 491 additions and 0 deletions.
1 change: 1 addition & 0 deletions python/core/core.sip
Expand Up @@ -25,6 +25,7 @@
%Include qgsattributetableconfig.sip
%Include qgsattributeeditorelement.sip
%Include qgsbearingutils.sip
%Include qgsbox3d.sip
%Include qgsbrowsermodel.sip
%Include qgsclipper.sip
%Include qgscolorramp.sip
Expand Down
191 changes: 191 additions & 0 deletions python/core/qgsbox3d.sip
@@ -0,0 +1,191 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/qgsbox3d.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/




class QgsBox3d
{
%Docstring
A 3-dimensional box composed of x, y, z coordinates.

A box composed of x/y/z minimum and maximum values. It is often used to return the 3D
extent of a geometry or collection of geometries.

.. versionadded:: 3.0
\see QgsRectangle
%End

%TypeHeaderCode
#include "qgsbox3d.h"
%End
public:

QgsBox3d( double xmin = 0, double ymin = 0, double mZmin = 0, double xmax = 0, double ymax = 0, double mZmax = 0 );
%Docstring
Constructor for QgsBox3D which accepts the ranges of x/y/z coordinates.
%End

QgsBox3d( const QgsPointV2 &p1, const QgsPointV2 &p2 );
%Docstring
Constructs a QgsBox3D from two points representing opposite corners of the box.
The box is normalized after construction.
%End

void setXMinimum( double x );
%Docstring
Sets the minimum x value.
\see xMinimum()
\see setXMaximum()
%End

void setXMaximum( double x );
%Docstring
Sets the maximum x value.
\see xMaximum()
\see setXMinimum()
%End

double xMinimum() const;
%Docstring
Returns the minimum x value.
\see setXMinimum()
\see xMaximum()
:rtype: float
%End

double xMaximum() const;
%Docstring
Returns the maximum x value.
\see setXMaximum()
\see xMinimum()
:rtype: float
%End

void setYMinimum( double y );
%Docstring
Sets the minimum y value.
\see yMinimum()
\see setYMaximum()
%End

void setYMaximum( double y );
%Docstring
Sets the maximum y value.
\see yMaximum()
\see setYMinimum()
%End

double yMinimum() const;
%Docstring
Returns the minimum y value.
\see setYMinimum()
\see yMaximum()
:rtype: float
%End

double yMaximum() const;
%Docstring
Returns the maximum y value.
\see setYMaximum()
\see yMinimum()
:rtype: float
%End

void setZMinimum( double z );
%Docstring
Sets the minimum z value.
\see zMinimum()
\see setZMaximum()
%End

void setZMaximum( double z );
%Docstring
Sets the maximum z value.
\see zMaximum()
\see setZMinimum()
%End

double zMinimum() const;
%Docstring
Returns the minimum z value.
\see setZMinimum()
\see zMaximum()
:rtype: float
%End

double zMaximum() const;
%Docstring
Returns the maximum z value.
\see setZMaximum()
\see zMinimum()
:rtype: float
%End

void normalize();
%Docstring
Normalize the box so it has non-negative width/height/depth.
%End

double width() const;
%Docstring
Returns the width of the box.
\see height()
\see depth()
:rtype: float
%End

double height() const;
%Docstring
Returns the height of the box.
\see width()
\see depth()
:rtype: float
%End

double depth() const;
%Docstring
Returns the depth of the box.
\see width()
\see height()
:rtype: float
%End

QgsBox3d intersect( const QgsBox3d &other ) const;
%Docstring
Returns the intersection of this box and another 3D box.
:rtype: QgsBox3d
%End

bool intersects( const QgsBox3d &other ) const;
%Docstring
Returns true if box intersects with another box.
:rtype: bool
%End

bool contains( const QgsBox3d &other ) const;
%Docstring
Returns true when box contains other box.
:rtype: bool
%End

bool contains( const QgsPointV2 &point ) const;
%Docstring
Returns true when box contains a point.
:rtype: bool
%End

};

/************************************************************************
* This file has been generated automatically from *
* *
* src/core/qgsbox3d.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
2 changes: 2 additions & 0 deletions src/core/CMakeLists.txt
Expand Up @@ -101,6 +101,7 @@ SET(QGIS_CORE_SRCS
qgsattributetableconfig.cpp
qgsattributeeditorelement.cpp
qgsbearingutils.cpp
qgsbox3d.cpp
qgsbrowsermodel.cpp
qgscachedfeatureiterator.cpp
qgscacheindex.cpp
Expand Down Expand Up @@ -673,6 +674,7 @@ SET(QGIS_CORE_HDRS
qgsattributetableconfig.h
qgsattributeeditorelement.h
qgsbearingutils.h
qgsbox3d.h
qgscachedfeatureiterator.h
qgscacheindex.h
qgscacheindexfeatureid.h
Expand Down
109 changes: 109 additions & 0 deletions src/core/qgsbox3d.cpp
@@ -0,0 +1,109 @@
/***************************************************************************
qgsbox3d.cpp
------------
begin : April 2017
copyright : (C) 2017 by Nyall Dawson
email : nyall dot dawson at gmail dot com
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgsbox3d.h"


QgsBox3d::QgsBox3d( double xmin, double ymin, double zmin, double xmax, double ymax, double zmax )
: mBounds2d( xmin, ymin, xmax, ymax )
, mZmin( zmin )
, mZmax( zmax )
{}

QgsBox3d::QgsBox3d( const QgsPointV2 &p1, const QgsPointV2 &p2 )
: mBounds2d( p1.x(), p1.y(), p2.x(), p2.y() )
, mZmin( qMin( p1.z(), p2.z() ) )
, mZmax( qMax( p1.z(), p2.z() ) )
{
mBounds2d.normalize();
}

void QgsBox3d::setXMinimum( double x )
{
mBounds2d.setXMinimum( x );
}

void QgsBox3d::setXMaximum( double x )
{
mBounds2d.setXMaximum( x );
}

void QgsBox3d::setYMinimum( double y )
{
mBounds2d.setYMinimum( y );
}

void QgsBox3d::setYMaximum( double y )
{
mBounds2d.setYMaximum( y );
}

void QgsBox3d::setZMinimum( double z )
{
mZmin = z;
}

void QgsBox3d::setZMaximum( double z )
{
mZmax = z;
}

void QgsBox3d::normalize()
{
mBounds2d.normalize();
double z1 = qMin( mZmin, mZmax );
double z2 = qMax( mZmin, mZmax );
mZmin = z1;
mZmax = z2;
}

QgsBox3d QgsBox3d::intersect( const QgsBox3d &other ) const
{
QgsRectangle intersect2d = mBounds2d.intersect( &( other.mBounds2d ) );
double zMin = qMax( mZmin, other.mZmin );
double zMax = qMin( mZmax, other.mZmax );
return QgsBox3d( intersect2d.xMinimum(), intersect2d.yMinimum(), zMin,
intersect2d.xMaximum(), intersect2d.yMaximum(), zMax );
}

bool QgsBox3d::intersects( const QgsBox3d &other ) const
{
if ( !mBounds2d.intersects( other.mBounds2d ) )
return false;

double z1 = ( mZmin > other.mZmin ? mZmin : other.mZmin );
double z2 = ( mZmax < other.mZmax ? mZmax : other.mZmax );
if ( z1 > z2 )
return false;

return true;
}

bool QgsBox3d::contains( const QgsBox3d &other ) const
{
if ( !mBounds2d.contains( other.mBounds2d ) )
return false;

return ( other.mZmin >= mZmin && other.mZmax <= mZmax );
}

bool QgsBox3d::contains( const QgsPointV2 &p ) const
{
if ( !mBounds2d.contains( QgsPoint( p.x(), p.y() ) ) )
return false;
return mZmin <= p.z() && p.z() <= mZmax;
}

0 comments on commit 0d843ff

Please sign in to comment.