Repository navigation
Faster offsets of pours: clusters by edge distance, repeated clusters computed once, Memo - #7
Merged
Merged
Conversation
… boxes Two rings were in one cluster when the boxes of some of their edges came within a unit of each other, tested for every pair of rings with overlapping boxes by a scan of both rings' chunks of edges. A pour's outer ring was so compared whole with every hole inside it, the search ran out of its budget and the union was computed in one piece; and long diagonal edges put rings in one cluster that only shared a box. Rings are now in one cluster when some of their edges come within three units of each other (snap rounding relates nothing farther apart than 2.4, see the module documentation), found by a descent of a binary tree of boxes over each ring's chunks of sixteen edges and then by the distance of the edges whose boxes come within reach. On the openings of the pours of a routed board recorded while tracks were added (cynthion: 391 openings, 3.3 M vertices, 18.6 M edges of raw offset curves), the unions computed in one piece for want of budget go from 1.9 M edges to 0.05 M. The output is the same (tests compare clusters with one piece at every distance round the reach; the hash of every vertex of the recorded openings is unchanged). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
What a cluster of rings gives depends on its edges, on the winding of
the other rings around it and on the fill rules and operation, and it
moves with the cluster: every predicate is exact and takes differences
of coordinates, and new vertices are exact roundings of crossings.
Within one boolean, clusters that are an earlier cluster moved (the same
edges relative to their first vertex, the same base winding; found by a
hash and then compared) are computed once and the result moved.
A Memo keeps the results of clusters from one operation to the next
(Boolean::memo, Memo::offset, Memo::offset_tagged, Memo::opening,
Memo::closing): a zone poured again after a few tracks moved has most of
its clusters as they were. Entries hold the cluster's points and the
result's relative to the first vertex, in 32 bits a coordinate where
they fit; a memo holds at most the bytes it was created with and drops
what was used least recently. The output is the same with and without a
memo; lone simple rings are not kept (they are passed through anyway).
Openings of the pours of three routed boards recorded while tracks were
added, one thread, best of 3, with the clusters by distance of the
commit before (ms):
0.0.6 no memo memo of 64 MiB
cynthion 8212 5641 3518
glasgow-revD1 2299 1666 1248
tinytapeout-demo 3584 3112 1775
56 % of the edges of cynthion's lone rings that have to be noded are in
a ring that is an earlier ring of the same union moved, and 80 % in a
ring an earlier opening had. The hash of every vertex of every result is
unchanged, without rayon and with it on one and four threads; with
set_memo_verify every reused result is computed as well and compared
(tests/memo.rs, and the recorded openings).
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
….rs) Times shrink, grow and opening on recorded calls (a file of the inputs of cadlab's openings) or on generated pours with their statistics: two layers of a board of 100 mm, pads of footprints, vias and tracks grown by their clearance taken from the pour, each poured four times while tracks are added. Prints a hash of every vertex of every result, to compare two builds; OFFSET_BENCH_MEMO runs the openings with a Memo kept over the calls and OFFSET_BENCH_VERIFY checks every reused result. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Round-join offsets of pour-shaped input (the openings a PCB tool runs for the minimum copper width) spend 92 % of their time in the union of the raw offset curves, and that union's profile is flat (noding 46 %, merging 13-17 %, sweep 9-11 %, assembly 7 %); building the raw curves is 5 %. What can be saved without changing a vertex of the output is how much of the union is computed at all.
Clusters by the distance of the edges (
perf). Rings were in one cluster when the boxes of some of their edges came within a unit of each other, tested by a scan of both rings' chunks for every pair of rings with overlapping boxes. A pour's outer ring was compared whole with every hole, the search ran out of its budget and the union ran in one piece; long diagonal edges joined rings that only shared a box. Rings are now in one cluster when some of their edges come within three units of each other (snap rounding relates nothing farther apart than 2.4, argued incluster.rs), found by a descent of a tree of boxes over each ring's chunks of edges.Clusters that are another one moved are computed once, and
Memokeeps the results of clusters from one operation to the next (feat):Boolean::memo,Memo::offset,Memo::offset_tagged,Memo::opening,Memo::closing. A cluster's result depends on its edges, the winding of the other rings around it, the fill rules and the operation, and moves with the cluster. A memo holds at most the bytes it is created with and drops what was used least recently. The output is the same with and without one.Bench (
examples/offset_bench.rs): recorded calls or generated pours, with a hash of every vertex of every result.Openings of the pours of three routed boards, recorded while tracks were added (391, 19 and 51 calls; 3.3 M, 0.8 M and 1.5 M vertices), best of 3, ms:
Same output: the hash of every vertex of every result (shrink and opening of every call) is unchanged on all four inputs, without
rayonand with it on one and four threads, with and without a memo; withset_memo_verifyevery reused result is also computed and compared, on the recorded calls and intests/memo.rs. The existing tests that compare clustered booleans and offsets with the one-piece computation pass; new unit tests compare the tree descent with all pairs of edges and clusters with one piece at every distance round the reach, and a property test checks that a boolean of moved input is the result moved.Checked here:
cargo fmt --check, clippy with all features and with none (-D warnings), tests in debug and release with all features and in release with none, rustdoc with-D warnings,cargo bench --no-run,cargo +1.89 check --all-features --lib. Not run here: the i686 target, Windows and macOS (CI), the fuzz targets, the Clipper2 oracle.🤖 Generated with Claude Code