1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-08-13 18:24:28 +02:00

refactor: rename

This commit is contained in:
Justin Lin
2022-05-08 16:01:06 +08:00
parent 1428dc8307
commit 6549c22938
2 changed files with 74 additions and 74 deletions

View File

@@ -1,42 +1,42 @@
function _turtle2d_turtle(x, y, angle) = [[x, y], angle]; function _turtle(x, y, angle) = [[x, y], angle];
function _turtle2d_set_point(turtle, point) = [point, _turtle2d_get_angle(turtle)]; function _set_point(turtle, point) = [point, _get_angle(turtle)];
function _turtle2d_set_x(turtle, x) = [[x, _turtle2d_get_y(turtle)], _turtle2d_get_angle(turtle)]; function _set_x(turtle, x) = [[x, _get_y(turtle)], _get_angle(turtle)];
function _turtle2d_set_y(turtle, y) = [[_turtle2d_get_x(turtle), y], _turtle2d_get_angle(turtle)]; function _set_y(turtle, y) = [[_get_x(turtle), y], _get_angle(turtle)];
function _turtle2d_set_angle(turtle, angle) = [_turtle2d_get_pt(turtle), angle]; function _set_angle(turtle, angle) = [_get_pt(turtle), angle];
function _turtle2d_forward(turtle, leng) = function _forward(turtle, leng) =
_turtle2d_turtle( _turtle(
_turtle2d_get_x(turtle) + leng * cos(_turtle2d_get_angle(turtle)), _get_x(turtle) + leng * cos(_get_angle(turtle)),
_turtle2d_get_y(turtle) + leng * sin(_turtle2d_get_angle(turtle)), _get_y(turtle) + leng * sin(_get_angle(turtle)),
_turtle2d_get_angle(turtle) _get_angle(turtle)
); );
function _turtle2d_turn(turtle, angle) = [_turtle2d_get_pt(turtle), _turtle2d_get_angle(turtle) + angle]; function _turn(turtle, angle) = [_get_pt(turtle), _get_angle(turtle) + angle];
function _turtle2d_get_x(turtle) = turtle[0].x; function _get_x(turtle) = turtle[0].x;
function _turtle2d_get_y(turtle) = turtle[0].y; function _get_y(turtle) = turtle[0].y;
function _turtle2d_get_pt(turtle) = turtle[0]; function _get_pt(turtle) = turtle[0];
function _turtle2d_get_angle(turtle) = turtle[1]; function _get_angle(turtle) = turtle[1];
function _turtle2d_three_args_command(cmd, arg1, arg2, arg3) = function _three_args_command(cmd, arg1, arg2, arg3) =
cmd == "create" ? _turtle2d_turtle(arg1, arg2, arg3) : _turtle2d_two_args_command(cmd, arg1, arg2); cmd == "create" ? _turtle(arg1, arg2, arg3) : _two_args_command(cmd, arg1, arg2);
function _turtle2d_two_args_command(cmd, arg1, arg2) = function _two_args_command(cmd, arg1, arg2) =
is_undef(arg2) ? _turtle2d_one_arg_command(cmd, arg1) : is_undef(arg2) ? _one_arg_command(cmd, arg1) :
cmd == "pt" ? _turtle2d_set_point(arg1, arg2) : cmd == "pt" ? _set_point(arg1, arg2) :
cmd == "x" ? _turtle2d_set_x(arg1, arg2) : cmd == "x" ? _set_x(arg1, arg2) :
cmd == "y" ? _turtle2d_set_y(arg1, arg2) : cmd == "y" ? _set_y(arg1, arg2) :
cmd == "angle" ? _turtle2d_set_angle(arg1, arg2) : cmd == "angle" ? _set_angle(arg1, arg2) :
cmd == "forward" ? _turtle2d_forward(arg1, arg2) : cmd == "forward" ? _forward(arg1, arg2) :
cmd == "turn" ? _turtle2d_turn(arg1, arg2) : undef; cmd == "turn" ? _turn(arg1, arg2) : undef;
function _turtle2d_one_arg_command(cmd, arg) = function _one_arg_command(cmd, arg) =
cmd == "x" ? _turtle2d_get_x(arg) : cmd == "x" ? _get_x(arg) :
cmd == "y" ? _turtle2d_get_y(arg) : cmd == "y" ? _get_y(arg) :
cmd == "angle" ? _turtle2d_get_angle(arg) : cmd == "angle" ? _get_angle(arg) :
cmd == "pt" ? _turtle2d_get_pt(arg) : undef; cmd == "pt" ? _get_pt(arg) : undef;
function _turtle2d_impl(cmd, arg1, arg2, arg3) = function _turtle2d_impl(cmd, arg1, arg2, arg3) =
_turtle2d_three_args_command(cmd, arg1, arg2, arg3); _three_args_command(cmd, arg1, arg2, arg3);

View File

@@ -1,45 +1,45 @@
use <../../matrix/m_rotation.scad>; use <../../matrix/m_rotation.scad>;
function _turtle3d_create(pt, unit_vts) = [pt, unit_vts]; function _create(pt, unit_vts) = [pt, unit_vts];
function _turtle3d_create_default() = _turtle3d_create( function _create_default() = _create(
[0, 0, 0], [0, 0, 0],
// unit vectors from the turtle's viewpoint // unit vectors from the turtle's viewpoint
[[1, 0, 0], [0, 1, 0], [0, 0, 1]] [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
); );
function _turtle3d_pt(turtle) = turtle[0]; function _pt(turtle) = turtle[0];
function _turtle3d_unit_vts(turtle) = turtle[1]; function _unit_vts(turtle) = turtle[1];
// forward the turtle in the x' direction // forward the turtle in the x' direction
function _turtle3d_xu_move(turtle, leng) = _turtle3d_create( function _xu_move(turtle, leng) = _create(
_turtle3d_pt(turtle) + _turtle3d_unit_vts(turtle).x * leng, _pt(turtle) + _unit_vts(turtle).x * leng,
_turtle3d_unit_vts(turtle) _unit_vts(turtle)
); );
// forward the turtle in the y' direction // forward the turtle in the y' direction
function _turtle3d_yu_move(turtle, leng) = _turtle3d_create( function _yu_move(turtle, leng) = _create(
_turtle3d_pt(turtle) + _turtle3d_unit_vts(turtle).y * leng, _pt(turtle) + _unit_vts(turtle).y * leng,
_turtle3d_unit_vts(turtle) _unit_vts(turtle)
); );
// forward the turtle in the z' direction // forward the turtle in the z' direction
function _turtle3d_zu_move(turtle, leng) = _turtle3d_create( function _zu_move(turtle, leng) = _create(
_turtle3d_pt(turtle) + _turtle3d_unit_vts(turtle).z * leng, _pt(turtle) + _unit_vts(turtle).z * leng,
_turtle3d_unit_vts(turtle) _unit_vts(turtle)
); );
// turn the turtle around the x'-axis // turn the turtle around the x'-axis
// return a new unit vector // return a new unit vector
function _turtle3d_xu_turn(turtle, a) = function _xu_turn(turtle, a) =
let( let(
unit_vts = _turtle3d_unit_vts(turtle), unit_vts = _unit_vts(turtle),
xu = unit_vts.x, xu = unit_vts.x,
m = m_rotation(a, xu), m = m_rotation(a, xu),
nyu = m * [each unit_vts.y, 1], nyu = m * [each unit_vts.y, 1],
nzu = m * [each unit_vts.z, 1] nzu = m * [each unit_vts.z, 1]
) )
_turtle3d_create( _create(
_turtle3d_pt(turtle), _pt(turtle),
[ [
xu, xu,
[nyu.x, nyu.y, nyu.z], [nyu.x, nyu.y, nyu.z],
@@ -49,16 +49,16 @@ function _turtle3d_xu_turn(turtle, a) =
// turn the turtle around the y'-axis // turn the turtle around the y'-axis
// return a new unit vector // return a new unit vector
function _turtle3d_yu_turn(turtle, a) = function _yu_turn(turtle, a) =
let( let(
unit_vts = _turtle3d_unit_vts(turtle), unit_vts = _unit_vts(turtle),
yu = unit_vts.y, yu = unit_vts.y,
m = m_rotation(a, yu), m = m_rotation(a, yu),
nxu = m * [each unit_vts.x, 1], nxu = m * [each unit_vts.x, 1],
nzu = m * [each unit_vts.z, 1] nzu = m * [each unit_vts.z, 1]
) )
_turtle3d_create( _create(
_turtle3d_pt(turtle), _pt(turtle),
[ [
[nxu.x, nxu.y, nxu.z], [nxu.x, nxu.y, nxu.z],
yu, yu,
@@ -68,16 +68,16 @@ function _turtle3d_yu_turn(turtle, a) =
// turn the turtle around the z'-axis // turn the turtle around the z'-axis
// return a new unit vector // return a new unit vector
function _turtle3d_zu_turn(turtle, a) = function _zu_turn(turtle, a) =
let( let(
unit_vts = _turtle3d_unit_vts(turtle), unit_vts = _unit_vts(turtle),
zu = unit_vts.z, zu = unit_vts.z,
m = m_rotation(a, zu), m = m_rotation(a, zu),
nxu = m * [each unit_vts.x, 1], nxu = m * [each unit_vts.x, 1],
nyu = m * [each unit_vts.y, 1] nyu = m * [each unit_vts.y, 1]
) )
_turtle3d_create( _create(
_turtle3d_pt(turtle), _pt(turtle),
[ [
[nxu.x, nxu.y, nxu.z], [nxu.x, nxu.y, nxu.z],
[nyu.x, nyu.y, nyu.z], [nyu.x, nyu.y, nyu.z],
@@ -85,27 +85,27 @@ function _turtle3d_zu_turn(turtle, a) =
] ]
); );
function _turtle3d_create_cmd(arg1, arg2) = function _create_cmd(arg1, arg2) =
is_undef(arg1) && is_undef(arg2) ? _turtle3d_create_default() : is_undef(arg1) && is_undef(arg2) ? _create_default() :
!is_undef(arg1) && !is_undef(arg2) ? _turtle3d_create(arg1, arg2) : undef; !is_undef(arg1) && !is_undef(arg2) ? _create(arg1, arg2) : undef;
function _turtle3d_chain_move(cmd, arg1, arg2) = function _chain_move(cmd, arg1, arg2) =
cmd == "forward" || cmd == "xu_move" ? _turtle3d_xu_move(arg1, arg2) : cmd == "forward" || cmd == "xu_move" ? _xu_move(arg1, arg2) :
cmd == "yu_move" ? _turtle3d_yu_move(arg1, arg2) : cmd == "yu_move" ? _yu_move(arg1, arg2) :
cmd == "zu_move" ? _turtle3d_zu_move(arg1, arg2) : _turtle3d_chain_turn(cmd, arg1, arg2); cmd == "zu_move" ? _zu_move(arg1, arg2) : _chain_turn(cmd, arg1, arg2);
function _turtle3d_chain_turn(cmd, arg1, arg2) = function _chain_turn(cmd, arg1, arg2) =
cmd == "roll" ? _turtle3d_xu_turn(arg1, -arg2) : cmd == "roll" ? _xu_turn(arg1, -arg2) :
cmd == "pitch" ? _turtle3d_yu_turn(arg1, -arg2) : cmd == "pitch" ? _yu_turn(arg1, -arg2) :
cmd == "turn" || cmd == "zu_turn" ? _turtle3d_zu_turn(arg1, arg2) : cmd == "turn" || cmd == "zu_turn" ? _zu_turn(arg1, arg2) :
cmd == "xu_turn" ? _turtle3d_xu_turn(arg1, arg2) : cmd == "xu_turn" ? _xu_turn(arg1, arg2) :
cmd == "yu_turn" ? _turtle3d_yu_turn(arg1, arg2) : _turtle3d_chain_one_arg(cmd, arg1); cmd == "yu_turn" ? _yu_turn(arg1, arg2) : _chain_one_arg(cmd, arg1);
function _turtle3d_chain_one_arg(cmd, arg) = function _chain_one_arg(cmd, arg) =
cmd == "pt" ? _turtle3d_pt(arg) : cmd == "pt" ? _pt(arg) :
cmd == "unit_vts" ? _turtle3d_unit_vts(arg) : undef; cmd == "unit_vts" ? _unit_vts(arg) : undef;
function _turtle3d_impl(cmd, arg1, arg2) = function _turtle3d_impl(cmd, arg1, arg2) =
cmd == "create" ? cmd == "create" ?
_turtle3d_create_cmd(arg1, arg2) : _create_cmd(arg1, arg2) :
_turtle3d_chain_move(cmd, arg1, arg2); _chain_move(cmd, arg1, arg2);