Skip to content

Commit

Permalink
qgsbox3d: Add support for set method
Browse files Browse the repository at this point in the history
  • Loading branch information
ptitjano committed Jul 11, 2024
1 parent 40c8a1c commit 2edb4db
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 0 deletions.
7 changes: 7 additions & 0 deletions python/PyQt6/core/auto_generated/geometry/qgsbox3d.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 7 additions & 0 deletions python/core/auto_generated/geometry/qgsbox3d.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
16 changes: 16 additions & 0 deletions src/core/geometry/qgsbox3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
33 changes: 33 additions & 0 deletions tests/src/python/test_qgsbox3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit 2edb4db

Please sign in to comment.