fix tests

This commit is contained in:
Adrian Mariano 2021-09-11 19:35:05 -04:00
parent 2494de9368
commit 4a463fd8b9
4 changed files with 12 additions and 146 deletions

View File

@ -7,7 +7,6 @@ include <../std.scad>
test_point_on_segment();
test_point_left_of_line2d();
test_collinear();
test_point_line_distance();
test_segment_distance();
@ -31,7 +30,6 @@ test_point_plane_distance();
test__general_plane_line_intersection();
test_plane_line_angle();
test_normalize_plane();
test_plane_line_intersection();
test_polygon_line_intersection();
test_plane_intersection();
@ -90,13 +88,13 @@ function info_str(list,i=0,string=chr(10)) =
: info_str(list,i+1,str(string,str(list[i][0],_valstr(list[i][1]),chr(10))));
module test_normalize_plane(){
module test__normalize_plane(){
plane = rands(-5,5,4,seed=333)+[10,0,0,0];
plane2 = normalize_plane(plane);
plane2 = _normalize_plane(plane);
assert_approx(norm(point3d(plane2)),1);
assert_approx(plane*plane2[3],plane2*plane[3]);
}
*test_normalize_plane();
test__normalize_plane();
module test_plane_line_intersection(){
line = [rands(-1,1,3,seed=74),rands(-1,1,3,seed=99)+[2,0,0]];
@ -148,7 +146,7 @@ module test_plane_intersection(){
module test_plane_offset(){
plane = rands(-1,1,4)+[2,0,0,0]; // a valid plane
info = info_str([["plane = ",plane]]);
assert_approx(plane_offset(plane), normalize_plane(plane)[3],info);
assert_approx(plane_offset(plane), _normalize_plane(plane)[3],info);
assert_approx(plane_offset([1,1,1,1]), 1/sqrt(3),info);
}
*test_plane_offset();
@ -301,12 +299,12 @@ module test_point_on_segment() {
*test_point_on_segment();
module test_point_left_of_line2d() {
assert(point_left_of_line2d([ -3, 0], [[-10,-10], [10,10]]) > 0);
assert(point_left_of_line2d([ 0, 0], [[-10,-10], [10,10]]) == 0);
assert(point_left_of_line2d([ 3, 0], [[-10,-10], [10,10]]) < 0);
module test__point_left_of_line2d() {
assert(_point_left_of_line2d([ -3, 0], [[-10,-10], [10,10]]) > 0);
assert(_point_left_of_line2d([ 0, 0], [[-10,-10], [10,10]]) == 0);
assert(_point_left_of_line2d([ 3, 0], [[-10,-10], [10,10]]) < 0);
}
*test_point_left_of_line2d();
test__point_left_of_line2d();
module test_collinear() {
assert(collinear([-10,-10], [-15, -16], [10,10]) == false);

View File

@ -17,8 +17,8 @@ module test_circle() {
for (pt = circle(r=100)) {
assert(approx(norm(pt),100));
}
assert(polygon_is_clockwise(circle(d=200)));
assert(polygon_is_clockwise(circle(r=100)));
assert(is_polygon_clockwise(circle(d=200)));
assert(is_polygon_clockwise(circle(r=100)));
assert(len(circle(d=100,$fn=6)) == 6);
assert(len(circle(d=100,$fn=36)) == 36);
}

View File

@ -217,32 +217,6 @@ module test_zflip() {
test_zflip();
module test_xyflip() {
assert_approx(xyflip(), [[0,1,0,0],[1,0,0,0],[0,0,1,0],[0,0,0,1]]);
assert_approx(xyflip(p=[1,2,3]), [2,1,3]);
// Verify that module at least doesn't crash.
xyflip() nil();
}
test_xyflip();
module test_xzflip() {
assert_approx(xzflip(), [[0,0,1,0],[0,1,0,0],[1,0,0,0],[0,0,0,1]]);
assert_approx(xzflip(p=[1,2,3]), [3,2,1]);
// Verify that module at least doesn't crash.
xzflip() nil();
}
test_xzflip();
module test_yzflip() {
assert_approx(yzflip(), [[1,0,0,0],[0,0,1,0],[0,1,0,0],[0,0,0,1]]);
assert_approx(yzflip(p=[1,2,3]), [1,3,2]);
// Verify that module at least doesn't crash.
yzflip() nil();
}
test_yzflip();
module test_rot() {
pts2d = 50 * [for (x=[-1,0,1],y=[-1,0,1]) [x,y]];
@ -403,67 +377,10 @@ module test_zrot() {
test_zrot();
module test_xyrot() {
vals = [-270,-135,-90,45,0,30,45,90,135,147,180];
path = path3d(pentagon(d=100), 50);
for (a=vals) {
m = affine3d_rot_by_axis(RIGHT+BACK,a);
assert_approx(xyrot(a), m);
assert_approx(xyrot(a, p=path[0]), apply(m, path[0]));
assert_approx(xyrot(a, p=path), apply(m, path));
// Verify that module at least doesn't crash.
xyrot(a) nil();
}
}
test_xyrot();
module test_xzrot() {
vals = [-270,-135,-90,45,0,30,45,90,135,147,180];
path = path3d(pentagon(d=100), 50);
for (a=vals) {
m = affine3d_rot_by_axis(RIGHT+UP,a);
assert_approx(xzrot(a), m);
assert_approx(xzrot(a, p=path[0]), apply(m, path[0]));
assert_approx(xzrot(a, p=path), apply(m, path));
// Verify that module at least doesn't crash.
xzrot(a) nil();
}
}
test_xzrot();
module test_yzrot() {
vals = [-270,-135,-90,45,0,30,45,90,135,147,180];
path = path3d(pentagon(d=100), 50);
for (a=vals) {
m = affine3d_rot_by_axis(BACK+UP,a);
assert_approx(yzrot(a), m);
assert_approx(yzrot(a, p=path[0]), apply(m, path[0]));
assert_approx(yzrot(a, p=path), apply(m, path));
// Verify that module at least doesn't crash.
yzrot(a) nil();
}
}
test_yzrot();
module test_xyzrot() {
vals = [-270,-135,-90,45,0,30,45,90,135,147,180];
path = path3d(pentagon(d=100), 50);
for (a=vals) {
m = affine3d_rot_by_axis(RIGHT+BACK+UP,a);
assert_approx(xyzrot(a), m);
assert_approx(xyzrot(a, p=path[0]), apply(m, path[0]));
assert_approx(xyzrot(a, p=path), apply(m, path));
// Verify that module at least doesn't crash.
xyzrot(a) nil();
}
}
test_xyzrot();
module test_frame_map() {
assert(approx(frame_map(x=[1,1,0], y=[-1,1,0]), affine3d_zrot(45)));
assert(approx(frame_map(x=[0,1,0], y=[0,0,1]), rot(v=[1,1,1],a=120)));
}
test_frame_map();

View File

@ -773,35 +773,6 @@ function _split_polygon_at_y(poly, y) =
) out;
function _split_polygon_at_z(poly, z) =
let(
zs = subindex(poly,2)
) (min(zs) >= z || max(zs) <= z)? [poly] :
let(
poly2 = [
for (p = pair(poly,true)) each [
p[0],
if(
(p[0].z < z && p[1].z > z) ||
(p[1].z < z && p[0].z > z)
) let(
u = (z - p[0].z) / (p[1].z - p[0].z)
) [
u*(p[1].x-p[0].x)+p[0].x,
u*(p[1].y-p[0].y)+p[0].y,
z, // Important for later exact match tests
]
]
],
out1 = [for (p = poly2) if(p.z <= z) p],
out2 = [for (p = poly2) if(p.z >= z) p],
out3 = [
if (len(out1)>=3) each split_path_at_self_crossings(close_path(out1), closed=false),
if (len(out2)>=3) each split_path_at_self_crossings(close_path(out2), closed=false),
],
out = [for (p=out3) if (len(p) > 2) cleanup_path(p)]
) out;
/// Function: _split_polygons_at_each_x()
// Usage:
@ -845,26 +816,6 @@ function _split_polygons_at_each_y(polys, ys, _i=0) =
);
/// Internal Function: _split_polygons_at_each_z()
// Usage:
// splitpolys = split_polygons_at_each_z(polys, zs);
/// Topics: Geometry, Polygons, Intersections
// Description:
// Given a list of 3D polygons, splits all of them wherever they cross any Z value given in `zs`.
// Arguments:
// polys = A list of 3D polygons to split.
// zs = A list of scalar Z values to split at.
function split_polygons_at_each_z(polys, zs, _i=0) =
assert( [for (poly=polys) if (!is_path(poly,3)) 1] == [], "Expects list of 3D paths.")
assert( is_vector(zs), "The split value list should contain only numbers." )
_i>=len(zs)? polys :
split_polygons_at_each_z(
[
for (poly = polys)
each _split_polygon_at_z(poly, zs[_i])
], zs, _i=_i+1
);
// Function&Module: vnf_validate()
// Usage: As Function