diff --git a/trimesh/interval.py b/trimesh/interval.py index 2c5aba7ec..73782d5bf 100644 --- a/trimesh/interval.py +++ b/trimesh/interval.py @@ -13,8 +13,8 @@ def intersection(a: NDArray[float64], b: NDArray[float64]) -> NDArray[float64]: """ - Given a pair of ranges, merge them in to - one range if they overlap at all + Given pairs of ranges merge them in to + one range if they overlap. Parameters -------------- @@ -27,7 +27,7 @@ def intersection(a: NDArray[float64], b: NDArray[float64]) -> NDArray[float64]: -------------- inter : (2, ) or (2, 2) float The unioned range from the two inputs, - if not overlapping ptp will be zero. + if not `inter.ptp(axis=1)` will be zero. """ a = np.array(a, dtype=np.float64) b = np.array(b, dtype=np.float64) diff --git a/trimesh/path/segments.py b/trimesh/path/segments.py index 960a89bf7..566be34ab 100644 --- a/trimesh/path/segments.py +++ b/trimesh/path/segments.py @@ -177,9 +177,11 @@ def clean(segments: NDArray[float64], digits: int = 10) -> NDArray[float64]: # collect new unified paramameters p, o, v = [], [], [] for g in group_rows(np.column_stack((origins, vectors)), digits=digits): + # union the intervals sorting ourselves to skip the `sort(axis=1)` we did above group = param[g] u = interval.union(group[group[:, 0].argsort()], sort=False) p.extend(u) + # use the origins for the subsetted union o.extend(origins[g[: len(u)]]) v.extend(vectors[g[: len(u)]])