Skip to content

Commit

Permalink
Added checker function for determining which coordinates are within a…
Browse files Browse the repository at this point in the history
… bounding box
  • Loading branch information
timbernat committed Apr 24, 2024
1 parent 7878773 commit b788cb3
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion polymerist/maths/lattices/coordops.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import numpy as np
from itertools import product as cartesian_product

from ...genutils.typetools.numpytypes import Shape, N, M, DType
from ...genutils.typetools.numpytypes import Shape, N, M, L, DType


def mean_coord(coords : np.ndarray[Shape[M, N], DType]) -> np.ndarray[Shape[N], DType]:
Expand Down Expand Up @@ -37,3 +37,9 @@ def bounding_box_points(coords : np.ndarray[Shape[M, N], DType]) -> np.ndarray[S
corner_point
for corner_point in cartesian_product(*np.vstack(bounding_box_extrema(coords)).T)
])

def coords_inside_bbox(coords : np.ndarray[Shape[M, N], DType], lower : np.ndarray[Shape[1, N], DType], upper : np.ndarray[Shape[1, N], DType], strict : bool=False) -> np.ndarray[Shape[M, N], bool]:
'''Boolean mask of whether coordinates are within the boundaries of some bounding box
With strict=True, points on the boundary are not considered inside; with strict=False, points on the boundary are considered insde as well'''
less_funct = np.less if strict else np.less_equal # set "<" vs "<=" check by strict flag
return less_funct(lower, coords) & less_funct(coords, upper)

0 comments on commit b788cb3

Please sign in to comment.