Skip to content

Commit

Permalink
Merge branch 'bugfix/assert-array-equal' into test/auto-unit-test
Browse files Browse the repository at this point in the history
  • Loading branch information
qbp758 committed Oct 6, 2023
2 parents 5c24ee6 + 4c2a36d commit 4a345c7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 45 deletions.
47 changes: 5 additions & 42 deletions python/rainbow/simulators/prox_soft_bodies/collision_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,8 +486,9 @@ def _contact_determination(overlaps, engine, stats, debug_on):
stats["contact_determination"] = contact_determination_timer.elapsed
return stats


def _cp_unique_id(cp) -> tuple:
""" This function returns a unique id for a contact point.
""" This function returns a unique id for a ContactPoint instance.
Args:
cp (ContactPoint): A instance of the ContactPoint
Expand All @@ -496,7 +497,8 @@ def _cp_unique_id(cp) -> tuple:
"""
return (cp.bodyA, cp.bodyB, tuple(cp.p))

def _optimize_contact_reduction(engine, stats, debug_on):

def _contact_reduction(engine, stats, debug_on):
""" During contact point computation it may happen that different colliding triangles of one body results
in the same contact point locations wrt to the other signed distance field of the other body. Imagine a spiky
polygonal cone pointing into a spherical shape. Here all triangles of the spike will result in the same
Expand All @@ -514,6 +516,7 @@ def _optimize_contact_reduction(engine, stats, debug_on):
Returns:
dict: A dictionary with profiling and timing measurements.
"""
reduction_timer = None
if debug_on:
reduction_timer = Timer("contact_point_reduction", 8)
reduction_timer.start()
Expand All @@ -535,46 +538,6 @@ def _optimize_contact_reduction(engine, stats, debug_on):

return stats

def _contact_reduction(engine, stats, debug_on):
"""
During contact point computation it may happen that different colliding triangles of one body results
in the same contact point locations wrt to the other signed distance field of the other body. Imagine a spiky
polygonal cone pointing into a spherical shape. Here all triangles of the spike will result in the same
contact point at the spiky tip. If the spiky polygonal cone has N triangle faces on the spike then we
will have N redundant contact points. This redundancy is usually bad for other numerical sub-routines for
computing impacts or contact forces. Hence, the purpose of this step is to eliminate redundant
contact point information. One may think of this as a kind of post-filtering process to clean up the
contact point information.
:param engine: The current engine instance we are working with.
:param stats: A dictionary where to add more profiling and timing measurements.
:param debug_on: Boolean flag for toggling debug (aka profiling) info on and off.
:return: A dictionary with profiling and timing measurements.
"""
if engine.params.speedup:
return _optimize_contact_reduction(engine, stats, debug_on)

reduction_timer = None
if debug_on:
reduction_timer = Timer("contact_point_reduction", 8)
reduction_timer.start()
# TODO 2020-09-07 Kristian: This brute force implementation can be implemented better
reduced_list = []
for cp1 in engine.contact_points:
unique = True
for cp2 in reduced_list:
if {cp1.bodyA, cp1.bodyB} == {cp2.bodyA, cp2.bodyB} and (
cp1.p == cp2.p
).all():
unique = False
if unique:
reduced_list.append(cp1)
engine.contact_points = reduced_list
if debug_on:
reduction_timer.end()
stats["contact_point_reduction"] = reduction_timer.elapsed
return stats


def run_collision_detection(engine, stats, debug_on):
"""
Expand Down
2 changes: 1 addition & 1 deletion python/rainbow/util/USD.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def set_animation_time(self, duration: float) -> None:
""" Set the total animation time of the scene
Args:
duration (_type_): The total animation time of the scene
duration (float): The total animation time of the scene
"""
self.stage.SetStartTimeCode(0)
self.stage.SetEndTimeCode(duration)
Expand Down
4 changes: 2 additions & 2 deletions python/rainbow/util/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"""


def is_array_equal(arr1, arr2, dec=8):
def is_array_equal(arr1, arr2):
"""
2022-04-06 Kenny TODO: Write proper documentation.
Expand All @@ -15,7 +15,7 @@ def is_array_equal(arr1, arr2, dec=8):
:param dec:
:return:
"""
return None == np.testing.assert_array_almost_equal(arr1, arr2, dec)
return None == np.testing.assert_allclose(arr1, arr2, rtol=1e-5, atol=1e-8)


def is_array_not_equal(arr1, arr2):
Expand Down

0 comments on commit 4a345c7

Please sign in to comment.