mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-08-17 20:11:50 +02:00
refactored
This commit is contained in:
@@ -47,7 +47,7 @@ module line3d(p1, p2, thickness, p1Style = "CAP_CIRCLE", p2Style = "CAP_CIRCLE")
|
|||||||
module cap(p, style) {
|
module cap(p, style) {
|
||||||
if(style == "CAP_CIRCLE") {
|
if(style == "CAP_CIRCLE") {
|
||||||
cap_leng = r / 1.414;
|
cap_leng = r / 1.414;
|
||||||
cap_with(p)
|
cap_with(p) `
|
||||||
linear_extrude(cap_leng * 2, center = true)
|
linear_extrude(cap_leng * 2, center = true)
|
||||||
circle(r, $fn = frags);
|
circle(r, $fn = frags);
|
||||||
|
|
||||||
|
@@ -21,14 +21,19 @@ module fail(title, message) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function shift_to_int(point, digits) =
|
function round_n(number, float_digits = 4) =
|
||||||
let(pt = point * pow(10, digits))
|
let(n = pow(10, float_digits))
|
||||||
|
round(number * n) / n;
|
||||||
|
|
||||||
|
function mul_round_pt(point, n) =
|
||||||
|
let(pt = point * n)
|
||||||
len(pt) == 2 ?
|
len(pt) == 2 ?
|
||||||
[round(pt[0]), round(pt[1])] :
|
[round(pt[0]), round(pt[1])] :
|
||||||
[round(pt[0]), round(pt[1]), round(pt[2])];
|
[round(pt[0]), round(pt[1]), round(pt[2])];
|
||||||
|
|
||||||
function round_pts(points, float_digits) =
|
function round_pts(points, float_digits = 4) =
|
||||||
[for(pt = points) shift_to_int(pt, float_digits) / pow(10, float_digits)];
|
let(n = pow(10, float_digits))
|
||||||
|
[for(pt = points) mul_round_pt(pt, n) / n];
|
||||||
|
|
||||||
module assertEqualPoint(expected, actual, float_digits = 4) {
|
module assertEqualPoint(expected, actual, float_digits = 4) {
|
||||||
leng_expected = len(expected);
|
leng_expected = len(expected);
|
||||||
@@ -41,12 +46,14 @@ module assertEqualPoint(expected, actual, float_digits = 4) {
|
|||||||
", but: ", leng_actual)
|
", but: ", leng_actual)
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
shifted_expected = shift_to_int(
|
n = pow(10, float_digits);
|
||||||
expected, float_digits
|
|
||||||
|
shifted_expected = mul_round_pt(
|
||||||
|
expected, n
|
||||||
);
|
);
|
||||||
|
|
||||||
shifted_actual = shift_to_int(
|
shifted_actual = mul_round_pt(
|
||||||
actual, float_digits
|
actual, n
|
||||||
);
|
);
|
||||||
|
|
||||||
if(shifted_expected != shifted_actual) {
|
if(shifted_expected != shifted_actual) {
|
||||||
@@ -76,12 +83,15 @@ module assertEqualPoints(expected, actual, float_digits = 4) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module assertEqual(expected, actual) {
|
module assertEqual(expected, actual, float_digits = 4) {
|
||||||
if(expected != actual) {
|
r_expected = round_n(expected, float_digits);
|
||||||
|
r_actual = round_n(actual, float_digits);
|
||||||
|
|
||||||
|
if(r_expected != r_actual) {
|
||||||
fail(
|
fail(
|
||||||
"Equality",
|
"Equality",
|
||||||
str("expected: ", expected,
|
str("expected: ", r_expected,
|
||||||
", but: ", actual)
|
", but: ", r_actual)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -94,3 +104,11 @@ module assertTrue(truth) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module round_echo_pts(points, float_digits = 4) {
|
||||||
|
echo(round_pts(points, float_digits = 4));
|
||||||
|
}
|
||||||
|
|
||||||
|
module round_echo_n(number, float_digits = 4) {
|
||||||
|
echo(round_n(number, float_digits));
|
||||||
|
}
|
Reference in New Issue
Block a user