1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-01-17 22:28:16 +01:00

use built-in is_num

This commit is contained in:
Justin Lin 2019-06-11 08:39:57 +08:00
parent 9d63c4ffeb
commit d1ae9174a9
28 changed files with 21 additions and 47 deletions

View File

@ -44,7 +44,7 @@ function __br_corner(frags, b_ang, l1, l2, h, round_r) =
function __half_trapezium(length, h, round_r) =
let(
is_flt = __is_float(length),
is_flt = is_num(length),
l1 = is_flt ? length : length[0],
l2 = is_flt ? length : length[1],
frags = __frags(round_r),

View File

@ -1 +0,0 @@
function __is_float(value) = is_num(value);

View File

@ -6,7 +6,7 @@ function __shape_arc(radius, angle, width, width_mode = "LINE_CROSS") =
frags = __frags(radius),
a_step = 360 / frags,
half_a_step = a_step / 2,
angles = __is_float(angle) ? [0, angle] : angle,
angles = is_num(angle) ? [0, angle] : angle,
m = floor(angles[0] / a_step) + 1,
n = floor(angles[1] / a_step),
r_outer = radius + w_offset[0],

View File

@ -3,7 +3,7 @@ function __shape_pie(radius, angle) =
frags = __frags(radius),
a_step = 360 / frags,
leng = radius * cos(a_step / 2),
angles = __is_float(angle) ? [0:angle] : angle,
angles = is_num(angle) ? [0:angle] : angle,
m = floor(angles[0] / a_step) + 1,
n = floor(angles[1] / a_step),
edge_r_begin = leng / cos((m - 0.5) * a_step - angles[0]),

View File

@ -4,4 +4,4 @@ function __to_3_elems_ang_vect(a) =
leng == 2 ? [a[0], a[1], 0] : [a[0], 0, 0]
);
function __to_ang_vect(a) = __is_float(a) ? [0, 0, a] : __to_3_elems_ang_vect(a);
function __to_ang_vect(a) = is_num(a) ? [0, 0, a] : __to_3_elems_ang_vect(a);

View File

@ -9,7 +9,6 @@
**/
include <__private__/__angy_angz.scad>;
include <__private__/__is_float.scad>;
include <__private__/__to3d.scad>;
// Becuase of improving the performance, this module requires m_rotation.scad which doesn't require in dotSCAD 1.0.
@ -23,7 +22,7 @@ module along_with(points, angles, twist = 0, scale = 1.0, method = "AXIS_ANGLE")
angles_defined = angles != undef;
scale_step_vt = __is_float(scale) ?
scale_step_vt = is_num(scale) ?
scale_step() :
[
(scale[0] - 1) / leng_points_minus_one,

View File

@ -9,7 +9,6 @@
**/
include <__private__/__frags.scad>;
include <__private__/__is_float.scad>;
include <__private__/__ra_to_xy.scad>;
include <__private__/__edge_r.scad>;
include <__private__/__shape_arc.scad>;

View File

@ -9,7 +9,6 @@
**/
include <__private__/__frags.scad>;
include <__private__/__is_float.scad>;
include <__private__/__ra_to_xy.scad>;
include <__private__/__edge_r.scad>;
@ -17,7 +16,7 @@ function arc_path(radius, angle) =
let(
frags = __frags(radius),
a_step = 360 / frags,
angles = __is_float(angle) ? [0, angle] : angle,
angles = is_num(angle) ? [0, angle] : angle,
m = floor(angles[0] / a_step) + 1,
n = floor(angles[1] / a_step),
points = concat([__ra_to_xy(__edge_r_begin(radius, angles[0], a_step, m), angles[0])],

View File

@ -9,14 +9,13 @@
**/
include <__private__/__to3d.scad>;
include <__private__/__is_float.scad>;
function cross_sections(shape_pts, path_pts, angles, twist = 0, scale = 1.0) =
let(
len_path_pts_minus_one = len(path_pts) - 1,
sh_pts = len(shape_pts[0]) == 3 ? shape_pts : [for(p = shape_pts) __to3d(p)],
pth_pts = len(path_pts[0]) == 3 ? path_pts : [for(p = path_pts) __to3d(p)],
scale_step_vt = __is_float(scale) ?
scale_step_vt = is_num(scale) ?
[(scale - 1) / len_path_pts_minus_one, (scale - 1) / len_path_pts_minus_one] :
[(scale[0] - 1) / len_path_pts_minus_one, (scale[1] - 1) / len_path_pts_minus_one]
,

View File

@ -9,10 +9,9 @@
**/
include <__private__/__nearest_multiple_of_4.scad>;
include <__private__/__is_float.scad>;
module crystal_ball(radius, theta = 360, phi = 180) {
phis = __is_float(phi) ? [0, phi] : phi;
phis = is_num(phi) ? [0, phi] : phi;
frags = __frags(radius);

View File

@ -8,12 +8,11 @@
*
**/
include <__private__/__is_float.scad>;
include <__private__/__frags.scad>;
function helix(radius, levels, level_dist, vt_dir = "SPI_DOWN", rt_dir = "CT_CLK") =
let(
is_flt = __is_float(radius),
is_flt = is_num(radius),
r1 = is_flt ? radius : radius[0],
r2 = is_flt ? radius : radius[1],
init_r = vt_dir == "SPI_DOWN" ? r2 : r1,

View File

@ -8,7 +8,6 @@
*
**/
include <__private__/__is_float.scad>;
include <__private__/__frags.scad>;
module helix_extrude(shape_pts, radius, levels, level_dist,
@ -22,7 +21,7 @@ module helix_extrude(shape_pts, radius, levels, level_dist,
vt[leng - 1 - i]
];
is_flt = __is_float(radius);
is_flt = is_num(radius);
r1 = is_flt ? radius : radius[0];
r2 = is_flt ? radius : radius[1];

View File

@ -8,7 +8,6 @@
*
**/
include <__private__/__is_float.scad>;
include <__private__/__to_ang_vect.scad>;
function _q_rotation(a, v) =

View File

@ -8,15 +8,13 @@
*
**/
include <__private__/__is_float.scad>;
function _to_3_elems_scaling_vect(s) =
let(leng = len(s))
leng == 3 ? s : (
leng == 2 ? [s[0], s[1], 1] : [s[0], 1, 1]
);
function _to_scaling_vect(s) = __is_float(s) ? [s, s, s] : _to_3_elems_scaling_vect(s);
function _to_scaling_vect(s) = is_num(s) ? [s, s, s] : _to_3_elems_scaling_vect(s);
function m_scaling(s) =
let(v = _to_scaling_vect(s))

View File

@ -8,15 +8,13 @@
*
**/
include <__private__/__is_float.scad>;
function _to_3_elems_translation_vect(v) =
let(leng = len(v))
leng == 3 ? v : (
leng == 2 ? [v[0], v[1], 0] : [v[0], 0, 0]
);
function _to_translation_vect(v) = __is_float(v) ? [v, 0, 0] : _to_3_elems_translation_vect(v);
function _to_translation_vect(v) = is_num(v) ? [v, 0, 0] : _to_3_elems_translation_vect(v);
function m_translation(v) =
let(vt = _to_translation_vect(v))

View File

@ -8,7 +8,6 @@
*
**/
include <__private__/__is_float.scad>;
include <__private__/__to3d.scad>;
include <__private__/__angy_angz.scad>;
@ -41,7 +40,7 @@ module path_extrude(shape_pts, path_pts, triangles = "SOLID", twist = 0, scale =
let(s = (scale - 1) / len_path_pts_minus_one)
[s, s, s];
scale_step_vt = __is_float(scale) ?
scale_step_vt = is_num(scale) ?
scale_step() :
[
(scale[0] - 1) / len_path_pts_minus_one,
@ -166,7 +165,7 @@ module path_extrude(shape_pts, path_pts, triangles = "SOLID", twist = 0, scale =
}
module euler_angle_path_extrude() {
scale_step_vt = __is_float(scale) ?
scale_step_vt = is_num(scale) ?
[(scale - 1) / len_path_pts_minus_one, (scale - 1) / len_path_pts_minus_one] :
[(scale[0] - 1) / len_path_pts_minus_one, (scale[1] - 1) / len_path_pts_minus_one];

View File

@ -9,7 +9,6 @@
**/
include <__private__/__frags.scad>;
include <__private__/__is_float.scad>;
include <__private__/__ra_to_xy.scad>;
include <__private__/__shape_pie.scad>;

View File

@ -19,7 +19,7 @@ module ring_extrude(shape_pts, radius, angle = 360, twist = 0, scale = 1.0, tria
} else {
a_step = 360 / __frags(radius);
angles = __is_float(angle) ? [0, angle] : angle;
angles = is_num(angle) ? [0, angle] : angle;
m = floor(angles[0] / a_step) + 1;
n = floor(angles[1] / a_step);

View File

@ -10,7 +10,6 @@
include <__private__/__to2d.scad>;
include <__private__/__to3d.scad>;
include <__private__/__is_float.scad>;
include <__private__/__to_ang_vect.scad>;
function _q_rotate_p_3d(p, a, v) =

View File

@ -8,12 +8,11 @@
*
**/
include <__private__/__is_float.scad>;
include <__private__/__frags.scad>;
include <__private__/__nearest_multiple_of_4.scad>;
module rounded_cube(size, corner_r, center = false) {
is_flt = __is_float(size);
is_flt = is_num(size);
x = is_flt ? size : size[0];
y = is_flt ? size : size[1];
z = is_flt ? size : size[2];

View File

@ -8,7 +8,6 @@
*
**/
include <__private__/__is_float.scad>;
include <__private__/__frags.scad>;
include <__private__/__pie_for_rounding.scad>;
include <__private__/__half_trapezium.scad>;

View File

@ -9,11 +9,10 @@
**/
include <__private__/__frags.scad>;
include <__private__/__is_float.scad>;
module rounded_extrude(size, round_r, angle = 90, twist = 0, convexity = 10) {
is_flt = __is_float(size);
is_flt = is_num(size);
x = is_flt ? size : size[0];
y = is_flt ? size : size[1];

View File

@ -8,14 +8,13 @@
*
**/
include <__private__/__is_float.scad>;
include <__private__/__frags.scad>;
include <__private__/__pie_for_rounding.scad>;
include <__private__/__half_trapezium.scad>;
include <__private__/__trapezium.scad>;
module rounded_square(size, corner_r, center = false) {
is_flt = __is_float(size);
is_flt = is_num(size);
x = is_flt ? size : size[0];
y = is_flt ? size : size[1];

View File

@ -9,7 +9,6 @@
**/
include <__private__/__frags.scad>;
include <__private__/__is_float.scad>;
include <__private__/__ra_to_xy.scad>;
include <__private__/__shape_arc.scad>;
include <__private__/__edge_r.scad>

View File

@ -9,7 +9,6 @@
**/
include <__private__/__frags.scad>;
include <__private__/__is_float.scad>;
include <__private__/__ra_to_xy.scad>;
include <__private__/__shape_pie.scad>;

View File

@ -8,7 +8,6 @@
*
**/
include <__private__/__is_float.scad>;
include <__private__/__frags.scad>;
include <__private__/__pie_for_rounding.scad>;
include <__private__/__half_trapezium.scad>;
@ -16,7 +15,7 @@ include <__private__/__trapezium.scad>;
function shape_square(size, corner_r = 0) =
let(
is_flt = __is_float(size),
is_flt = is_num(size),
x = is_flt ? size : size[0],
y = is_flt ? size : size[1]
)

View File

@ -8,7 +8,6 @@
*
**/
include <__private__/__is_float.scad>;
include <__private__/__frags.scad>;
include <__private__/__pie_for_rounding.scad>;
include <__private__/__half_trapezium.scad>;

View File

@ -1,5 +1,3 @@
include <__private__/__is_float.scad>;
module fail(title, message) {
echo(
str(
@ -86,8 +84,8 @@ module assertEqualPoints(expected, actual, float_digits = 4) {
}
module assertEqual(expected, actual, float_digits = 4) {
r_expected = __is_float(expected) ? round_n(expected, float_digits) : expected;
r_actual = __is_float(actual) ? round_n(actual, float_digits) : actual;
r_expected = is_num(expected) ? round_n(expected, float_digits) : expected;
r_actual = is_num(actual) ? round_n(actual, float_digits) : actual;
if(r_expected != r_actual) {
fail(