mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-08-12 09:44:16 +02:00
refactor
This commit is contained in:
@@ -49,7 +49,7 @@ module along_with(points, angles, twist = 0, scale = 1.0, method = "AXIS_ANGLE")
|
||||
let(
|
||||
vt0 = pts[i] - pts[i - 1],
|
||||
vt1 = pts[i + 1] - pts[i],
|
||||
a = acos((vt0 * vt1) / (norm(vt0) * norm(vt1))),
|
||||
a = acos((vt0 * vt1) / sqrt((vt0 * vt0) * (vt1 * vt1))),
|
||||
v = cross(vt0, vt1)
|
||||
)
|
||||
[a, v]
|
||||
|
@@ -23,8 +23,8 @@ function _tri_circumcircle(shape_pts) =
|
||||
)
|
||||
det == 0 ? undef :
|
||||
let(
|
||||
x = (d1 * v0[1] - d0 * v1[1]) / det,
|
||||
y = (d0 * v1[0] - d1 * v0[0]) / det,
|
||||
x = (d1 * v0.y - d0 * v1.y) / det,
|
||||
y = (d0 * v1.x - d1 * v0.x) / det,
|
||||
center = [x, y],
|
||||
v = p0 - center
|
||||
)
|
||||
@@ -179,10 +179,9 @@ function delaunayBadTriangles(d, p, _indices_hash) =
|
||||
function inCircumcircle(t, p, circles, _indices_hash) =
|
||||
let(
|
||||
c = hashmap_get(circles, t, hash = _indices_hash),
|
||||
ct = cc_center(c),
|
||||
rr = (ct[0] - p[0]) ^ 2 + (ct[1] - p[1]) ^ 2
|
||||
v = cc_center(c) - p
|
||||
)
|
||||
rr <= cc_rr(c);
|
||||
v * v <= cc_rr(c);
|
||||
|
||||
function delaunayBoundaries(d, badTriangles, _indices_hash) =
|
||||
let(
|
||||
|
@@ -14,13 +14,7 @@ function _triangulate_snipable(shape_pts, u, v, w, n, indices, epsilon = 0.0001)
|
||||
a = shape_pts[indices[u]],
|
||||
b = shape_pts[indices[v]],
|
||||
c = shape_pts[indices[w]],
|
||||
ax = a[0],
|
||||
ay = a[1],
|
||||
bx = b[0],
|
||||
by = b[1],
|
||||
cx = c[0],
|
||||
cy = c[1],
|
||||
determinant = cross([bx - ax, by - ay], [cx - ax, cy - ay])
|
||||
determinant = cross([b.x - a.x, b.y - a.y], [c.x - a.x, c.y - a.y])
|
||||
)
|
||||
epsilon > determinant ?
|
||||
false : _triangulate_snipable_sub(shape_pts, n, u, v, w, a, b, c, indices);
|
||||
@@ -35,9 +29,7 @@ function _triangulate_snipable_sub(shape_pts, n, u, v, w, a, b, c, indices, p =
|
||||
|
||||
// remove the elem at idx v from indices
|
||||
function _triangulate_remove_v(indices, v, num_of_vertices) =
|
||||
let(
|
||||
nv_minuns_one = num_of_vertices - 1
|
||||
)
|
||||
let(nv_minuns_one = num_of_vertices - 1)
|
||||
v == 0 ? [for(i = 1; i <= nv_minuns_one; i = i + 1) indices[i]] : (
|
||||
v == nv_minuns_one ? [for(i = 0; i < v; i = i + 1) indices[i]] : concat(
|
||||
[for(i = 0; i < v; i = i + 1) indices[i]],
|
||||
|
@@ -20,6 +20,6 @@ function tri_circumcenter(shape_pts) =
|
||||
det = -cross(v0 , v1)
|
||||
)
|
||||
det == 0 ? undef : [
|
||||
(d1 * v0[1] - d0 * v1[1]) / det,
|
||||
(d0 * v1[0] - d1 * v0[0]) / det
|
||||
(d1 * v0.y - d0 * v1.y) / det,
|
||||
(d0 * v1.x - d1 * v0.x) / det
|
||||
];
|
@@ -24,8 +24,8 @@ function tri_delaunay(points, ret = "TRI_INDICES") =
|
||||
max_y = max(ys),
|
||||
min_y = min(ys),
|
||||
center = [max_x + min_x, max_y + min_y] / 2,
|
||||
width = abs(max_x - center[0]) * 4,
|
||||
height = abs(max_y - center[1]) * 4,
|
||||
width = abs(max_x - center.x) * 4,
|
||||
height = abs(max_y - center.y) * 4,
|
||||
leng_pts = len(points),
|
||||
d = _tri_delaunay(
|
||||
delaunay_init(center, width, height, leng_pts, _indices_hash),
|
||||
|
@@ -10,4 +10,4 @@
|
||||
|
||||
use <../__comm__/__angy_angz.scad>;
|
||||
|
||||
function polar_coordinate(point) = [norm(point), atan2(point[1], point[0])]; // r, theta
|
||||
function polar_coordinate(point) = [norm(point), atan2(point.y, point.x)]; // r, theta
|
@@ -12,6 +12,6 @@ function spherical_coordinate(point) =
|
||||
// mathematics [r, theta, phi]
|
||||
[
|
||||
norm(point),
|
||||
atan2(point[1], point[0]),
|
||||
atan2(sqrt(point[0]^2 + point[1]^2), point[2])
|
||||
atan2(point.y, point.x),
|
||||
atan2(sqrt(point.x ^ 2 + point.y ^ 2), point.z)
|
||||
];
|
||||
|
@@ -8,4 +8,6 @@
|
||||
*
|
||||
**/
|
||||
|
||||
function sum(lt) = [for(i = [0:len(lt) - 1]) 1] * lt;
|
||||
function sum(lt) =
|
||||
let(leng = len(lt))
|
||||
[for(i = 0; i < leng; i = i + 1) 1] * lt;
|
@@ -26,7 +26,7 @@ _vx_contour_nxt_offset = [
|
||||
];
|
||||
function _vx_contour_travel(pts, p, fst) =
|
||||
let(
|
||||
dir_i = _vx_contour_dir(_vx_contour_corner_value(pts, p[0], p[1])),
|
||||
dir_i = _vx_contour_dir(_vx_contour_corner_value(pts, p.x, p.y)),
|
||||
nxt_p = p + _vx_contour_nxt_offset[dir_i]
|
||||
)
|
||||
nxt_p == fst ? [p] : [p, each _vx_contour_travel(pts, nxt_p, fst)];
|
||||
|
@@ -1,20 +1,18 @@
|
||||
function _vx_cylinder_vx_circle(radius, filled, thickness) =
|
||||
let(range = [-radius: radius - 1])
|
||||
filled ? [
|
||||
for(y = range)
|
||||
for(x = range)
|
||||
for(y = range, x = range)
|
||||
let(v = [x, y])
|
||||
if(norm(v) < radius) v
|
||||
] :
|
||||
let(ishell = radius * radius - 2 * thickness * radius)
|
||||
let(ishell = radius ^ 2 - 2 * thickness * radius)
|
||||
[
|
||||
for(y = range)
|
||||
for(x = range)
|
||||
for(y = range, x = range)
|
||||
let(
|
||||
v = [x, y],
|
||||
leng = norm(v)
|
||||
)
|
||||
if(leng < radius && (leng * leng) > ishell) v
|
||||
if(leng < radius && (leng ^ 2) > ishell) v
|
||||
];
|
||||
|
||||
function _vx_cylinder_diff_r(r, h, filled, thickness) =
|
||||
@@ -29,7 +27,7 @@ function _vx_cylinder_diff_r(r, h, filled, thickness) =
|
||||
let(r = round(r1 + dr * i))
|
||||
each [
|
||||
for(pt = _vx_cylinder_vx_circle(r, filled, thickness))
|
||||
[pt[0], pt[1], i]
|
||||
[pt.x, pt.y, i]
|
||||
]
|
||||
];
|
||||
|
||||
@@ -39,7 +37,7 @@ function _vx_cylinder_same_r(r, h, filled, thickness) =
|
||||
for(i = 0; i < h; i = i + 1)
|
||||
each [
|
||||
for(pt = c)
|
||||
[pt[0], pt[1], i]
|
||||
[pt.x, pt.y, i]
|
||||
]
|
||||
];
|
||||
|
||||
|
@@ -12,54 +12,36 @@ function _vx_line_xdominant_zd(zd, ax, az) = (zd >= 0 ? zd - ax : zd) + az;
|
||||
|
||||
function _vx_line_xdominant(start, end, a, s) =
|
||||
let(
|
||||
x = start[0],
|
||||
y = start[1],
|
||||
z = start[2],
|
||||
ax = a[0],
|
||||
ay = a[1],
|
||||
az = a[2],
|
||||
sx = s[0],
|
||||
sy = s[1],
|
||||
sz = s[2],
|
||||
shrx = floor(ax / 2),
|
||||
yd = ay - shrx,
|
||||
zd = az - shrx,
|
||||
endx = end[0]
|
||||
shrx = floor(a.x / 2),
|
||||
yd = a.y - shrx,
|
||||
zd = a.z - shrx
|
||||
)
|
||||
[
|
||||
start,
|
||||
each _vx_line_xdominant_sub(
|
||||
x + sx,
|
||||
_vx_line_xdominant_y(y, yd, sy),
|
||||
_vx_line_xdominant_z(z, zd, sz),
|
||||
endx,
|
||||
start.x + s.x,
|
||||
_vx_line_xdominant_y(start.y, yd, s.y),
|
||||
_vx_line_xdominant_z(start.z, zd, s.z),
|
||||
end.x,
|
||||
a,
|
||||
s,
|
||||
_vx_line_xdominant_yd(yd, ax, ay),
|
||||
_vx_line_xdominant_zd(zd, ax, az)
|
||||
_vx_line_xdominant_yd(yd, a.x, a.y),
|
||||
_vx_line_xdominant_zd(zd, a.x, a.z)
|
||||
)
|
||||
];
|
||||
|
||||
function _vx_line_xdominant_sub(x, y, z, endx, a, s, yd, zd) =
|
||||
let(
|
||||
ax = a[0],
|
||||
ay = a[1],
|
||||
az = a[2],
|
||||
sx = s[0],
|
||||
sy = s[1],
|
||||
sz = s[2]
|
||||
)
|
||||
x == endx ? [] : [
|
||||
[x, y, z],
|
||||
each _vx_line_xdominant_sub(
|
||||
x + sx,
|
||||
_vx_line_xdominant_y(y, yd, sy),
|
||||
_vx_line_xdominant_z(z, zd, sz),
|
||||
x + s.x,
|
||||
_vx_line_xdominant_y(y, yd, s.y),
|
||||
_vx_line_xdominant_z(z, zd, s.z),
|
||||
endx,
|
||||
a,
|
||||
s,
|
||||
_vx_line_xdominant_yd(yd, ax, ay),
|
||||
_vx_line_xdominant_zd(zd, ax, az)
|
||||
_vx_line_xdominant_yd(yd, a.x, a.y),
|
||||
_vx_line_xdominant_zd(zd, a.x, a.z)
|
||||
)
|
||||
];
|
||||
|
||||
@@ -71,54 +53,36 @@ function _vx_line_ydominant_zd(zd, ay, az) = (zd >= 0 ? zd - ay : zd) + az;
|
||||
|
||||
function _vx_line_ydominant(start, end, a, s) =
|
||||
let(
|
||||
x = start[0],
|
||||
y = start[1],
|
||||
z = start[2],
|
||||
ax = a[0],
|
||||
ay = a[1],
|
||||
az = a[2],
|
||||
sx = s[0],
|
||||
sy = s[1],
|
||||
sz = s[2],
|
||||
shry = floor(ay / 2),
|
||||
xd = ax - shry,
|
||||
zd = az - shry,
|
||||
endy = end[1]
|
||||
shry = floor(a.y / 2),
|
||||
xd = a.x - shry,
|
||||
zd = a.z - shry
|
||||
)
|
||||
[
|
||||
start,
|
||||
each _vx_line_ydominant_sub(
|
||||
_vx_line_ydominant_x(x, xd, sx),
|
||||
y + sy,
|
||||
_vx_line_ydominant_z(z, zd, sz),
|
||||
endy,
|
||||
_vx_line_ydominant_x(start.x, xd, s.x),
|
||||
start.y + s.y,
|
||||
_vx_line_ydominant_z(start.z, zd, s.z),
|
||||
end.y,
|
||||
a,
|
||||
s,
|
||||
_vx_line_ydominant_xd(xd, ax, ay),
|
||||
_vx_line_ydominant_zd(zd, ay, az)
|
||||
_vx_line_ydominant_xd(xd, a.x, a.y),
|
||||
_vx_line_ydominant_zd(zd, a.y, a.z)
|
||||
)
|
||||
];
|
||||
|
||||
function _vx_line_ydominant_sub(x, y, z, endy, a, s, xd, zd) =
|
||||
let(
|
||||
ax = a[0],
|
||||
ay = a[1],
|
||||
az = a[2],
|
||||
sx = s[0],
|
||||
sy = s[1],
|
||||
sz = s[2]
|
||||
)
|
||||
y == endy ? [] : [
|
||||
[x, y, z],
|
||||
each _vx_line_ydominant_sub(
|
||||
_vx_line_ydominant_x(x, xd, sx),
|
||||
y + sy,
|
||||
_vx_line_ydominant_z(z, zd, sz),
|
||||
_vx_line_ydominant_x(x, xd, s.x),
|
||||
y + s.y,
|
||||
_vx_line_ydominant_z(z, zd, s.z),
|
||||
endy,
|
||||
a,
|
||||
s,
|
||||
_vx_line_ydominant_xd(xd, ax, ay),
|
||||
_vx_line_ydominant_zd(zd, ay, az)
|
||||
_vx_line_ydominant_xd(xd, a.x, a.y),
|
||||
_vx_line_ydominant_zd(zd, a.y, a.z)
|
||||
)
|
||||
];
|
||||
|
||||
@@ -131,54 +95,36 @@ function _vx_line_zdominant_yd(yd, ay, az) = (yd >= 0 ? yd - az : yd) + ay;
|
||||
|
||||
function _vx_line_zdominant(start, end, a, s) =
|
||||
let(
|
||||
x = start[0],
|
||||
y = start[1],
|
||||
z = start[2],
|
||||
ax = a[0],
|
||||
ay = a[1],
|
||||
az = a[2],
|
||||
sx = s[0],
|
||||
sy = s[1],
|
||||
sz = s[2],
|
||||
shrz = floor(az / 2),
|
||||
xd = ax - shrz,
|
||||
yd = ay - shrz,
|
||||
endz = end[2]
|
||||
shrz = floor(a.z / 2),
|
||||
xd = a.x - shrz,
|
||||
yd = a.y - shrz
|
||||
)
|
||||
[
|
||||
start,
|
||||
each _vx_line_zdominant_sub(
|
||||
_vx_line_zdominant_x(x, xd, sx),
|
||||
_vx_line_zdominant_y(y, yd, sy),
|
||||
z + sz,
|
||||
endz,
|
||||
_vx_line_zdominant_x(start.x, xd, s.x),
|
||||
_vx_line_zdominant_y(start.y, yd, s.y),
|
||||
start.z + s.z,
|
||||
end.z,
|
||||
a,
|
||||
s,
|
||||
_vx_line_zdominant_xd(xd, ax, az),
|
||||
_vx_line_zdominant_yd(yd, ay, az)
|
||||
_vx_line_zdominant_xd(xd, a.x, a.z),
|
||||
_vx_line_zdominant_yd(yd, a.y, a.z)
|
||||
)
|
||||
];
|
||||
|
||||
function _vx_line_zdominant_sub(x, y, z, endz, a, s, xd, yd) =
|
||||
let(
|
||||
ax = a[0],
|
||||
ay = a[1],
|
||||
az = a[2],
|
||||
sx = s[0],
|
||||
sy = s[1],
|
||||
sz = s[2]
|
||||
)
|
||||
z == endz ? [] : [
|
||||
[x, y, z],
|
||||
each _vx_line_zdominant_sub(
|
||||
_vx_line_zdominant_x(x, xd, sx),
|
||||
_vx_line_zdominant_y(y, yd, sy),
|
||||
z + sz,
|
||||
_vx_line_zdominant_x(x, xd, s.x),
|
||||
_vx_line_zdominant_y(y, yd, s.y),
|
||||
z + s.z,
|
||||
endz,
|
||||
a,
|
||||
s,
|
||||
_vx_line_zdominant_xd(xd, ax, az),
|
||||
_vx_line_zdominant_yd(yd, ay, az)
|
||||
_vx_line_zdominant_xd(xd, a.x, a.z),
|
||||
_vx_line_zdominant_yd(yd, a.y, a.z)
|
||||
)
|
||||
];
|
||||
|
||||
|
@@ -12,5 +12,4 @@ use <_impl/_vx_circle_impl.scad>;
|
||||
use <../util/dedup.scad>;
|
||||
|
||||
function vx_circle(radius, filled = false) =
|
||||
let(all = _vx_circle_impl(radius, filled))
|
||||
dedup(all);
|
||||
dedup(_vx_circle_impl(radius, filled));
|
@@ -12,9 +12,8 @@ use <_impl/_vx_curve_impl.scad>;
|
||||
use <../util/dedup.scad>;
|
||||
|
||||
function vx_curve(points, tightness = 0) =
|
||||
let(
|
||||
leng = len(points),
|
||||
pts = [
|
||||
let(leng = len(points))
|
||||
dedup([
|
||||
each [
|
||||
for(i = [0:leng - 4])
|
||||
let(
|
||||
@@ -23,6 +22,4 @@ function vx_curve(points, tightness = 0) =
|
||||
for(i = [0:len(pts) - 2]) pts[i]
|
||||
],
|
||||
points[leng - 2]
|
||||
]
|
||||
)
|
||||
dedup(pts);
|
||||
]);
|
@@ -11,17 +11,13 @@
|
||||
function vx_sphere(radius, filled = false, thickness = 1) =
|
||||
let(range = [-radius: radius - 1])
|
||||
filled ? [
|
||||
for(z = range)
|
||||
for(y = range)
|
||||
for(x = range)
|
||||
for(z = range, y = range, x = range)
|
||||
let(v = [x, y, z])
|
||||
if(norm(v) < radius) v
|
||||
] :
|
||||
let(ishell = radius * radius - 2 * thickness * radius)
|
||||
[
|
||||
for(z = range)
|
||||
for(y = range)
|
||||
for(x = range)
|
||||
for(z = range, y = range, x = range)
|
||||
let(
|
||||
v = [x, y, z],
|
||||
leng = norm(v)
|
||||
|
Reference in New Issue
Block a user