Skip to content

Commit

Permalink
Merge branch 'fix/docs_and_cleanup' of github.com:Loop3D/LoopStructur…
Browse files Browse the repository at this point in the history
…al into fix/docs_and_cleanup
  • Loading branch information
lachlangrose committed Feb 17, 2025
2 parents f6ee608 + bba3623 commit 8b5a8e3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
27 changes: 14 additions & 13 deletions LoopStructural/datatypes/_bounding_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,36 +288,37 @@ def with_buffer(self, buffer: float = 0.2) -> BoundingBox:
# xyz = np.array(xyz)
# if len(xyz.shape) == 1:
# xyz = xyz.reshape((1, -1))
# distances = np.maximum(0,

# distances = np.maximum(0,
# np.maximum(self.global_origin+self.origin - xyz,
# xyz - self.global_maximum))
# distance = np.linalg.norm(distances, axis=1)
# distance[self.is_inside(xyz)] = -1
# return distance
def __call__(self,xyz):
# Calculate center and half-extents of the box
center = (self.maximum + self.global_origin+self.origin) / 2
half_extents = (self.maximum - self.global_origin+self.origin) / 2

def __call__(self, xyz):
# Calculate center and half-extents of the box
center = (self.maximum + self.global_origin + self.origin) / 2
half_extents = (self.maximum - self.global_origin + self.origin) / 2

# Calculate the distance from point to center
offset = np.abs(xyz - center) - half_extents

# Inside distance: negative value based on the smallest penetration
inside_distance = np.min(half_extents - np.abs(xyz - center),axis=1)
inside_distance = np.min(half_extents - np.abs(xyz - center), axis=1)

# Outside distance: length of the positive components of offset
outside_distance = np.linalg.norm(np.maximum(offset, 0))

# If any component of offset is positive, we're outside
# Otherwise, we're inside and return the negative penetration distance
distance = np.zeros(xyz.shape[0])
mask = np.any(offset > 0,axis=1)
mask = np.any(offset > 0, axis=1)
distance[mask] = outside_distance
distance[~mask] = -inside_distance[~mask]
return distance
# return outside_distance if np.any(offset > 0) else -inside_distance

def get_value(self, name):
ix, iy = self.name_map.get(name, (-1, -1))
if ix == -1 and iy == -1:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ def __init__(
aabb_nsteps[aabb_nsteps < 2] = 2
aabb_nsteps = np.array(aabb_nsteps, dtype=int)
step_vector = (self.maximum - self.minimum) / (aabb_nsteps - 1)
self.aabb_grid = StructuredGrid(self.minimum, nsteps=aabb_nsteps, step_vector=step_vector)
self.aabb_grid = StructuredGrid(
self.minimum, nsteps=aabb_nsteps, step_vector=step_vector
)
# make a big table to store which tetra are in which element.
# if this takes up too much memory it could be simplified by using sparse matrices or dict but
# at the expense of speed
Expand Down

0 comments on commit 8b5a8e3

Please sign in to comment.