From 9a8f9be2e639d97848c41571fd5dcb36580cdb25 Mon Sep 17 00:00:00 2001 From: Michael Dawson-Haggerty Date: Fri, 10 May 2024 15:44:01 -0400 Subject: [PATCH] test and fix for #2224 --- tests/test_paths.py | 20 ++++++++++++++++++++ trimesh/constants.py | 8 ++++++-- trimesh/path/exchange/misc.py | 3 ++- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/tests/test_paths.py b/tests/test_paths.py index 61c2a44dd..9aa8ff04b 100644 --- a/tests/test_paths.py +++ b/tests/test_paths.py @@ -298,6 +298,26 @@ def test_section(self): # should be a valid Path2D g.check_path2D(planar) + def test_multiplane(self): + # check to make sure we're applying `tol_path.merge_digits` for line segments + vertices = g.np.array( + [ + [19.402250931139097, -14.88787016674277, 64.0], + [20.03318396099334, -14.02738654377374, 64.0], + [19.402250931139097, -14.88787016674277, 0.0], + [20.03318396099334, -14.02738654377374, 0.0], + [21, -16.5, 32], + ] + ) + faces = g.np.array( + [[1, 3, 0], [0, 3, 2], [1, 0, 4], [0, 2, 4], [3, 1, 4], [2, 3, 4]] + ) + z_layer_centers = g.np.array([3, 3.0283334255218506]) + m = g.trimesh.Trimesh(vertices, faces) + r = m.section_multiplane([0, 0, 0], [0, 0, 1], z_layer_centers) + assert len(r) == 2 + assert all(i.is_closed for i in r) + if __name__ == "__main__": g.trimesh.util.attach_to_log() diff --git a/trimesh/constants.py b/trimesh/constants.py index 28d4cdcf1..3c79982f2 100644 --- a/trimesh/constants.py +++ b/trimesh/constants.py @@ -2,7 +2,7 @@ import numpy as np -from .util import log, now +from .util import decimal_to_digits, log, now @dataclass @@ -88,6 +88,7 @@ class TolerancePath: zero: float = 1e-12 merge: float = 1e-5 + planar: float = 1e-5 seg_frac: float = 0.125 seg_angle: float = float(np.radians(50)) @@ -98,9 +99,12 @@ class TolerancePath: radius_min: float = 1e-4 radius_max: float = 50.0 tangent: float = float(np.radians(20)) - strict: bool = False + @property + def merge_digits(self) -> int: + return decimal_to_digits(self.merge) + @dataclass class ResolutionPath: diff --git a/trimesh/path/exchange/misc.py b/trimesh/path/exchange/misc.py index e99d56429..2ae3423ed 100644 --- a/trimesh/path/exchange/misc.py +++ b/trimesh/path/exchange/misc.py @@ -1,6 +1,7 @@ import numpy as np from ... import graph, grouping, util +from ...constants import tol_path from ..entities import Arc, Line @@ -62,7 +63,7 @@ def lines_to_path(lines): # convert lines to even number of (n, dimension) points lines = lines.reshape((-1, dimension)) # merge duplicate vertices - unique, inverse = grouping.unique_rows(lines) + unique, inverse = grouping.unique_rows(lines, digits=tol_path.merge_digits) # use scipy edges_to_path to skip creating # a bajillion individual line entities which # will be super slow vs. fewer polyline entities