From 0ff6735025ca6eaefc8494861a4b32f5f6af7463 Mon Sep 17 00:00:00 2001 From: Lachlan Grose Date: Mon, 4 Dec 2023 09:59:06 +1100 Subject: [PATCH] fix: isinside and init with list --- LoopStructural/datatypes/_bounding_box.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/LoopStructural/datatypes/_bounding_box.py b/LoopStructural/datatypes/_bounding_box.py index 185a02fe1..0e335e7bc 100644 --- a/LoopStructural/datatypes/_bounding_box.py +++ b/LoopStructural/datatypes/_bounding_box.py @@ -12,8 +12,8 @@ def __init__( maximum: Optional[np.ndarray] = None, nsteps: Optional[np.ndarray] = None, ): - self._origin = origin - self._maximum = maximum + self._origin = np.array(origin) + self._maximum = np.array(maximum) self.dimensions = dimensions if nsteps is None: self.nsteps = np.array([50, 50, 25]) @@ -122,7 +122,13 @@ def __getitem__(self, name): return self.get_value(name) def is_inside(self, xyz): - inside = np.zeros(xyz.shape[0], dtype=bool) + if len(xyz.shape) == 1: + xyz = xyz.reshape((1, -1)) + if xyz.shape[1] != 3: + raise LoopValueError( + f"locations array is {xyz.shape[1]}D but bounding box is {self.dimensions}" + ) + inside = np.ones(xyz.shape[0], dtype=bool) inside = np.logical_and(inside, xyz[:, 0] > self.origin[0]) inside = np.logical_and(inside, xyz[:, 0] < self.maximum[0]) inside = np.logical_and(inside, xyz[:, 1] > self.origin[1])