Skip to content

Commit

Permalink
Add is2d() method to QgsBox3d to determine whether box is 2d
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Apr 19, 2017
1 parent 24c5b03 commit 18c8c1f
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
9 changes: 8 additions & 1 deletion python/core/geometry/qgsbox3d.sip
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions src/core/geometry/qgsbox3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) )
Expand Down
8 changes: 7 additions & 1 deletion src/core/geometry/qgsbox3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
*/
Expand Down
10 changes: 10 additions & 0 deletions tests/src/python/test_qgsbox3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.