diff --git a/python/PyQt6/core/auto_generated/geometry/qgsbox3d.sip.in b/python/PyQt6/core/auto_generated/geometry/qgsbox3d.sip.in index f98092502f326..2b4886e4268f6 100644 --- a/python/PyQt6/core/auto_generated/geometry/qgsbox3d.sip.in +++ b/python/PyQt6/core/auto_generated/geometry/qgsbox3d.sip.in @@ -110,6 +110,13 @@ the normalization step will not be applied automatically. } %End + void set( double xMin, double yMin, double zMin, double xMax, double yMax, double zMax, bool normalize = true ); +%Docstring +Sets the box from a set of (x,y,z) minimum and maximum coordinates. + +.. versionadded:: 3.40 +%End + void setXMinimum( double x ) /HoldGIL/; %Docstring Sets the minimum ``x`` value. diff --git a/python/core/auto_generated/geometry/qgsbox3d.sip.in b/python/core/auto_generated/geometry/qgsbox3d.sip.in index f98092502f326..2b4886e4268f6 100644 --- a/python/core/auto_generated/geometry/qgsbox3d.sip.in +++ b/python/core/auto_generated/geometry/qgsbox3d.sip.in @@ -110,6 +110,13 @@ the normalization step will not be applied automatically. } %End + void set( double xMin, double yMin, double zMin, double xMax, double yMax, double zMax, bool normalize = true ); +%Docstring +Sets the box from a set of (x,y,z) minimum and maximum coordinates. + +.. versionadded:: 3.40 +%End + void setXMinimum( double x ) /HoldGIL/; %Docstring Sets the minimum ``x`` value. diff --git a/src/core/geometry/qgsbox3d.h b/src/core/geometry/qgsbox3d.h index a20191b5fccf7..374e5719cbc23 100644 --- a/src/core/geometry/qgsbox3d.h +++ b/src/core/geometry/qgsbox3d.h @@ -140,6 +140,22 @@ class CORE_EXPORT QgsBox3D % End #endif + /** + * Sets the box from a set of (x,y,z) minimum and maximum coordinates. + * + * \since QGIS 3.40 + */ + void set( double xMin, double yMin, double zMin, double xMax, double yMax, double zMax, bool normalize = true ) + { + mBounds2d.set( xMin, yMin, xMax, yMax, false ); + mZmin = zMin; + mZmax = zMax; + if ( normalize ) + { + QgsBox3D::normalize(); + } + } + /** * Sets the minimum \a x value. * \see xMinimum() diff --git a/tests/src/python/test_qgsbox3d.py b/tests/src/python/test_qgsbox3d.py index c31716a8435b9..096ebf93bfba1 100644 --- a/tests/src/python/test_qgsbox3d.py +++ b/tests/src/python/test_qgsbox3d.py @@ -526,6 +526,39 @@ def test_corners(self): QgsVector3D(11, 6, 15), QgsVector3D(11, 13, 15)]) + def test_set(self): + box1 = QgsBox3d(5.0, 6.0, 7.0, 11.0, 13.0, 15.0) + self.assertEqual(box1.xMinimum(), 5.0) + self.assertEqual(box1.yMinimum(), 6.0) + self.assertEqual(box1.zMinimum(), 7.0) + self.assertEqual(box1.xMaximum(), 11.0) + self.assertEqual(box1.yMaximum(), 13.0) + self.assertEqual(box1.zMaximum(), 15.0) + + box1.set(23, 24, 25, 22, 42, 43, False) + self.assertEqual(box1.xMinimum(), 23.0) + self.assertEqual(box1.yMinimum(), 24.0) + self.assertEqual(box1.zMinimum(), 25.0) + self.assertEqual(box1.xMaximum(), 22.0) + self.assertEqual(box1.yMaximum(), 42.0) + self.assertEqual(box1.zMaximum(), 43.0) + + box1.normalize() + self.assertEqual(box1.xMinimum(), 22.0) + self.assertEqual(box1.yMinimum(), 24.0) + self.assertEqual(box1.zMinimum(), 25.0) + self.assertEqual(box1.xMaximum(), 23.0) + self.assertEqual(box1.yMaximum(), 42.0) + self.assertEqual(box1.zMaximum(), 43.0) + + box1.set(-5, -6, -7, 12, 13, 14) + self.assertEqual(box1.xMinimum(), -5.0) + self.assertEqual(box1.yMinimum(), -6.0) + self.assertEqual(box1.zMinimum(), -7.0) + self.assertEqual(box1.xMaximum(), 12.0) + self.assertEqual(box1.yMaximum(), 13.0) + self.assertEqual(box1.zMaximum(), 14.0) + if __name__ == '__main__': unittest.main()