toolwake 0.2.2__tar.gz → 0.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (26) hide show
  1. {toolwake-0.2.2 → toolwake-0.3.0}/CHANGELOG.md +71 -0
  2. {toolwake-0.2.2/src/toolwake.egg-info → toolwake-0.3.0}/PKG-INFO +1 -1
  3. {toolwake-0.2.2 → toolwake-0.3.0}/pyproject.toml +1 -1
  4. {toolwake-0.2.2 → toolwake-0.3.0}/src/toolwake/__init__.py +1 -1
  5. {toolwake-0.2.2 → toolwake-0.3.0}/src/toolwake/simulate.py +64 -11
  6. {toolwake-0.2.2 → toolwake-0.3.0/src/toolwake.egg-info}/PKG-INFO +1 -1
  7. {toolwake-0.2.2 → toolwake-0.3.0}/tests/test_toolwake.py +81 -0
  8. {toolwake-0.2.2 → toolwake-0.3.0}/LICENSE +0 -0
  9. {toolwake-0.2.2 → toolwake-0.3.0}/MANIFEST.in +0 -0
  10. {toolwake-0.2.2 → toolwake-0.3.0}/README.md +0 -0
  11. {toolwake-0.2.2 → toolwake-0.3.0}/examples/demo.py +0 -0
  12. {toolwake-0.2.2 → toolwake-0.3.0}/setup.cfg +0 -0
  13. {toolwake-0.2.2 → toolwake-0.3.0}/src/toolwake/cli.py +0 -0
  14. {toolwake-0.2.2 → toolwake-0.3.0}/src/toolwake/deposit.py +0 -0
  15. {toolwake-0.2.2 → toolwake-0.3.0}/src/toolwake/geometry.py +0 -0
  16. {toolwake-0.2.2 → toolwake-0.3.0}/src/toolwake/profile.py +0 -0
  17. {toolwake-0.2.2 → toolwake-0.3.0}/src/toolwake/render.py +0 -0
  18. {toolwake-0.2.2 → toolwake-0.3.0}/src/toolwake/serve.py +0 -0
  19. {toolwake-0.2.2 → toolwake-0.3.0}/src/toolwake/tool.py +0 -0
  20. {toolwake-0.2.2 → toolwake-0.3.0}/src/toolwake/toolpath.py +0 -0
  21. {toolwake-0.2.2 → toolwake-0.3.0}/src/toolwake/viewer.py +0 -0
  22. {toolwake-0.2.2 → toolwake-0.3.0}/src/toolwake.egg-info/SOURCES.txt +0 -0
  23. {toolwake-0.2.2 → toolwake-0.3.0}/src/toolwake.egg-info/dependency_links.txt +0 -0
  24. {toolwake-0.2.2 → toolwake-0.3.0}/src/toolwake.egg-info/entry_points.txt +0 -0
  25. {toolwake-0.2.2 → toolwake-0.3.0}/src/toolwake.egg-info/requires.txt +0 -0
  26. {toolwake-0.2.2 → toolwake-0.3.0}/src/toolwake.egg-info/top_level.txt +0 -0
@@ -4,6 +4,77 @@ All notable changes to this project are documented here. Format follows
4
4
  [Keep a Changelog](https://keepachangelog.com/en/1.1.0/); versions follow
5
5
  [Semantic Versioning](https://semver.org/).
6
6
 
7
+ ## [0.3.0] — 2026-09-24
8
+
9
+ Performance. Verdicts are unchanged on every file tested; reported clearances
10
+ for DISTANT material are not, which is why this is a minor rather than a patch.
11
+
12
+ ### Changed
13
+ - **`search` default 0.02 → 0.002 m.** Twenty millimetres of padding around
14
+ every query meant that on a 10 mm part the query box covered the whole
15
+ thing and the spatial hash could prune nothing: 949 candidate beads per
16
+ query against a wake of 2 046, and 99.2% of the 30 million point-distance
17
+ evaluations were against material nowhere near the tool.
18
+
19
+ Detection is unaffected — 2 mm is still more than forty times the largest
20
+ bead radius. What changes is that a clearance larger than `search` now
21
+ reports `inf` instead of a number, so anything printing at a much larger
22
+ scale wants this raised.
23
+ - **Grid cell size now follows the TOOL, not `search`.** They were tied
24
+ (`cell = search / 4`), which welded two opposing costs to one knob:
25
+ shrinking `search` cut candidates per query 36x (949 → 26) but grew the
26
+ cells walked per query 1000x (8 → 7 913), because the cell shrank with it.
27
+ Below about 5 mm the second swamped the first and asking for a tighter
28
+ search radius made the whole sweep *slower*.
29
+
30
+ Query boxes are a tool bounding box plus `search`, so the tool's own width
31
+ is what the grid should be sized against. For a luer tip that is the 11 mm
32
+ collar, giving 2.75 mm cells — within noise of the 2.5 mm that measured
33
+ fastest. The housing is excluded: at 130 mm it would force cells so coarse
34
+ that every needle query returned the whole wake.
35
+
36
+ Measured over the reference set, with every verdict and every worst clearance
37
+ identical to 0.2.3:
38
+
39
+ | toolpath | rows | 0.2.3 | 0.3.0 | |
40
+ |---|---|---|---|---|
41
+ | 360-180 SMOL Middle | 36 305 | 626 s | 252 s | 2.5x |
42
+ | 360-180 SMOL Middle (1) | 36 305 | 577 s | 261 s | 2.2x |
43
+ | test_infill | 2 674 | 7.3 s | 1.0 s | 7.2x |
44
+ | REDO WOW Slab | 2 674 | 7.8 s | 3.6 s | 2.2x |
45
+ | slab_infill | 2 674 | 7.2 s | 3.8 s | 1.9x |
46
+ | small_slab | 1 747 | 3.0 s | 2.3 s | 1.3x |
47
+ | LightPipeRobotTest | 1 170 | 0.8 s | 0.7 s | 1.1x |
48
+
49
+ Timings are from one laptop and vary with what else it is doing; treat the
50
+ ratios as indicative, not as a benchmark.
51
+
52
+ ## [0.2.3] — 2026-09-18
53
+
54
+ Touching is not penetrating. Reported collision counts change.
55
+
56
+ ### Fixed
57
+ - **Exact tangency was reported as a collision, at random.** With
58
+ `bead_radius` and `bead_drop` both h/2 — the setting that makes a bead fill
59
+ its layer, which 0.2.1 introduced — a same-layer neighbour passing under the
60
+ nozzle wall sits at a clearance of EXACTLY zero. Which side of zero each one
61
+ lands on is rounding, not geometry.
62
+
63
+ On a real 36 305-row part that put **4 677 rows, 12.9% of the file**, on the
64
+ wrong side and reported them as collisions. Every one was blamed on the
65
+ cannula, every culprit bead was a same-layer neighbour 0.066–0.093 mm away
66
+ laterally — under the wall, outside the bore — and every penetration depth
67
+ printed as `-0.0000 mm`.
68
+
69
+ `Result.n_hits` and `Result.status` now ignore anything shallower than
70
+ `CONTACT_TOL` (1e-12 m), which is six orders of magnitude above
71
+ double-precision noise on metre-scale coordinates and seven below anything
72
+ this models. `report()` reports such a row as `0.0` rather than `-0.0`.
73
+ - **A zero threshold reported tangencies as "close".** With no warning band,
74
+ a clearance of -1e-13 satisfied both "not penetrating" and "below the
75
+ threshold", so a clean result came back as `warn`. A threshold of zero now
76
+ means what it says: only penetration counts.
77
+
7
78
  ## [0.2.2] — 2026-09-18
8
79
 
9
80
  Bounds the size of the viewer page. No reported number changes.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: toolwake
3
- Version: 0.2.2
3
+ Version: 0.3.0
4
4
  Summary: Simulate a depositing tool travelling a toolpath, accumulate the material it leaves in its wake, and check the tool against it.
5
5
  Author-email: Zane Bates <zanetbates1@gmail.com>
6
6
  License: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "toolwake"
7
- version = "0.2.2"
7
+ version = "0.3.0"
8
8
  description = "Simulate a depositing tool travelling a toolpath, accumulate the material it leaves in its wake, and check the tool against it."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.9"
@@ -19,7 +19,7 @@ from .profile import Section, ToolProfile, blunt_cannula, luer_taper_tip
19
19
  from .tool import Needle, ToolPose
20
20
  from .toolpath import PRINT, TRAVEL, Toolpath
21
21
 
22
- __version__ = "0.2.2"
22
+ __version__ = "0.3.0"
23
23
 
24
24
  __all__ = [
25
25
  "Toolpath", "PRINT", "TRAVEL",
@@ -23,6 +23,21 @@ from .toolpath import PRINT, Toolpath
23
23
 
24
24
  __all__ = ["Result", "simulate"]
25
25
 
26
+ # Below this, a negative clearance is not a penetration — it is a tangency that
27
+ # lost a coin-flip on the sign bit, metres.
28
+ #
29
+ # Tangency is not an edge case here, it is the designed-for case: with
30
+ # `bead_radius` and `bead_drop` both h/2 a bead exactly fills its layer, so a
31
+ # same-layer neighbour passing under the nozzle wall sits at a clearance of
32
+ # EXACTLY zero. Whether each one lands at +0, -1e-18 or +1e-18 is rounding.
33
+ #
34
+ # On a real 36 305-row part that put 4 677 rows — 12.9% of the file — on the
35
+ # wrong side of zero and reported them as collisions, every one at a depth that
36
+ # printed as -0.0000 mm. A picometre is six orders of magnitude above
37
+ # double-precision noise on metre-scale coordinates and seven below anything
38
+ # this models, so nothing physical can hide beneath it.
39
+ CONTACT_TOL = 1e-12
40
+
26
41
 
27
42
  @dataclass
28
43
  class Result:
@@ -45,13 +60,25 @@ class Result:
45
60
 
46
61
  @property
47
62
  def n_hits(self) -> int:
48
- """Rows where the tool actually penetrates deposited material."""
49
- return int(np.sum(self.clearance < 0))
63
+ """Rows where the tool actually penetrates deposited material.
64
+
65
+ Touching is not penetrating — see CONTACT_TOL.
66
+ """
67
+ return int(np.sum(self.clearance < -CONTACT_TOL))
50
68
 
51
69
  @property
52
70
  def n_close(self) -> int:
53
- """Rows inside the warning band but not penetrating."""
54
- return int(np.sum((self.clearance >= 0) & (self.clearance < self.threshold)))
71
+ """Rows inside the warning band but not penetrating.
72
+
73
+ A threshold of zero means there is no warning band — only penetration
74
+ counts. Without the guard, a tangency at -1e-13 satisfies both
75
+ "not penetrating" and "below zero" and gets reported as close, so a
76
+ result with nothing wrong with it comes back as a warning.
77
+ """
78
+ if self.threshold <= 0:
79
+ return 0
80
+ return int(np.sum((self.clearance >= -CONTACT_TOL)
81
+ & (self.clearance < self.threshold)))
55
82
 
56
83
  @property
57
84
  def status(self) -> str:
@@ -64,6 +91,10 @@ class Result:
64
91
  def report(self) -> dict:
65
92
  """A JSON-ready summary, shaped like a clearance report."""
66
93
  w = self.worst
94
+ # A tangency rounds to "-0.0", which looks like a penetration sitting
95
+ # in a report that has just said there were none.
96
+ if np.isfinite(w) and abs(w) <= CONTACT_TOL:
97
+ w = 0.0
67
98
  i = int(np.argmin(np.where(np.isfinite(self.clearance),
68
99
  self.clearance, np.inf)))
69
100
  return {
@@ -88,7 +119,7 @@ class Result:
88
119
 
89
120
 
90
121
  def simulate(path: Toolpath, needle: Needle | None = None, *, lag: int = 8,
91
- threshold: float = 5e-4, search: float = 0.02,
122
+ threshold: float = 5e-4, search: float = 0.002,
92
123
  bead_radius: float | None = None, bead_drop: float = 0.0,
93
124
  progress=None) -> Result:
94
125
  """Run the wake simulation over `path`.
@@ -99,8 +130,18 @@ def simulate(path: Toolpath, needle: Needle | None = None, *, lag: int = 8,
99
130
  lag: rows of immunity behind the nozzle. Material laid within this many
100
131
  rows is not treated as an obstacle.
101
132
  threshold: clearance below which a row counts as "close", metres.
102
- search: broad-phase radius, metres. Beads beyond this are not measured;
103
- raise it if the housing is large.
133
+ search: broad-phase radius, metres. Beads beyond this are not measured,
134
+ so a clearance larger than `search` comes back as `inf`.
135
+
136
+ Detection is unaffected as long as this exceeds the bead radius,
137
+ which it does by more than an order of magnitude; what it bounds is
138
+ how far away a clearance is still worth reporting a number for.
139
+
140
+ It was 0.02 (20 mm), which on a 10 mm part meant the query box
141
+ covered the whole thing and the spatial hash could prune nothing —
142
+ 949 candidate beads per query against a wake of 2 046. Measured
143
+ across three real files, dropping it to 2 mm is 1.9x to 5.1x
144
+ faster with identical verdicts and identical worst clearances.
104
145
  bead_radius: radius of the laid bead, metres. Defaults to the needle's
105
146
  bore radius, which assumes the bead keeps the round cross-section
106
147
  it had inside the needle.
@@ -140,10 +181,22 @@ def simulate(path: Toolpath, needle: Needle | None = None, *, lag: int = 8,
140
181
  r_bead = needle.bead_radius if bead_radius is None else float(bead_radius)
141
182
  if r_bead < 0:
142
183
  raise ValueError("bead_radius must be >= 0")
143
- # The grid only exists to shrink the candidate set, so scale it to the
144
- # query, not the bead — see Deposit.__init__.
145
- dep = Deposit(bead_radius=r_bead,
146
- cell=max(search / 4.0, 8.0 * r_bead))
184
+ # Cell size follows the TOOL, not the search radius. Tying it to `search`
185
+ # welded two opposing costs to one knob: shrinking `search` cut candidates
186
+ # per query 36x (949 -> 26) but grew the cells walked per query 1000x
187
+ # (8 -> 7 913), because the cell shrank with it. Below about 5 mm the
188
+ # second swamped the first and shrinking the search radius made the whole
189
+ # sweep SLOWER.
190
+ #
191
+ # The query boxes are a tool bounding box plus `search`, so the tool's own
192
+ # width is what the grid should be sized against. For a luer tip that is
193
+ # the 11 mm collar, giving 2.75 mm cells — within noise of the 2.5 mm that
194
+ # measured fastest. The housing is deliberately excluded: at 130 mm it
195
+ # would force cells so coarse that every needle query returned the whole
196
+ # wake, and its own query is already bounded by the occupied-cell count.
197
+ span = 2.0 * max((sec.r_max for sec in needle.profile.sections),
198
+ default=r_bead)
199
+ dep = Deposit(bead_radius=r_bead, cell=max(span / 4.0, 8.0 * r_bead))
147
200
  n = len(path)
148
201
  clearance = np.full(n, np.inf)
149
202
  culprit = np.full(n, -1, dtype=int)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: toolwake
3
- Version: 0.2.2
3
+ Version: 0.3.0
4
4
  Summary: Simulate a depositing tool travelling a toolpath, accumulate the material it leaves in its wake, and check the tool against it.
5
5
  Author-email: Zane Bates <zanetbates1@gmail.com>
6
6
  License: MIT
@@ -920,3 +920,84 @@ def test_viewer_bounds_the_wake_but_keeps_every_collision():
920
920
  assert len(small) < len(full)
921
921
  assert sum(1 for b in small if b[7]) == n_hot, (
922
922
  "decimation dropped a bead that something collided with")
923
+
924
+
925
+ def test_touching_is_not_penetrating():
926
+ """A tangency must not be reported as a collision.
927
+
928
+ Tangency is the designed-for case, not an edge case: with `bead_radius` and
929
+ `bead_drop` both h/2 a bead exactly fills its layer, so a same-layer
930
+ neighbour passing under the nozzle wall sits at a clearance of EXACTLY
931
+ zero. Which side of zero each one lands on is rounding.
932
+
933
+ On a real 36 305-row part that put 4 677 rows — 12.9% of the file — on the
934
+ wrong side and reported them as collisions, every one at a depth that
935
+ printed as -0.0000 mm.
936
+ """
937
+ from toolwake.simulate import CONTACT_TOL
938
+
939
+ path = Toolpath.helix(radius=0.01, pitch=5e-4, turns=2.0, per_turn=60)
940
+ res = simulate(path, Needle(inner_d=90e-6), lag=4, threshold=0.0)
941
+
942
+ res.clearance = np.array([1e-3, 0.0, -CONTACT_TOL / 10, +CONTACT_TOL / 10,
943
+ -1e-6, -2e-3])
944
+ assert res.n_hits == 2, "only the two real penetrations should count"
945
+ assert res.status == "collision"
946
+
947
+ res.clearance = np.array([1e-3, 0.0, -CONTACT_TOL / 10, +CONTACT_TOL / 10])
948
+ assert res.n_hits == 0, "sub-picometre contact is not a penetration"
949
+ assert res.status == "ok"
950
+ # ...and the report must not show a tangency as a negative clearance.
951
+ assert res.report()["min_clearance_mm"] == 0.0
952
+
953
+
954
+ def test_grid_cell_does_not_follow_the_search_radius():
955
+ """Cell size must depend on the TOOL, not on `search`.
956
+
957
+ Tying them together welded two opposing costs to one knob: shrinking
958
+ `search` cut candidates per query 36x (949 -> 26) but grew the cells
959
+ walked per query 1000x (8 -> 7 913), because the cell shrank with it.
960
+ Below about 5 mm the second swamped the first and asking for a tighter
961
+ search radius made the whole sweep slower — the opposite of the point.
962
+ """
963
+ path = Toolpath.helix(radius=0.01, pitch=1e-3, turns=3.0, per_turn=60)
964
+ needle = Needle.luer(inner_d=90e-6)
965
+
966
+ wide = simulate(path, needle, lag=4, threshold=0.0, search=0.02)
967
+ tight = simulate(path, needle, lag=4, threshold=0.0, search=0.001)
968
+
969
+ assert wide.deposit.cell == tight.deposit.cell, (
970
+ f"cell moved with search: {wide.deposit.cell} vs {tight.deposit.cell}")
971
+
972
+ # And it should be sized against the tool's own width — the collar, here.
973
+ span = 2.0 * max(sec.r_max for sec in needle.profile.sections)
974
+ expected = max(span / 4.0, 8.0 * needle.bead_radius)
975
+ assert wide.deposit.cell == pytest.approx(expected)
976
+
977
+ # Narrowing the search must not change the verdict, only the work done.
978
+ assert wide.n_hits == tight.n_hits
979
+
980
+
981
+ def test_narrowing_the_search_radius_prunes_work():
982
+ """A tighter search must measure strictly fewer beads, not more."""
983
+ path = Toolpath.helix(radius=0.01, pitch=1e-3, turns=3.0, per_turn=60)
984
+ needle = Needle.luer(inner_d=90e-6)
985
+
986
+ seen = {}
987
+ from toolwake.geometry import Cylinder
988
+ original = Cylinder.distance
989
+
990
+ def counted(self, pts, _key=None):
991
+ seen[key] = seen.get(key, 0) + len(np.atleast_2d(pts))
992
+ return original(self, pts)
993
+
994
+ try:
995
+ Cylinder.distance = counted
996
+ for key in ("wide", "tight"):
997
+ simulate(path, needle, lag=4, threshold=0.0,
998
+ search=0.02 if key == "wide" else 0.001)
999
+ finally:
1000
+ Cylinder.distance = original
1001
+
1002
+ assert seen["tight"] < seen["wide"], (
1003
+ f"tight search measured {seen['tight']} points, wide {seen['wide']}")
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes