mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-08-16 11:44:50 +02:00
use scad
This commit is contained in:
50
src/pixel/_impl/_px_cylinder_impl.scad
Normal file
50
src/pixel/_impl/_px_cylinder_impl.scad
Normal file
@@ -0,0 +1,50 @@
|
||||
|
||||
function _px_cylinder_px_circle(radius, filled, thickness) =
|
||||
let(range = [-radius: radius - 1])
|
||||
filled ? [
|
||||
for(y = range)
|
||||
for(x = range)
|
||||
let(v = [x, y])
|
||||
if(norm(v) < radius) v
|
||||
] :
|
||||
let(ishell = radius * radius - 2 * thickness * radius)
|
||||
[
|
||||
for(y = range)
|
||||
for(x = range)
|
||||
let(
|
||||
v = [x, y],
|
||||
leng = norm(v)
|
||||
)
|
||||
if(leng < radius && (leng * leng) > ishell) v
|
||||
];
|
||||
|
||||
function _px_cylinder_diff_r(r, h, filled, thickness) =
|
||||
let(
|
||||
r1 = r[0],
|
||||
r2 = r[1]
|
||||
)
|
||||
r1 == r2 ? _px_cylinder_same_r(r1, h, filled, thickness) :
|
||||
let(dr = (r2 - r1) / (h - 1))
|
||||
[
|
||||
for(i = 0; i < h; i = i + 1)
|
||||
let(r = round(r1 + dr * i))
|
||||
each [
|
||||
for(pt = _px_cylinder_px_circle(r, filled, thickness))
|
||||
[pt[0], pt[1], i]
|
||||
]
|
||||
];
|
||||
|
||||
function _px_cylinder_same_r(r, h, filled, thickness) =
|
||||
let(c = _px_cylinder_px_circle(r, filled, thickness))
|
||||
[
|
||||
for(i = 0; i < h; i = i + 1)
|
||||
each [
|
||||
for(pt = c)
|
||||
[pt[0], pt[1], i]
|
||||
]
|
||||
];
|
||||
|
||||
function _px_cylinder_impl(r, h, filled, thickness) =
|
||||
is_num(r) ?
|
||||
_px_cylinder_same_r(r, h, filled, thickness) :
|
||||
_px_cylinder_diff_r(r, h, filled, thickness);
|
@@ -8,52 +8,7 @@
|
||||
*
|
||||
**/
|
||||
|
||||
function _px_cylinder_px_circle(radius, filled, thickness) =
|
||||
let(range = [-radius: radius - 1])
|
||||
filled ? [
|
||||
for(y = range)
|
||||
for(x = range)
|
||||
let(v = [x, y])
|
||||
if(norm(v) < radius) v
|
||||
] :
|
||||
let(ishell = radius * radius - 2 * thickness * radius)
|
||||
[
|
||||
for(y = range)
|
||||
for(x = range)
|
||||
let(
|
||||
v = [x, y],
|
||||
leng = norm(v)
|
||||
)
|
||||
if(leng < radius && (leng * leng) > ishell) v
|
||||
];
|
||||
|
||||
function _px_cylinder_diff_r(r, h, filled, thickness) =
|
||||
let(
|
||||
r1 = r[0],
|
||||
r2 = r[1]
|
||||
)
|
||||
r1 == r2 ? _px_cylinder_same_r(r1, h, filled, thickness) :
|
||||
let(dr = (r2 - r1) / (h - 1))
|
||||
[
|
||||
for(i = 0; i < h; i = i + 1)
|
||||
let(r = round(r1 + dr * i))
|
||||
each [
|
||||
for(pt = _px_cylinder_px_circle(r, filled, thickness))
|
||||
[pt[0], pt[1], i]
|
||||
]
|
||||
];
|
||||
|
||||
function _px_cylinder_same_r(r, h, filled, thickness) =
|
||||
let(c = _px_cylinder_px_circle(r, filled, thickness))
|
||||
[
|
||||
for(i = 0; i < h; i = i + 1)
|
||||
each [
|
||||
for(pt = c)
|
||||
[pt[0], pt[1], i]
|
||||
]
|
||||
];
|
||||
use <pixel/_impl/_px_cylinder_impl.scad>;
|
||||
|
||||
function px_cylinder(r, h, filled = false, thickness = 1) =
|
||||
is_num(r) ?
|
||||
_px_cylinder_same_r(r, h, filled, thickness) :
|
||||
_px_cylinder_diff_r(r, h, filled, thickness);
|
||||
_px_cylinder_impl(r, h, filled, thickness);
|
@@ -1,5 +1,5 @@
|
||||
include <unittest.scad>;
|
||||
include <pixel/px_cylinder.scad>;
|
||||
use <unittest.scad>;
|
||||
use <pixel/px_cylinder.scad>;
|
||||
|
||||
module test_px_cylinder() {
|
||||
echo("==== test_px_cylinder ====");
|
||||
|
Reference in New Issue
Block a user