def test_pickle(center, wx, wy, wz, ex, ey, ez): box = Box(center, wx, wy, wz, ex, ey, ez) with io.BytesIO() as f: pickle.dump(box, f) f.seek(0) box_unpickled = pickle.load(f) assert box == box_unpickled
def test_simplify(self, geometry, surfaces, case_no, expected, kwarg): expected = [TestShape.filter_arg(a, surfaces) for a in expected] expected_shape = Shape.from_polish_notation(expected) body = Body(geometry[case_no], **kwarg) gb = Box([3, 0, 0], 26, 20, 20) simple_body = body.simplify(min_volume=0.001, box=gb) assert simple_body.shape == expected_shape for k, v in kwarg.items(): assert simple_body.options[k] == v assert simple_body.material() == kwarg.get('MAT', None)
def test_bounding_box(self, geometry, tol, case_no, expected): base = [0, 0, 0] dims = [30, 30, 30] gb = Box(base, dims[0], dims[1], dims[2]) if tol is not None: bb = geometry[case_no].bounding_box(box=gb, tol=tol) else: tol = 100.0 bb = geometry[case_no].bounding_box() for j, (low, high) in enumerate(expected): bbdim = 0.5 * bb.dimensions[j] assert bb.center[j] - bbdim <= low assert bb.center[j] - bbdim >= low - tol assert bb.center[j] + bbdim >= high assert bb.center[j] + bbdim <= high + tol
def bounding_box(self, tol=100, box=GLOBAL_BOX): """Gets bounding box for the universe. It finds all bounding boxes for universe cells and then constructs box, that covers all cells' bounding boxes. The main purpose of this method is to find boundaries of the model geometry to compare transformation and surface objects for equality. It is recommended to choose tol value not too small to reduce computation time. Parameters ---------- tol : float Linear tolerance for the bounding box. The distance [in cm] between every box's surface and universe in every direction won't exceed this value. Default: 100 cm. box : Box Starting box for the search. The user must be sure that box covers all geometry, because cells, that already contains corners of the box will be considered as infinite and will be excluded from analysis. Returns ------- bbox : Box Universe bounding box. """ boxes = [] for c in self._cells: test = c.shape.test_points(box.corners) if np.any(test == +1): continue boxes.append(c.shape.bounding_box(tol=tol, box=box)) all_corners = np.empty((8 * len(boxes), 3)) for i, b in enumerate(boxes): all_corners[i * 8:(i + 1) * 8, :] = b.corners min_pt = np.min(all_corners, axis=0) max_pt = np.max(all_corners, axis=0) center = 0.5 * (min_pt + max_pt) dims = max_pt - min_pt return Box(center, *dims)
def __call__(self, cell: mk.Body): box = cell.shape.bounding_box(tol=self.tolerance) if not isinstance(box, Box): box = Box.from_geometry_box(box) return box
def box(): boxes = [Box([0.5, 1, 1.5], 1, 2, 3), Box([0.5, -1, 1.5], 3, 2, 1)] return boxes
@pytest.mark.parametrize('case_no, expected', enumerate([6, 6])) def test_volume(box, case_no, expected): vol = box[case_no].volume assert vol == expected @pytest.mark.parametrize('case_no', range(2)) def test_random_points(box, case_no): points = box[case_no].generate_random_points(100) pt = box[case_no].test_points(points) assert np.all(pt) == True boxes = [ Box([0, 0, 0], 1, 1, 1), Box([2, 0, 0], 0.5, 4, 2), Box([0, 0, 2], 0.5, 4, 2), Box([0, 0, 2], 0.2, 0.2, 10), Box([1, 1, 1], 1.1, 1.1, 1.1), Box([-1, -1, -1], 1.1, 1.1, 1.1) ] eq_matrix = [ [1, 0, 0, 1, 1, 1], [0, 1, 0, 0, 0, 0], [0, 0, 1, 1, 0, 0], [1, 0, 1, 1, 0, 0], [1, 0, 0, 0, 1, 0], [1, 0, 0, 0, 0, 1] ]
def box(self): boxes = [Box(*b) for b in self.box_data] return boxes
copy_surfaces_idx = {s.name(): s for s in uc.get_surfaces()} assert surfaces_idx == copy_surfaces_idx for k, v in surfaces_idx.items(): assert copy_surfaces_idx[k] is not v assert copy_surfaces_idx[k] == v @pytest.mark.slow @pytest.mark.parametrize("tol", [0.2, None]) @pytest.mark.parametrize("case, expected", [(1, [[-10, 10], [-10, 10], [-6.5, 13.5]])]) def test_bounding_box(universe, tol, case, expected): u = universe(case) base = [0, 0, 0] dims = [30, 30, 30] gb = Box(base, dims[0], dims[1], dims[2]) if tol is not None: bb = u.bounding_box(box=gb, tol=tol) else: tol = 100.0 bb = u.bounding_box() for j, (low, high) in enumerate(expected): dimensions = 0.5 * bb.dimensions[j] assert bb.center[j] - dimensions <= low assert bb.center[j] - dimensions >= low - tol assert bb.center[j] + dimensions >= high assert bb.center[j] + dimensions <= high + tol @pytest.mark.parametrize( "case, condition, inner, answer",