core.utils

Core utilities.

Classes

OrderedEnum

An OrderedEnum is an enum that allows for comparisons with <, >, <=, and >= based on entries' values.

Functions

angle_between(v1, v2)

Get the angle from v1 to v2 (in radians).

angle_range_contains(range_, angle)

Returns True if angle is contained in range_ (mod shapemachine.core.utils.tau).

angles_similar(angle1, angle2)

Returns True if two angles are equivalent (mod pi).

are_points_collinear(v1, v2, v3)

Returns True if points v1, v2, and v3 are collinear.

are_points_counterclockwise(v1, v2, v3)

Returns True if points v1, v2, and v3 are arranged in a counter-clockwise fashion.

join_angle_ranges(range1, range2)

Join angle ranges, assuming they overlap.

list_fuzzy_subset(list1, list2)

Returns True if every element in list1 has a unique match in list2.

list_fuzzy_union(list1, list2)

Returns a new list made from list1 and all elements in list2 not already present in the new list.

normalize_angle(angle)

Normalize an angle to range [0, 2 * pi].

points_close(p1, p2)

Returns True if the distance between two points is less than shapemachine.core.utils.tolerance.

range_contains(range_, x)

Returns True if x is contained in range_.

reduce_points(points)

Given a numpy array of shape (n, 3), create clusters of rows such that each row in the cluster is close to another row in the group.

Module attributes

tau

2 * pi.

angle_between(v1: ArrayLike, v2: ArrayLike) float

Get the angle from v1 to v2 (in radians).

angle_range_contains(range_: Tuple[float, float], angle: float) bool

Returns True if angle is contained in range_ (mod shapemachine.core.utils.tau). Fuzzy with shapemachine.core.utils.tolerance.

angles_similar(angle1: float, angle2: float) bool

Returns True if two angles are equivalent (mod pi). Fuzzy with shapemachine.core.utils.tolerance.

are_points_collinear(v1: ArrayLike, v2: ArrayLike, v3: ArrayLike) bool

Returns True if points v1, v2, and v3 are collinear. Fuzzy with shapemachine.core.utils.tolerance.

are_points_counterclockwise(v1: ArrayLike, v2: ArrayLike, v3: ArrayLike) bool

Returns True if points v1, v2, and v3 are arranged in a counter-clockwise fashion.

join_angle_ranges(range1: Tuple[float, float], range2: Tuple[float, float]) Tuple[float, float]

Join angle ranges, assuming they overlap. Fuzzy with shapemachine.core.utils.tolerance.

list_fuzzy_subset(list1: List[float], list2: List[float]) bool

Returns True if every element in list1 has a unique match in list2.

list_fuzzy_union(list1: List[float], list2: List[float]) List[float]

Returns a new list made from list1 and all elements in list2 not already present in the new list. Note that this only keeps duplicates from the first list.

normalize_angle(angle: float) float

Normalize an angle to range [0, 2 * pi].

points_close(p1: ndarray, p2: ndarray) bool

Returns True if the distance between two points is less than shapemachine.core.utils.tolerance.

range_contains(range_: Tuple[float, float], x: float) bool

Returns True if x is contained in range_. Fuzzy with shapemachine.core.utils.tolerance.

reduce_points(points: ndarray) Iterator[Tuple[ndarray, Set[int]]]

Given a numpy array of shape (n, 3), create clusters of rows such that each row in the cluster is close to another row in the group. Compute the center of each cluster, and yield that center along with the indices of the rows in the cluster.

Parameters:

points – An (n, 3) numpy array.

Returns:

An iterator that yields (center, cluster indices) pairs

tau: float = 6.283185307179586

2 * pi.