mirror of
https://github.com/revarbat/BOSL2.git
synced 2025-08-21 06:02:06 +02:00
Renamed normalize() to unit()
This commit is contained in:
@@ -8,15 +8,15 @@ testpoints_on_sphere = [ for(p =
|
||||
[0,1,PHI], [0,-1,PHI], [0,1,-PHI], [0,-1,-PHI],
|
||||
[PHI,0,1], [-PHI,0,1], [PHI,0,-1], [-PHI,0,-1]
|
||||
])
|
||||
normalize(p)
|
||||
unit(p)
|
||||
];
|
||||
|
||||
testpoints_circular = [ for(a = [0:15:360-EPSILON]) [cos(a),sin(a)] ];
|
||||
|
||||
testpoints_coplanar = let(u = normalize([1,3,7]), v = normalize([-2,1,-2])) [ for(i = [1:10]) rands(-1,1,1)[0] * u + rands(-1,1,1)[0] * v ];
|
||||
testpoints_coplanar = let(u = unit([1,3,7]), v = unit([-2,1,-2])) [ for(i = [1:10]) rands(-1,1,1)[0] * u + rands(-1,1,1)[0] * v ];
|
||||
|
||||
testpoints_collinear_2d = let(u = normalize([5,3])) [ for(i = [1:20]) rands(-1,1,1)[0] * u ];
|
||||
testpoints_collinear_3d = let(u = normalize([5,3,-5])) [ for(i = [1:20]) rands(-1,1,1)[0] * u ];
|
||||
testpoints_collinear_2d = let(u = unit([5,3])) [ for(i = [1:20]) rands(-1,1,1)[0] * u ];
|
||||
testpoints_collinear_3d = let(u = unit([5,3,-5])) [ for(i = [1:20]) rands(-1,1,1)[0] * u ];
|
||||
|
||||
testpoints2d = 20 * [for (i = [1:10]) concat(rands(-1,1,2))];
|
||||
testpoints3d = 20 * [for (i = [1:50]) concat(rands(-1,1,3))];
|
||||
|
@@ -91,7 +91,7 @@ module test_line_normal() {
|
||||
for (p = pair_wrap(pts)) {
|
||||
p1 = p.x;
|
||||
p2 = p.y;
|
||||
n = normalize(p2-p1);
|
||||
n = unit(p2-p1);
|
||||
n1 = [-n.y, n.x];
|
||||
n2 = line_normal(p1,p2);
|
||||
assert(approx(n2, n1));
|
||||
@@ -239,7 +239,7 @@ module test_find_circle_3points() {
|
||||
for(i = list_range(count)) {
|
||||
cp = select(coords,i,i+2);
|
||||
r = radii[i];
|
||||
nrm = normalize(select(coords,i+10,i+12));
|
||||
nrm = unit(select(coords,i+10,i+12));
|
||||
n = nrm.z<0? -nrm : nrm;
|
||||
angs = sort(select(angles,i,i+2));
|
||||
pts = translate(cp,p=rot(from=UP,to=n,p=[for (a=angs) point3d(polar_to_xy(r,a))]));
|
||||
@@ -266,7 +266,7 @@ module test_find_circle_3points() {
|
||||
for(i = list_range(count)) {
|
||||
cp = select(coords,i,i+2);
|
||||
r = radii[i];
|
||||
nrm = normalize(select(coords,i+10,i+12));
|
||||
nrm = unit(select(coords,i+10,i+12));
|
||||
n = nrm.z<0? -nrm : nrm;
|
||||
angs = sort(select(angles,i,i+2));
|
||||
pts = translate(cp,p=rot(from=UP,to=n,p=[for (a=angs) point3d(polar_to_xy(r,a))]));
|
||||
|
@@ -67,17 +67,17 @@ module test_vang() {
|
||||
test_vang();
|
||||
|
||||
|
||||
module test_normalize() {
|
||||
assert(normalize([10,0,0]) == [1,0,0]);
|
||||
assert(normalize([0,10,0]) == [0,1,0]);
|
||||
assert(normalize([0,0,10]) == [0,0,1]);
|
||||
assert(abs(norm(normalize([10,10,10]))-1) < EPSILON);
|
||||
assert(abs(norm(normalize([-10,-10,-10]))-1) < EPSILON);
|
||||
assert(abs(norm(normalize([-10,0,0]))-1) < EPSILON);
|
||||
assert(abs(norm(normalize([0,-10,0]))-1) < EPSILON);
|
||||
assert(abs(norm(normalize([0,0,-10]))-1) < EPSILON);
|
||||
module test_unit() {
|
||||
assert(unit([10,0,0]) == [1,0,0]);
|
||||
assert(unit([0,10,0]) == [0,1,0]);
|
||||
assert(unit([0,0,10]) == [0,0,1]);
|
||||
assert(abs(norm(unit([10,10,10]))-1) < EPSILON);
|
||||
assert(abs(norm(unit([-10,-10,-10]))-1) < EPSILON);
|
||||
assert(abs(norm(unit([-10,0,0]))-1) < EPSILON);
|
||||
assert(abs(norm(unit([0,-10,0]))-1) < EPSILON);
|
||||
assert(abs(norm(unit([0,0,-10]))-1) < EPSILON);
|
||||
}
|
||||
test_normalize();
|
||||
test_unit();
|
||||
|
||||
|
||||
module test_vector_angle() {
|
||||
|
Reference in New Issue
Block a user