mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-09-01 02:33:00 +02:00
add the eq
parameter
This commit is contained in:
Binary file not shown.
Before Width: | Height: | Size: 27 KiB |
Binary file not shown.
Before Width: | Height: | Size: 32 KiB |
@@ -1,45 +0,0 @@
|
||||
# dedup
|
||||
|
||||
Eliminating duplicate copies of repeating vectors. If `lt` has a large number of 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 index to the first one) and `dedup` will use binary search internally.
|
||||
|
||||
## Examples
|
||||
|
||||
use <voxel/vx_circle.scad>;
|
||||
use <util/dedup.scad>;
|
||||
|
||||
pts1 = vx_circle(10, filled = true);
|
||||
pts2 = [for(p = vx_circle(5, filled = true)) p + [10, 0]];
|
||||
|
||||
// simple union
|
||||
pts3 = dedup(concat(pts1, pts2));
|
||||
for(p = pts3) {
|
||||
translate(p)
|
||||
square(1, center = true);
|
||||
}
|
||||
|
||||

|
||||
|
||||
use <voxel/vx_circle.scad>;
|
||||
use <util/sort.scad>;
|
||||
use <util/dedup.scad>;
|
||||
|
||||
pts1 = vx_circle(20, filled = true);
|
||||
pts2 = [for(p = vx_circle(10, filled = true)) p + [20, 0]];
|
||||
|
||||
sorted_pts = sort(concat(pts1, pts2), by = "vt");
|
||||
|
||||
// simple union
|
||||
pts3 = dedup(sorted_pts, sorted = true);
|
||||
for(p = pts3) {
|
||||
translate(p)
|
||||
square(1, center = true);
|
||||
}
|
||||
|
||||

|
36
docs/lib3x-dedup.md
Normal file
36
docs/lib3x-dedup.md
Normal file
@@ -0,0 +1,36 @@
|
||||
# dedup
|
||||
|
||||
Eliminating duplicate copies of repeating vectors. If `lt` has a large number of 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 index to the first one) and `dedup` will use binary search internally.
|
||||
- `eq` : A equality function. If it's ignored, use `==` to compare elements. **Since: ** 3.0
|
||||
|
||||
## Examples
|
||||
|
||||
eq = function(e1, e2) e1[0] == e2[0] && e1[1] == e2[1] && e1[2] == e2[2];
|
||||
|
||||
points = [[1, 1, 2], [3, 4, 2], [7, 2, 2], [3, 4, 2], [1, 2, 3]];
|
||||
assert(
|
||||
dedup([[1, 1, 2], [3, 4, 2], [7, 2, 2], [3, 4, 2], [1, 2, 3]])
|
||||
== [[1, 1, 2], [3, 4, 2], [7, 2, 2], [1, 2, 3]]
|
||||
);
|
||||
|
||||
assert(
|
||||
dedup([[1, 1, 2], [3, 4, 2], [7, 2, 2], [3, 4, 2], [1, 2, 3]], eq = eq)
|
||||
== [[1, 1, 2], [3, 4, 2], [7, 2, 2], [1, 2, 3]]
|
||||
);
|
||||
|
||||
sorted = sort([[1, 1, 2], [3, 4, 2], [7, 2, 2], [3, 4, 2], [1, 2, 3]]);
|
||||
|
||||
assert(
|
||||
dedup(sorted, sorted = true) == [[1, 1, 2], [1, 2, 3], [3, 4, 2], [7, 2, 2]]
|
||||
);
|
||||
|
||||
assert(
|
||||
dedup(sorted, sorted = true, eq = eq) == [[1, 1, 2], [1, 2, 3], [3, 4, 2], [7, 2, 2]]
|
||||
);
|
Reference in New Issue
Block a user