Skip to content
Permalink
Browse files
Add is2d() method to QgsBox3d to determine whether box is 2d
  • Loading branch information
nyalldawson committed Apr 19, 2017
1 parent 24c5b03 commit 18c8c1fe367b391f03fb1ab786e9695a0df537f6
Showing with 30 additions and 2 deletions.
  1. +8 −1 python/core/geometry/qgsbox3d.sip
  2. +5 −0 src/core/geometry/qgsbox3d.cpp
  3. +7 −1 src/core/geometry/qgsbox3d.h
  4. +10 −0 tests/src/python/test_qgsbox3d.py
@@ -26,7 +26,7 @@ class QgsBox3d
%End
public:

QgsBox3d( double xmin = 0, double ymin = 0, double mZmin = 0, double xmax = 0, double ymax = 0, double mZmax = 0 );
QgsBox3d( double xmin = 0, double ymin = 0, double zmin = 0, double xmax = 0, double ymax = 0, double zmax = 0 );
%Docstring
Constructor for QgsBox3D which accepts the ranges of x/y/z coordinates.
%End
@@ -168,6 +168,13 @@ class QgsBox3d
:rtype: QgsBox3d
%End

bool is2d() const;
%Docstring
Returns true if the box can be considered a 2-dimensional box, i.e.
it has equal minimum and maximum z values.
:rtype: bool
%End

bool intersects( const QgsBox3d &other ) const;
%Docstring
Returns true if box intersects with another box.
@@ -80,6 +80,11 @@ QgsBox3d QgsBox3d::intersect( const QgsBox3d &other ) const
intersect2d.xMaximum(), intersect2d.yMaximum(), zMax );
}

bool QgsBox3d::is2d() const
{
return qgsDoubleNear( mZmin, mZmax ) || ( mZmin > mZmax );
}

bool QgsBox3d::intersects( const QgsBox3d &other ) const
{
if ( !mBounds2d.intersects( other.mBounds2d ) )
@@ -38,7 +38,7 @@ class CORE_EXPORT QgsBox3d
/**
* Constructor for QgsBox3D which accepts the ranges of x/y/z coordinates.
*/
QgsBox3d( double xmin = 0, double ymin = 0, double mZmin = 0, double xmax = 0, double ymax = 0, double mZmax = 0 );
QgsBox3d( double xmin = 0, double ymin = 0, double zmin = 0, double xmax = 0, double ymax = 0, double zmax = 0 );

/**
* Constructs a QgsBox3D from two points representing opposite corners of the box.
@@ -166,6 +166,12 @@ class CORE_EXPORT QgsBox3d
*/
QgsBox3d intersect( const QgsBox3d &other ) const;

/**
* Returns true if the box can be considered a 2-dimensional box, i.e.
* it has equal minimum and maximum z values.
*/
bool is2d() const;

/**
* Returns true if box intersects with another box.
*/
@@ -155,6 +155,16 @@ def testToRectangle(self):
rect = box.toRectangle()
self.assertEqual(rect, QgsRectangle(5, 6, 11, 13))

def is2d(self):
box = QgsBox3d(5.0, 6.0, 7.0, 11.0, 13.0, 15.0)
self.assertFalse(box.is2d())
box = QgsBox3d(5.0, 6.0, 7.0, 11.0, 13.0, 7.0)
self.assertTrue(box.is2d())
box = QgsBox3d(5.0, 6.0, 0.0, 11.0, 13.0, 0.0)
self.assertTrue(box.is2d())
box = QgsBox3d(5.0, 6.0, 7.0, 11.0, 13.0, -7.0)
self.assertTrue(box.is2d())


if __name__ == '__main__':
unittest.main()

0 comments on commit 18c8c1f

Please sign in to comment.