1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-08-19 13:01:37 +02:00
This commit is contained in:
Justin Lin
2022-03-01 09:54:48 +08:00
parent 769023f639
commit 14ad6b4090
13 changed files with 29 additions and 43 deletions

View File

@@ -2,7 +2,9 @@ function __angy_angz(p1, p2) =
let(
dx = p2.x - p1.x,
dy = p2.y - p1.y,
dz = p2.z - p1.z,
ya = atan2(dz, sqrt(dx * dx + dy * dy)),
za = atan2(dy, dx)
) [ya, za];
dz = p2.z - p1.z
)
[
atan2(dz, sqrt(dx ^ 2 + dy ^ 2)),
atan2(dy, dx)
];

View File

@@ -1,7 +1,6 @@
function __lines_from(pts, closed = false) =
let(
leng = len(pts),
endi = leng - 1,
endi = len(pts) - 1,
lines = [for(i = 0; i < endi; i = i + 1) [pts[i], pts[i + 1]]]
)
closed ? [each lines, [pts[endi], pts[0]]] : lines;

View File

@@ -1 +1 @@
function __to_degree(phi) = 180 / PI * phi;
function __to_degree(radians) = (radians * 180) / PI;

View File

@@ -115,11 +115,12 @@ function _convex_hull3(pts) =
[v2, v1, v3],
[v0, v2, v3]
],
init_vis = [for(i = [0:leng - 1]) [for(j = [0:leng - 1]) 0]],
zeros = [for(j = [0:leng - 1]) 0],
init_vis = [for(i = [0:leng - 1]) zeros],
faces = _all_faces(v0, v1, v2, v3, sorted, leng, init_vis, fst_tetrahedron), // counter-clockwise
reversed = [for(face = faces) // OpenSCAD prefers clockwise.
[for(i = 2; i >= 0; i = i - 1)
face[i]]
reversed = [
for(face = faces) // OpenSCAD requires clockwise.
[for(i = 2; i >= 0; i = i - 1) face[i]]
]
)
[

View File

@@ -6,11 +6,12 @@ function _liquid_splitting_pie_curve(radius, centre_dist, tangent_angle) =
let(
begin_ang = 90 + tangent_angle,
shape_pts = shape_pie(radius, [-begin_ang, begin_ang]),
leng = len(shape_pts)
leng = len(shape_pts),
offset_p = [centre_dist / 2, 0]
)
[
for(i = 1; i < leng; i = i + 1)
shape_pts[i] + [centre_dist / 2, 0]
shape_pts[i] + offset_p
];
function _liquid_splitting_bezier(radius, centre_dist, tangent_angle, t_step, ctrl_p1) =

View File

@@ -106,8 +106,7 @@ function wf_entropy(wf, x, y) =
let(
states = wf_eigenstates_at(wf, x, y),
weights = wf_weights(wf),
state_leng = len(states),
sumOfWeights_sumOfWeightLogWeights = _wf_entropy(weights, states, state_leng, 0, 0),
sumOfWeights_sumOfWeightLogWeights = _wf_entropy(weights, states, len(states), 0, 0),
sumOfWeights = sumOfWeights_sumOfWeightLogWeights[0],
sumOfWeightLogWeights = sumOfWeights_sumOfWeightLogWeights[1]
)
@@ -241,8 +240,8 @@ function tilemap_generate(tm) =
wf_is_all_collapsed(wf) ? collapsed_tiles(wf) :
let(
coord = wf_coord_min_entropy(wf),
x = coord[0],
y = coord[1]
x = coord.x,
y = coord.y
)
tilemap_generate(tilemap_propagate([
tilemap_width(tm),
@@ -269,10 +268,8 @@ function compatibilities_of_tiles(sample) =
height = len(sample)
)
hashset([
for(y = [0:height - 1])
for(x = [0:width - 1])
for(c = neighbor_compatibilities(sample, x, y, width, height))
c
for(y = [0:height - 1], x = [0:width - 1])
each neighbor_compatibilities(sample, x, y, width, height)
], number_of_buckets = width * height);
function collapsed_tiles(wf) =

View File

@@ -6,7 +6,6 @@ function _dedup(elems, leng, buckets, eq, hash, bucket_numbers, i = 0) =
function _dedup_add(buckets, i_elem, eq, hash, bucket_numbers) =
let(
i = i_elem[0],
elem = i_elem[1],
b_idx = hash(elem) % bucket_numbers,
bucket = buckets[b_idx]

View File

@@ -1,2 +0,0 @@
function _sum_impl(lt, leng, i = 0) =
i >= leng - 1 ? lt[i] : (lt[i] + _sum_impl(lt, leng, i + 1));

View File

@@ -8,4 +8,4 @@
*
**/
function degrees(radians) = 180 / PI * radians;
function degrees(radians) = (radians * 180) / PI;

View File

@@ -8,4 +8,4 @@
*
**/
function radians(degrees) = PI / 180 * degrees;
function radians(degrees) = (degrees * PI) / 180;

View File

@@ -8,6 +8,4 @@
*
**/
use <_impl/_sum_impl.scad>;
function sum(lt) = _sum_impl(lt, len(lt));
function sum(lt) = [for(i = [0:len(lt) - 1]) 1] * lt;

View File

@@ -17,26 +17,20 @@ function _in_convex(convex_pts, pt) =
function _intersection_ps(shape, line_pts, epsilon) =
let(
leng = len(shape),
pts = [each shape, shape[0]]
)
let(pts = [each shape, shape[0]])
dedup([
for(i = [0:leng - 1])
for(i = [0:len(shape) - 1])
let(p = lines_intersection(line_pts, [pts[i], pts[i + 1]], epsilon = epsilon))
if(p != []) p
]);
function _convex_intersection(shape1, shape2, epsilon = 0.0001) =
(shape1 == [] || shape2 == []) ? [] :
let(
leng = len(shape1),
pts = [each shape1, shape1[0]]
)
let(pts = [each shape1, shape1[0]])
_convex_ct_clk_order(
concat(
[for(p = shape1) if(_in_convex(shape2, p)) p],
[for(p = shape2) if(_in_convex(shape1, p)) p],
[for(i = [0:leng - 1]) each _intersection_ps(shape2, [pts[i], pts[i + 1]], epsilon)]
[for(i = [0:len(shape1) - 1]) each _intersection_ps(shape2, [pts[i], pts[i + 1]], epsilon)]
)
);

View File

@@ -22,10 +22,7 @@ function cell_pt(fcord, grid_w, seed, x, y, gw, gh) =
function _neighbors(fcord, seed, grid_w, gw, gh) =
let(range = [-1:1])
concat(
[
for(y = range, x = range)
cell_pt(fcord, grid_w, seed, x, y, gw, gh)
],
[for(y = range, x = range) cell_pt(fcord, grid_w, seed, x, y, gw, gh)],
[for(x = range) cell_pt(fcord, grid_w, seed, x, -2, gw, gh)],
[for(x = range) cell_pt(fcord, grid_w, seed, x, 2, gw, gh)],
[for(y = range) cell_pt(fcord, grid_w, seed, -2, y, gw, gh)],