1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-08-07 07:16:36 +02:00

include scad

This commit is contained in:
Justin Lin
2020-01-28 09:44:36 +08:00
parent eb70c87117
commit 0390817c03
23 changed files with 70 additions and 315 deletions

View File

@@ -1,7 +1,6 @@
// 2D // 2D
include <test_rounded_square.scad>; include <test_rounded_square.scad>;
include <test_line2d.scad>; include <test_line2d.scad>;
include <test_polyline2d.scad>;
include <test_hull_polyline2d.scad>; include <test_hull_polyline2d.scad>;
include <test_hexagons.scad>; include <test_hexagons.scad>;
@@ -10,10 +9,8 @@ include <test_rounded_cube.scad>;
include <test_rounded_cylinder.scad>; include <test_rounded_cylinder.scad>;
include <test_crystal_ball.scad>; include <test_crystal_ball.scad>;
include <test_line3d.scad>; include <test_line3d.scad>;
include <test_polyline3d.scad>;
include <test_hull_polyline3d.scad>; include <test_hull_polyline3d.scad>;
include <test_function_grapher.scad>; include <test_function_grapher.scad>;
include <test_polysections.scad>;
// Transformation // Transformation
include <test_bend.scad>; include <test_bend.scad>;

View File

@@ -1,6 +1,6 @@
use <unittest.scad>; use <unittest.scad>;
use <circle_path.scad>; use <circle_path.scad>;
use <along_with.scad>; include <along_with.scad>;
module test_along_with_angles(angles, children) { module test_along_with_angles(angles, children) {
if(children == 1) { if(children == 1) {

File diff suppressed because one or more lines are too long

View File

@@ -1,5 +1,5 @@
use <unittest.scad>; use <unittest.scad>;
use <bend.scad>; include <bend.scad>;
module test_bend_tri_frag(points, angle) { module test_bend_tri_frag(points, angle) {
expected_points = [[0, 0], [0.1927, 1.9566], [0.3854, 0], [0, 0]]; expected_points = [[0, 0], [0.1927, 1.9566], [0.3854, 0], [0, 0]];

View File

@@ -1,5 +1,5 @@
use <unittest.scad>; use <unittest.scad>;
use <crystal_ball.scad>; include <crystal_ball.scad>;
module test_crystal_ball_pie(shape_pts) { module test_crystal_ball_pie(shape_pts) {
expected = [[0, 0], [5.1392, 2.9671], [4.8541, 3.5267], [3.5267, 4.8541], [2.9671, 5.1392]]; expected = [[0, 0], [5.1392, 2.9671], [4.8541, 3.5267], [3.5267, 4.8541], [2.9671, 5.1392]];

View File

@@ -1,5 +1,5 @@
use <unittest.scad>; use <unittest.scad>;
use <ellipse_extrude.scad>; include <ellipse_extrude.scad>;
module test_ellipse_extrude_fzc(child_fs, pre_zs, center_offset) { module test_ellipse_extrude_fzc(child_fs, pre_zs, center_offset) {
expected_fs = [1, 0.996917, 0.987688, 0.97237, 0.951057, 0.92388, 0.891007, 0.85264, 0.809017, 0.760406, 0.707107, 0.649448, 0.587785, 0.522499, 0.45399, 0.382683, 0.309017, 0.233445, 0.156434, 0.0784591, 0]; expected_fs = [1, 0.996917, 0.987688, 0.97237, 0.951057, 0.92388, 0.891007, 0.85264, 0.809017, 0.760406, 0.707107, 0.649448, 0.587785, 0.522499, 0.45399, 0.382683, 0.309017, 0.233445, 0.156434, 0.0784591, 0];

View File

@@ -1,5 +1,5 @@
use <unittest.scad>; use <unittest.scad>;
use <function_grapher.scad>; include <function_grapher.scad>;
module test_function_grapher_faces(points, faces) { module test_function_grapher_faces(points, faces) {
pts = [ pts = [

View File

@@ -1,6 +1,6 @@
use <unittest.scad>; use <unittest.scad>;
use <circle_path.scad>; use <circle_path.scad>;
use <golden_spiral_extrude.scad>; include <golden_spiral_extrude.scad>;
module test_golden_spiral_extrude(sections, triangles) { module test_golden_spiral_extrude(sections, triangles) {
if(triangles == "SOLID") { if(triangles == "SOLID") {

View File

@@ -1,5 +1,5 @@
use <unittest.scad>; use <unittest.scad>;
use <hexagons.scad>; include <hexagons.scad>;
module test_each_hexagon(hex_r, pts_all_lines) { module test_each_hexagon(hex_r, pts_all_lines) {
// ==== test_hexagons_lv2 ==== // ==== test_hexagons_lv2 ====

View File

@@ -1,5 +1,5 @@
use <unittest.scad>; use <unittest.scad>;
use <hull_polyline2d.scad>; include <hull_polyline2d.scad>;
module test_hull_polyline2d_line_segment(index, point1, point2, radius) { module test_hull_polyline2d_line_segment(index, point1, point2, radius) {
points = [[1, 2], [-5, -4], [-5, 3], [5, 5]]; points = [[1, 2], [-5, -4], [-5, 3], [5, 5]];

View File

@@ -1,5 +1,5 @@
use <unittest.scad>; use <unittest.scad>;
use <hull_polyline3d.scad>; include <hull_polyline3d.scad>;
module test_hull_polyline3d_line_segment(index, point1, point2, radius) { module test_hull_polyline3d_line_segment(index, point1, point2, radius) {
points = [ points = [

View File

@@ -1,16 +1,9 @@
use <unittest.scad>; use <unittest.scad>;
use <line2d.scad>; include <line2d.scad>;
module test_line2d() {
$fn = 24;
p1 = [0, 0];
p2 = [5, 0];
width = 1;
echo("==== test_line2d_cap_square ====");
module test_line2d_cap(point, style) { module test_line2d_cap(point, style) {
p1 = [0, 0];
p2 = [5, 0];
assert( assert(
(point == p1 && style == "CAP_SQUARE") || (point == p1 && style == "CAP_SQUARE") ||
(point == p2 && style == "CAP_SQUARE") (point == p2 && style == "CAP_SQUARE")
@@ -24,6 +17,14 @@ module test_line2d() {
assertEqualNum(24, frags); assertEqualNum(24, frags);
} }
module test_line2d() {
$fn = 24;
p1 = [0, 0];
p2 = [5, 0];
width = 1;
echo("==== test_line2d_cap_square ====");
line2d(p1 = p1, p2 = p2, width = width); line2d(p1 = p1, p2 = p2, width = width);
} }

View File

@@ -1,15 +1,11 @@
use <unittest.scad>; use <unittest.scad>;
use <line3d.scad>; include <line3d.scad>;
module test_line3d() { module test_line3d_butt(p, r, frags, length, angles) {
p1 = [0, 0, 0]; p1 = [0, 0, 0];
p2 = [10, 2, 10]; p2 = [10, 2, 10];
thickness = 1; thickness = 1;
fn = 24; fn = 24;
echo("==== test_line3d_default_caps ====");
module test_line3d_butt(p, r, frags, length, angles) {
assertEqualPoint(p1, p); assertEqualPoint(p1, p);
assertEqualNum(thickness / 2, r); assertEqualNum(thickness / 2, r);
assertEqualNum(fn, frags); assertEqualNum(fn, frags);
@@ -18,6 +14,10 @@ module test_line3d() {
} }
module test_line3d_cap(p, r, frags, cap_leng, angles) { module test_line3d_cap(p, r, frags, cap_leng, angles) {
p1 = [0, 0, 0];
p2 = [10, 2, 10];
thickness = 1;
fn = 24;
assert(p == p1 || p == p2); assert(p == p1 || p == p2);
assertEqualNum(thickness / 2, r); assertEqualNum(thickness / 2, r);
assertEqualNum(fn, frags); assertEqualNum(fn, frags);
@@ -25,6 +25,13 @@ module test_line3d() {
assertEqualPoint([0, 45.5618, 11.3099], angles); assertEqualPoint([0, 45.5618, 11.3099], angles);
} }
module test_line3d() {
p1 = [0, 0, 0];
p2 = [10, 2, 10];
thickness = 1;
fn = 24;
echo("==== test_line3d_default_caps ====");
line3d( line3d(
p1 = p1, p1 = p1,

View File

@@ -1,7 +1,7 @@
use <unittest.scad>; use <unittest.scad>;
use <shape_pentagram.scad>; use <shape_pentagram.scad>;
use <torus_knot.scad>; use <torus_knot.scad>;
use <path_extrude.scad>; include <path_extrude.scad>;
module test_path_extrude(sections, method) { module test_path_extrude(sections, method) {
if(method == "EULER_ANGLE") { if(method == "EULER_ANGLE") {

View File

@@ -1,74 +0,0 @@
use <unittest.scad>;
use <polyline2d.scad>;
module test_polyline2d() {
$fn = 24;
points = [[1, 2], [-5, -4], [-5, 3], [5, 5]];
line_width = 1;
leng_points = len(points);
module assertCorrectSegment(index, point1, point2, width) {
assertEqualPoint(points[index - 1], point1);
assertEqualPoint(points[index], point2);
assertEqualNum(line_width, width);
}
module assertCorrectCaps(startStyle, endStyle, index, p1Style, p2Style) {
function correctMiddleCaps(p1Style, p2Style) =
p1Style == "CAP_BUTT" && p2Style == "CAP_ROUND";
if(index == 1 && (p1Style != startStyle || p2Style != "CAP_ROUND")) {
fail(
"Wrong start caps",
str(
"expected: [", startStyle, ", \"CAP_ROUND\"]",
", but: ", [p1Style, p2Style]
)
);
}
if((1 < index && index < leng_points - 1) && !correctMiddleCaps(p1Style, p2Style)) {
fail(
"Wrong middle caps",
str(
"expected: [\"CAP_BUTT\", \"CAP_ROUND\"]",
", but: ", [p1Style, p2Style]
)
);
}
if(index == leng_points - 1 && (p1Style != "CAP_BUTT" || p2Style != endStyle)) {
fail(
"Wrong end caps",
str(
"expected: [\"CAP_BUTT\, ", endStyle, "]",
", but: ", [p1Style, p2Style]
)
);
}
}
// testcases
module test_polyline2d_cap_square() {
echo("==== test_polyline2d_cap_square ====");
module test_polyline2d_line_segment(index, point1, point2, width, p1Style, p2Style) {
assertCorrectSegment(index, point1, point2, width);
assertCorrectCaps(
"CAP_SQUARE", "CAP_SQUARE",
index, p1Style, p2Style
);
}
polyline2d(points = points, width = line_width);
}
test_polyline2d_cap_square();
}
test_polyline2d();

View File

@@ -1,87 +0,0 @@
use <unittest.scad>;
use <polyline3d.scad>;
module test_polyline3d() {
$fn = 24;
points = [
[1, 2, 1],
[-5, -4, 2],
[-5, 3, 3],
[5, 5, 4]
];
line_thickness = 1;
leng_points = len(points);
module assertCorrectSegment(expected, actual, thickness) {
assertEqualPoint(expected[0], actual[0]);
assertEqualPoint(expected[1], actual[1]);
assertEqualNum(line_thickness, thickness);
}
module assertCorrectCaps(leng_pts, startStyle, endStyle, index, p1Style, p2Style) {
function correctMiddleCaps(p1Style, p2Style) =
p1Style == "CAP_SPHERE" && p2Style == "CAP_BUTT";
if(index == 1 && (p1Style != startStyle || p2Style != "CAP_BUTT")) {
fail(
"Wrong start caps",
str(
"expected: [", startStyle, ", \"CAP_BUTT\"]",
", but: ", [p1Style, p2Style]
)
);
}
if((1 < index && index < leng_pts - 1) && !correctMiddleCaps(p1Style, p2Style)) {
fail(
"Wrong middle caps",
str(
"expected: [\"CAP_SPHERE\", \"CAP_BUTT\"]",
", but: ", [p1Style, p2Style]
)
);
}
if(index == leng_pts - 1 && (p1Style != "CAP_SPHERE" || p2Style != endStyle)) {
fail(
"Wrong end caps",
str(
"expected: [\"CAP_SPHERE\, ", endStyle, "]",
", but: ", [p1Style, p2Style]
)
);
}
}
// testcases
module test_polyline3d_cap_default() {
echo("==== test_polyline3d_cap_default ====");
module test_polyline3d_line3d_segment(index, point1, point2, thickness, p1Style, p2Style) {
assertCorrectSegment(
[points[index - 1], points[index]],
[point1, point2],
thickness
);
assertCorrectCaps(
leng_points,
"CAP_CIRCLE", "CAP_CIRCLE",
index, p1Style, p2Style
);
}
polyline3d(
points = points,
thickness = line_thickness,
$fn = 24
);
}
test_polyline3d_cap_default();
}
test_polyline3d();

File diff suppressed because one or more lines are too long

View File

@@ -1,5 +1,5 @@
use <unittest.scad>; use <unittest.scad>;
use <ring_extrude.scad>; include <ring_extrude.scad>;
module test_ring_extrude(sections, angle) { module test_ring_extrude(sections, angle) {
if(angle == 360) { if(angle == 360) {

View File

@@ -1,5 +1,5 @@
use <unittest.scad>; use <unittest.scad>;
use <rounded_cube.scad>; include <rounded_cube.scad>;
module test_rounded_edge_corner_center(corner_frags, corners, center_pts) { module test_rounded_edge_corner_center(corner_frags, corners, center_pts) {
size = 20; size = 20;

View File

@@ -1,12 +1,8 @@
use <unittest.scad>; use <unittest.scad>;
use <rounded_cylinder.scad>; include <rounded_cylinder.scad>;
module test_rounded_cylinder() {
echo("==== test_rounded_cylinder ====");
h = 25;
module test_center_half_trapezium(center_pt, shape_pts) { module test_center_half_trapezium(center_pt, shape_pts) {
h = 25;
assertEqualPoint([0, 0, h / 2], center_pt); assertEqualPoint([0, 0, h / 2], center_pt);
expected_shape = [[0, -12.5], [15.5689, -12.5], [17.424, -11.8577], [18.4847, -10.2057], [18.3543, -8.3858], [10.7543, 10.6142], [9.469, 12.098], [7.9689, 12.5], [0, 12.5]]; expected_shape = [[0, -12.5], [15.5689, -12.5], [17.424, -11.8577], [18.4847, -10.2057], [18.3543, -8.3858], [10.7543, 10.6142], [9.469, 12.098], [7.9689, 12.5], [0, 12.5]];
@@ -14,6 +10,11 @@ module test_rounded_cylinder() {
assertEqualPoints(expected_shape, shape_pts); assertEqualPoints(expected_shape, shape_pts);
} }
module test_rounded_cylinder() {
echo("==== test_rounded_cylinder ====");
h = 25;
rounded_cylinder( rounded_cylinder(
radius = [20, 10], radius = [20, 10],
h = h, h = h,

View File

@@ -1,5 +1,5 @@
use <unittest.scad>; use <unittest.scad>;
use <rounded_square.scad>; include <rounded_square.scad>;
module test_rounded_square(position, points) { module test_rounded_square(position, points) {
assertEqualPoint([25, 25], position); assertEqualPoint([25, 25], position);

File diff suppressed because one or more lines are too long

View File

@@ -1,5 +1,5 @@
use <unittest.scad>; use <unittest.scad>;
use <stereographic_extrude.scad>; include <stereographic_extrude.scad>;
module test_stereographic_extrude_rs(outer_sphere_r, inner_sphere_r) { module test_stereographic_extrude_rs(outer_sphere_r, inner_sphere_r) {
assertEqualPoint([16.6667, 15.0756], [outer_sphere_r, inner_sphere_r]); assertEqualPoint([16.6667, 15.0756], [outer_sphere_r, inner_sphere_r]);