Skip to content

Commit

Permalink
test and fix for #2224
Browse files Browse the repository at this point in the history
  • Loading branch information
mikedh committed May 10, 2024
1 parent b7dc7e0 commit 9a8f9be
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
20 changes: 20 additions & 0 deletions tests/test_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
8 changes: 6 additions & 2 deletions trimesh/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import numpy as np

from .util import log, now
from .util import decimal_to_digits, log, now


@dataclass
Expand Down Expand Up @@ -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))
Expand All @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion trimesh/path/exchange/misc.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import numpy as np

from ... import graph, grouping, util
from ...constants import tol_path
from ..entities import Arc, Line


Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9a8f9be

Please sign in to comment.