Skip to content

Commit 5b5fcc7

Browse files
committed
add inplace arg to boundingbox
1 parent 7ca8810 commit 5b5fcc7

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

LoopStructural/datatypes/_bounding_box.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -500,41 +500,50 @@ def structured_grid(
500500
name=name,
501501
)
502502

503-
def project(self, xyz):
503+
def project(self, xyz, inplace=False):
504504
"""Project a point into the bounding box
505505
506506
Parameters
507507
----------
508508
xyz : np.ndarray
509509
point to project
510+
inplace : bool, optional
511+
Whether to modify the input array in place, by default False
510512
511513
Returns
512514
-------
513515
np.ndarray
514516
projected point
515517
"""
516-
518+
if inplace:
519+
xyz -= self.global_origin
520+
xyz = np.clip(xyz, self.origin, self.maximum)
521+
return xyz
517522
return (xyz - self.global_origin) / np.max(
518523
(self.global_maximum - self.global_origin)
519524
) # np.clip(xyz, self.origin, self.maximum)
520525

521526
def scale_by_projection_factor(self, value):
522527
return value / np.max((self.global_maximum - self.global_origin))
523528

524-
def reproject(self, xyz):
529+
def reproject(self, xyz, inplace=False):
525530
"""Reproject a point from the bounding box to the global space
526531
527532
Parameters
528533
----------
529534
xyz : np.ndarray
530535
point to reproject
531-
536+
inplace : bool, optional
537+
Whether to modify the input array in place, by default False
532538
Returns
533539
-------
534540
np.ndarray
535541
reprojected point
536542
"""
537-
543+
if inplace:
544+
xyz -= self.global_origin
545+
xyz /= np.max((self.global_maximum - self.global_origin))
546+
return xyz
538547
return xyz * np.max((self.global_maximum - self.global_origin)) + self.global_origin
539548

540549
def __repr__(self):

0 commit comments

Comments
 (0)