1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-01-17 06:08:31 +01:00

add count

This commit is contained in:
Justin Lin 2022-03-18 08:07:46 +08:00
parent 2a7c38915b
commit 18991671f8
4 changed files with 14 additions and 1 deletions

View File

@ -12,3 +12,4 @@ new:
- polyline_join: doc multi-childs
- mz_squarewalls, mz_hexwalls
- mz_hamiltonian supports init_cells
- util/count

1
src/util/count.scad Normal file
View File

@ -0,0 +1 @@
function count(lt, test) = len([for(elem = lt) if(test(elem)) undef]);

View File

@ -75,6 +75,7 @@ include <util/test_every.scad>;
include <util/test_shuffle.scad>;
include <util/test_find_index.scad>;
include <util/test_spherical_coordinate.scad>;
include <util/test_count.scad>;
include <util/set/test_hashset.scad>;
include <util/map/test_hashmap.scad>;

10
test/util/test_count.scad Normal file
View File

@ -0,0 +1,10 @@
use <util/count.scad>;
module test_count() {
echo("==== test_count ====");
points = [[7, 2, 2], [1, 1, 2], [3, 4, 2], [3, 4, 2], [1, 2, 3]];
assert(count(points, function(p) norm(p) > 5) == 3);
}
test_count();