Skip to content

Commit 18c8c1f

Browse files
committedApr 19, 2017
Add is2d() method to QgsBox3d to determine whether box is 2d
1 parent 24c5b03 commit 18c8c1f

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed
 

‎python/core/geometry/qgsbox3d.sip

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class QgsBox3d
2626
%End
2727
public:
2828

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

171+
bool is2d() const;
172+
%Docstring
173+
Returns true if the box can be considered a 2-dimensional box, i.e.
174+
it has equal minimum and maximum z values.
175+
:rtype: bool
176+
%End
177+
171178
bool intersects( const QgsBox3d &other ) const;
172179
%Docstring
173180
Returns true if box intersects with another box.

‎src/core/geometry/qgsbox3d.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ QgsBox3d QgsBox3d::intersect( const QgsBox3d &other ) const
8080
intersect2d.xMaximum(), intersect2d.yMaximum(), zMax );
8181
}
8282

83+
bool QgsBox3d::is2d() const
84+
{
85+
return qgsDoubleNear( mZmin, mZmax ) || ( mZmin > mZmax );
86+
}
87+
8388
bool QgsBox3d::intersects( const QgsBox3d &other ) const
8489
{
8590
if ( !mBounds2d.intersects( other.mBounds2d ) )

‎src/core/geometry/qgsbox3d.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class CORE_EXPORT QgsBox3d
3838
/**
3939
* Constructor for QgsBox3D which accepts the ranges of x/y/z coordinates.
4040
*/
41-
QgsBox3d( double xmin = 0, double ymin = 0, double mZmin = 0, double xmax = 0, double ymax = 0, double mZmax = 0 );
41+
QgsBox3d( double xmin = 0, double ymin = 0, double zmin = 0, double xmax = 0, double ymax = 0, double zmax = 0 );
4242

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

169+
/**
170+
* Returns true if the box can be considered a 2-dimensional box, i.e.
171+
* it has equal minimum and maximum z values.
172+
*/
173+
bool is2d() const;
174+
169175
/**
170176
* Returns true if box intersects with another box.
171177
*/

‎tests/src/python/test_qgsbox3d.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,16 @@ def testToRectangle(self):
155155
rect = box.toRectangle()
156156
self.assertEqual(rect, QgsRectangle(5, 6, 11, 13))
157157

158+
def is2d(self):
159+
box = QgsBox3d(5.0, 6.0, 7.0, 11.0, 13.0, 15.0)
160+
self.assertFalse(box.is2d())
161+
box = QgsBox3d(5.0, 6.0, 7.0, 11.0, 13.0, 7.0)
162+
self.assertTrue(box.is2d())
163+
box = QgsBox3d(5.0, 6.0, 0.0, 11.0, 13.0, 0.0)
164+
self.assertTrue(box.is2d())
165+
box = QgsBox3d(5.0, 6.0, 7.0, 11.0, 13.0, -7.0)
166+
self.assertTrue(box.is2d())
167+
158168

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

0 commit comments

Comments
 (0)
Please sign in to comment.