Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
6 changed files
with
89 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
Code/Mantid/Framework/PythonInterface/mantid/geometry/src/Exports/BoundingBox.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#include "MantidGeometry/Objects/BoundingBox.h" | ||
#include <boost/python/class.hpp> | ||
#include <boost/python/copy_const_reference.hpp> | ||
|
||
using Mantid::Geometry::BoundingBox; | ||
using Mantid::Kernel::V3D; | ||
using namespace boost::python; | ||
|
||
void export_BoundingBox() | ||
{ | ||
class_<BoundingBox>("BoundingBox", "Constructs a zero-sized box") | ||
.def(init<double, double, double, double, double, double>( | ||
(arg("xmax"), arg("ymax"), arg("zmax"), arg("xmin"), arg("ymin"), arg("zmin")), | ||
"Constructs a box from the six given points")) | ||
|
||
.def("minPoint", &BoundingBox::minPoint, return_value_policy<copy_const_reference>(), | ||
"Returns a V3D containing the values of the minimum of the box. See mantid.kernel.V3D") | ||
|
||
.def("maxPoint", &BoundingBox::maxPoint, return_value_policy<copy_const_reference>(), | ||
"Returns a V3D containing the values of the minimum of the box. See mantid.kernel.V3D") | ||
|
||
.def("centrePoint", &BoundingBox::centrePoint, | ||
"Returns a V3D containing the coordinates of the centre point. See mantid.kernel.V3D") | ||
|
||
.def("width", &BoundingBox::width, | ||
"Returns a V3D containing the widths for each dimension. See mantid.kernel.V3D") | ||
|
||
.def("isNull", &BoundingBox::isNull, | ||
"Returns true if the box has no dimensions that have been set") | ||
|
||
.def("isPointInside", &BoundingBox::isPointInside, | ||
"Returns true if the given point is inside the object. See mantid.kernel.V3D") | ||
|
||
.def("doesLineIntersect", | ||
(bool (BoundingBox::*)(const V3D &, const V3D &) const)&BoundingBox::doesLineIntersect, | ||
(arg("startPoint"), arg("lineDir")), | ||
"Returns true if the line given by the starting point & direction vector passes through the box") | ||
; | ||
} | ||
|
6 changes: 6 additions & 0 deletions
6
Code/Mantid/Framework/PythonInterface/mantid/geometry/src/Exports/Object.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
Code/Mantid/Framework/PythonInterface/test/python/mantid/geometry/BoundingBoxTest.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import unittest | ||
from mantid.geometry import BoundingBox | ||
from mantid.kernel import V3D | ||
|
||
class BoundingBoxTest(unittest.TestCase): | ||
|
||
def test_default_construction_is_allowed(self): | ||
box = BoundingBox() | ||
self.assertTrue(isinstance(box, BoundingBox)) | ||
self.assertTrue(box.isNull()) | ||
|
||
def test_construction_with_min_max_values_is_allowed(self): | ||
box = BoundingBox(1.0, 4.0, 5.0, 0.0, 2.0, 3.0) | ||
self.assertTrue(isinstance(box, BoundingBox)) | ||
|
||
def test_properties_are_correct(self): | ||
bbox = BoundingBox (1.0, 2.0, 3.0, -1.0, -2.0, -3.0) | ||
self.assertEquals(bbox.minPoint(), V3D(-1.0,-2.0,-3.0)) | ||
self.assertEquals(bbox.maxPoint(), V3D(1.0,2.0,3.0)) | ||
self.assertEquals(bbox.centrePoint(), V3D(0.0,0.0,0.0)) | ||
self.assertEquals(bbox.width(), V3D(2.0,4.0,6.0)) | ||
|
||
def test_point_inside(self): | ||
box = BoundingBox(1.0, 2.0, 3.0, -1.0, -2.0, -3.0) | ||
self.assertTrue(box.isPointInside(V3D(0.0,0.0,0.0))) | ||
|
||
def test_doesLineIntersect(self): | ||
bbox = BoundingBox(4.1, 4.1, 4.1, -4.1, -4.1, -4.1) | ||
self.assertTrue(bbox.doesLineIntersect(V3D(-6.0,0.0,0.0), V3D(1.0,0.0,0.0))) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |
3 changes: 2 additions & 1 deletion
3
Code/Mantid/Framework/PythonInterface/test/python/mantid/geometry/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters