1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-02-23 17:15:05 +01:00
dotSCAD/docs/lib2x-dedup.md

46 lines
1.2 KiB
Markdown
Raw Normal View History

2020-03-19 09:14:42 +08:00
# dedup
Eliminating duplicate copies of repeating vectors. If `lt` has many elements, sorting `lt` first and setting `sorted` to `true` will be faster.
**Since:** 2.3
## Parameters
- `lt` : A list of vectors.
- `sorted` : If `false` (default), use native `search`. If `true`, `lt` must be sorted by zyx (from the last idx to first) and `dedup` will use binary search internally.
## Examples
use <pixel/px_circle.scad>;
use <util/dedup.scad>;
pts1 = px_circle(10, filled = true);
pts2 = [for(p = px_circle(5, filled = true)) p + [10, 0]];
// simple union
pts3 = dedup(concat(pts1, pts2));
for(p = pts3) {
translate(p)
square(1, center = true);
}
![dedup](images/lib2x-dedup-1.JPG)
use <pixel/px_circle.scad>;
use <util/sort.scad>;
use <util/dedup.scad>;
pts1 = px_circle(20, filled = true);
pts2 = [for(p = px_circle(10, filled = true)) p + [20, 0]];
2020-03-19 15:53:38 +08:00
// From dotSCAD 2.3, you can use sort(concat(pts1, pts2), by = "vt") instead.
2020-03-19 09:14:42 +08:00
sorted_pts = sort(sort(concat(pts1, pts2), by = "x"), by = "y");
// simple union
pts3 = dedup(sorted_pts, sorted = true);
for(p = pts3) {
translate(p)
square(1, center = true);
}
![dedup](images/lib2x-dedup-2.JPG)