summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bench/libdimension/geometry.c32
-rw-r--r--bench/libdimension/kD_splay_tree.c4
-rw-r--r--dimension/realize.c24
-rw-r--r--libdimension/cameras.c4
-rw-r--r--libdimension/dimension/geometry.h12
-rw-r--r--libdimension/geometry.c90
-rw-r--r--libdimension/kD_splay_tree.c14
-rw-r--r--libdimension/objects.c20
-rw-r--r--libdimension/raytrace.c9
-rw-r--r--tests/libdimension/kD_splay_tree.c12
-rw-r--r--tests/libdimension/tests.c12
11 files changed, 114 insertions, 119 deletions
diff --git a/bench/libdimension/geometry.c b/bench/libdimension/geometry.c
index a80c0ff..38cac9b 100644
--- a/bench/libdimension/geometry.c
+++ b/bench/libdimension/geometry.c
@@ -37,20 +37,20 @@ main()
return EXIT_FAILURE;
}
- /* dmnsn_vector_construct() */
+ /* dmnsn_new_vector() */
sandglass_bench_fine(&sandglass, {
- vector = dmnsn_vector_construct(1.0, 2.0, 3.0);
+ vector = dmnsn_new_vector(1.0, 2.0, 3.0);
});
- printf("dmnsn_vector_construct(): %ld\n", sandglass.grains);
+ printf("dmnsn_new_vector(): %ld\n", sandglass.grains);
/* dmnsn_matrix_construct() */
sandglass_bench_fine(&sandglass, {
- matrix = dmnsn_matrix_construct(1.0, 1.0, 0.0, 0.0,
- 1.0, 1.0, 1.0, 0.0,
- 0.0, 1.0, 1.0, 0.0,
- 0.0, 0.0, 0.0, 1.0);
+ matrix = dmnsn_new_matrix(1.0, 1.0, 0.0, 0.0,
+ 1.0, 1.0, 1.0, 0.0,
+ 0.0, 1.0, 1.0, 0.0,
+ 0.0, 0.0, 0.0, 1.0);
});
- printf("dmnsn_matrix_construct(): %ld\n", sandglass.grains);
+ printf("dmnsn_new_matrix(): %ld\n", sandglass.grains);
/* dmnsn_identity_matrix() */
sandglass_bench_fine(&sandglass, {
@@ -76,12 +76,12 @@ main()
});
printf("dmnsn_rotation_matrix(): %ld\n", sandglass.grains);
- /* dmnsn_line_construct() */
- vector2 = dmnsn_vector_construct(3.0, 2.0, 1.0);
+ /* dmnsn_new_line() */
+ vector2 = dmnsn_new_vector(3.0, 2.0, 1.0);
sandglass_bench_fine(&sandglass, {
- line = dmnsn_line_construct(vector, vector2);
+ line = dmnsn_new_line(vector, vector2);
});
- printf("dmnsn_line_construct(): %ld\n", sandglass.grains);
+ printf("dmnsn_new_line(): %ld\n", sandglass.grains);
/* dmnsn_vector_add() */
sandglass_bench_fine(&sandglass, {
@@ -138,10 +138,10 @@ main()
printf("dmnsn_matrix_inverse(): %ld\n", sandglass.grains);
/* dmnsn_matrix_inverse(HARD) */
- matrix2 = dmnsn_matrix_construct(1.0, 1.0, 0.0, 0.0,
- 1.0, 1.0, 1.0, 0.0,
- 0.0, 1.0, 1.0, 0.0,
- 0.0, 0.0, 0.0, 1.0);
+ matrix2 = dmnsn_new_matrix(1.0, 1.0, 0.0, 0.0,
+ 1.0, 1.0, 1.0, 0.0,
+ 0.0, 1.0, 1.0, 0.0,
+ 0.0, 0.0, 0.0, 1.0);
sandglass_bench_fine(&sandglass, {
matrix = dmnsn_matrix_inverse(matrix2);
});
diff --git a/bench/libdimension/kD_splay_tree.c b/bench/libdimension/kD_splay_tree.c
index bb20a14..fffab69 100644
--- a/bench/libdimension/kD_splay_tree.c
+++ b/bench/libdimension/kD_splay_tree.c
@@ -146,8 +146,8 @@ main()
/* dmnsn_kD_splay_search() */
- ray.x0 = dmnsn_vector_construct(0.0, 0.0, -2.0);
- ray.n = dmnsn_vector_construct(0.0, 0.0, 1.0);
+ ray.x0 = dmnsn_new_vector(0.0, 0.0, -2.0);
+ ray.n = dmnsn_new_vector(0.0, 0.0, 1.0);
dmnsn_delete_intersection((*objects[0]->intersection_fn)(objects[0], ray));
sandglass_bench_noprecache(&sandglass, {
diff --git a/dimension/realize.c b/dimension/realize.c
index bb977a6..264c4a7 100644
--- a/dimension/realize.c
+++ b/dimension/realize.c
@@ -80,7 +80,7 @@ dmnsn_realize_vector(dmnsn_astnode astnode)
y = dmnsn_realize_float(ynode),
z = dmnsn_realize_float(znode);
- return dmnsn_vector_construct(x, y, z);
+ return dmnsn_new_vector(x, y, z);
}
dmnsn_object *
@@ -103,14 +103,14 @@ dmnsn_realize_box(dmnsn_astnode astnode)
}
box->trans = dmnsn_scale_matrix(
- dmnsn_vector_construct(fabs(x2.x - x1.x)/2.0,
- fabs(x2.y - x1.y)/2.0,
- fabs(x2.z - x1.z)/2.0)
+ dmnsn_new_vector(fabs(x2.x - x1.x)/2.0,
+ fabs(x2.y - x1.y)/2.0,
+ fabs(x2.z - x1.z)/2.0)
);
box->trans = dmnsn_matrix_mul(
- dmnsn_translation_matrix(dmnsn_vector_construct((x2.x + x1.x)/2.0,
- (x2.y + x1.y)/2.0,
- (x2.z + x1.z)/2.0)),
+ dmnsn_translation_matrix(dmnsn_new_vector((x2.x + x1.x)/2.0,
+ (x2.y + x1.y)/2.0,
+ (x2.z + x1.z)/2.0)),
box->trans
);
@@ -148,7 +148,7 @@ dmnsn_realize_sphere(dmnsn_astnode astnode)
dmnsn_error(DMNSN_SEVERITY_HIGH, "Couldn't allocate sphere pigment.");
}
- sphere->trans = dmnsn_scale_matrix(dmnsn_vector_construct(r, r, r));
+ sphere->trans = dmnsn_scale_matrix(dmnsn_new_vector(r, r, r));
sphere->trans = dmnsn_matrix_mul(dmnsn_translation_matrix(x0), sphere->trans);
return sphere;
@@ -176,20 +176,20 @@ dmnsn_realize(const dmnsn_array *astree)
/* Set up the transformation matrix for the perspective camera */
dmnsn_matrix trans = dmnsn_scale_matrix(
- dmnsn_vector_construct(
+ dmnsn_new_vector(
((double)scene->canvas->x)/scene->canvas->y, 1.0, 1.0
)
);
trans = dmnsn_matrix_mul(
- dmnsn_translation_matrix(dmnsn_vector_construct(0.0, 0.0, -4.0)),
+ dmnsn_translation_matrix(dmnsn_new_vector(0.0, 0.0, -4.0)),
trans
);
trans = dmnsn_matrix_mul(
- dmnsn_rotation_matrix(dmnsn_vector_construct(0.0, 1.0, 0.0)),
+ dmnsn_rotation_matrix(dmnsn_new_vector(0.0, 1.0, 0.0)),
trans
);
trans = dmnsn_matrix_mul(
- dmnsn_rotation_matrix(dmnsn_vector_construct(-0.75, 0.0, 0.0)),
+ dmnsn_rotation_matrix(dmnsn_new_vector(-0.75, 0.0, 0.0)),
trans
);
diff --git a/libdimension/cameras.c b/libdimension/cameras.c
index 54c7e7f..3389cc7 100644
--- a/libdimension/cameras.c
+++ b/libdimension/cameras.c
@@ -77,10 +77,10 @@ dmnsn_perspective_camera_ray_fn(const dmnsn_camera *camera,
dmnsn_line l;
/* Rays originate at the origin, oddly enough */
- l.x0 = dmnsn_vector_construct(0.0, 0.0, 0.0);
+ l.x0 = dmnsn_new_vector(0.0, 0.0, 0.0);
/* Aim at the z = 1 plane */
- l.n = dmnsn_vector_construct(x - 0.5, y - 0.5, 1.0);
+ l.n = dmnsn_new_vector(x - 0.5, y - 0.5, 1.0);
return dmnsn_matrix_line_mul(*trans, l);
}
diff --git a/libdimension/dimension/geometry.h b/libdimension/dimension/geometry.h
index 08ac1b3..68359aa 100644
--- a/libdimension/dimension/geometry.h
+++ b/libdimension/dimension/geometry.h
@@ -42,17 +42,17 @@ typedef struct {
/* Shorthand for vector/matrix construction */
DMNSN_INLINE dmnsn_vector
-dmnsn_vector_construct(double x, double y, double z)
+dmnsn_new_vector(double x, double y, double z)
{
dmnsn_vector v = { x, y, z };
return v;
}
DMNSN_INLINE dmnsn_matrix
-dmnsn_matrix_construct(double a0, double a1, double a2, double a3,
- double b0, double b1, double b2, double b3,
- double c0, double c1, double c2, double c3,
- double d0, double d1, double d2, double d3)
+dmnsn_new_matrix(double a0, double a1, double a2, double a3,
+ double b0, double b1, double b2, double b3,
+ double c0, double c1, double c2, double c3,
+ double d0, double d1, double d2, double d3)
{
dmnsn_matrix m = { { { a0, a1, a2, a3 },
{ b0, b1, b2, b3 },
@@ -68,7 +68,7 @@ dmnsn_matrix dmnsn_translation_matrix(dmnsn_vector d);
dmnsn_matrix dmnsn_rotation_matrix(dmnsn_vector theta);
DMNSN_INLINE dmnsn_line
-dmnsn_line_construct(dmnsn_vector x0, dmnsn_vector n)
+dmnsn_new_line(dmnsn_vector x0, dmnsn_vector n)
{
dmnsn_line l = { x0, n };
return l;
diff --git a/libdimension/geometry.c b/libdimension/geometry.c
index 6df0102..cbcc2c1 100644
--- a/libdimension/geometry.c
+++ b/libdimension/geometry.c
@@ -25,30 +25,30 @@
dmnsn_matrix
dmnsn_identity_matrix()
{
- return dmnsn_matrix_construct(1.0, 0.0, 0.0, 0.0,
- 0.0, 1.0, 0.0, 0.0,
- 0.0, 0.0, 1.0, 0.0,
- 0.0, 0.0, 0.0, 1.0);
+ return dmnsn_new_matrix(1.0, 0.0, 0.0, 0.0,
+ 0.0, 1.0, 0.0, 0.0,
+ 0.0, 0.0, 1.0, 0.0,
+ 0.0, 0.0, 0.0, 1.0);
}
/* Scaling matrix */
dmnsn_matrix
dmnsn_scale_matrix(dmnsn_vector s)
{
- return dmnsn_matrix_construct(s.x, 0.0, 0.0, 0.0,
- 0.0, s.y, 0.0, 0.0,
- 0.0, 0.0, s.z, 0.0,
- 0.0, 0.0, 0.0, 1.0);
+ return dmnsn_new_matrix(s.x, 0.0, 0.0, 0.0,
+ 0.0, s.y, 0.0, 0.0,
+ 0.0, 0.0, s.z, 0.0,
+ 0.0, 0.0, 0.0, 1.0);
}
/* Translation matrix */
dmnsn_matrix
dmnsn_translation_matrix(dmnsn_vector d)
{
- return dmnsn_matrix_construct(1.0, 0.0, 0.0, d.x,
- 0.0, 1.0, 0.0, d.y,
- 0.0, 0.0, 1.0, d.z,
- 0.0, 0.0, 0.0, 1.0);
+ return dmnsn_new_matrix(1.0, 0.0, 0.0, d.x,
+ 0.0, 1.0, 0.0, d.y,
+ 0.0, 0.0, 1.0, d.z,
+ 0.0, 0.0, 0.0, 1.0);
}
/* Left-handed rotation matrix; theta/|theta| = axis, |theta| = angle */
@@ -56,25 +56,23 @@ dmnsn_matrix
dmnsn_rotation_matrix(dmnsn_vector theta)
{
/* Two trig calls, 25 multiplications, 13 additions */
- dmnsn_vector axis;
- double angle, s, t, x, y, z;
- angle = dmnsn_vector_norm(theta);
+ double angle = dmnsn_vector_norm(theta);
if (angle == 0.0) {
return dmnsn_identity_matrix();
}
- axis = dmnsn_vector_normalize(theta);
+ dmnsn_vector axis = dmnsn_vector_normalize(theta);
- /* Shorthand to make dmnsn_matrix_construct() call legible */
+ /* Shorthand to make dmnsn_new_matrix() call legible */
- s = sin(angle);
- t = 1.0 - cos(angle);
+ double s = sin(angle);
+ double t = 1.0 - cos(angle);
- x = axis.x;
- y = axis.y;
- z = axis.z;
+ double x = axis.x;
+ double y = axis.y;
+ double z = axis.z;
- return dmnsn_matrix_construct(
+ return dmnsn_new_matrix(
1.0 + t*(x*x - 1.0), -z*s + t*x*y, y*s + t*x*z, 0.0,
z*s + t*x*y, 1.0 + t*(y*y - 1.0), -x*s + t*y*z, 0.0,
-y*s + t*x*z, x*s + t*y*z, 1.0 + t*(z*z - 1.0), 0.0,
@@ -86,8 +84,8 @@ dmnsn_rotation_matrix(dmnsn_vector theta)
typedef struct { double n[2][2]; } dmnsn_matrix2;
-static dmnsn_matrix2 dmnsn_matrix2_construct(double a1, double a2,
- double b1, double b2);
+static dmnsn_matrix2 dmnsn_new_matrix2(double a1, double a2,
+ double b1, double b2);
static dmnsn_matrix2 dmnsn_matrix2_inverse(dmnsn_matrix2 A);
static dmnsn_matrix2 dmnsn_matrix2_negate(dmnsn_matrix2 A);
static dmnsn_matrix2 dmnsn_matrix2_sub(dmnsn_matrix2 lhs, dmnsn_matrix2 rhs);
@@ -134,18 +132,18 @@ dmnsn_matrix_inverse(dmnsn_matrix A)
}
/* Partition the matrix */
- P = dmnsn_matrix2_construct(A.n[0][0], A.n[0][1],
- A.n[1][0], A.n[1][1]);
- Q = dmnsn_matrix2_construct(A.n[0][2], A.n[0][3],
- A.n[1][2], A.n[1][3]);
- R = dmnsn_matrix2_construct(A.n[2][0], A.n[2][1],
- A.n[3][0], A.n[3][1]);
- S = dmnsn_matrix2_construct(A.n[2][2], A.n[2][3],
- A.n[3][2], A.n[3][3]);
+ P = dmnsn_new_matrix2(A.n[0][0], A.n[0][1],
+ A.n[1][0], A.n[1][1]);
+ Q = dmnsn_new_matrix2(A.n[0][2], A.n[0][3],
+ A.n[1][2], A.n[1][3]);
+ R = dmnsn_new_matrix2(A.n[2][0], A.n[2][1],
+ A.n[3][0], A.n[3][1]);
+ S = dmnsn_new_matrix2(A.n[2][2], A.n[2][3],
+ A.n[3][2], A.n[3][3]);
/* Do this inversion ourselves, since we already have the determinant */
- Pi = dmnsn_matrix2_construct( P.n[1][1]/Pdet, -P.n[0][1]/Pdet,
- -P.n[1][0]/Pdet, P.n[0][0]/Pdet);
+ Pi = dmnsn_new_matrix2( P.n[1][1]/Pdet, -P.n[0][1]/Pdet,
+ -P.n[1][0]/Pdet, P.n[0][0]/Pdet);
/* Calculate R*inv(P), inv(P)*Q, and R*inv(P)*Q */
RPi = dmnsn_matrix2_mul(R, Pi);
@@ -159,15 +157,15 @@ dmnsn_matrix_inverse(dmnsn_matrix A)
PP = dmnsn_matrix2_sub(Pi, dmnsn_matrix2_mul(PiQ, RR));
/* Reconstruct the matrix */
- return dmnsn_matrix_construct(PP.n[0][0], PP.n[0][1], QQ.n[0][0], QQ.n[0][1],
- PP.n[1][0], PP.n[1][1], QQ.n[1][0], QQ.n[1][1],
- RR.n[0][0], RR.n[0][1], SS.n[0][0], SS.n[0][1],
- RR.n[1][0], RR.n[1][1], SS.n[1][0], SS.n[1][1]);
+ return dmnsn_new_matrix(PP.n[0][0], PP.n[0][1], QQ.n[0][0], QQ.n[0][1],
+ PP.n[1][0], PP.n[1][1], QQ.n[1][0], QQ.n[1][1],
+ RR.n[0][0], RR.n[0][1], SS.n[0][0], SS.n[0][1],
+ RR.n[1][0], RR.n[1][1], SS.n[1][0], SS.n[1][1]);
}
/* For nice shorthand */
static dmnsn_matrix2
-dmnsn_matrix2_construct(double a1, double a2, double b1, double b2)
+dmnsn_new_matrix2(double a1, double a2, double b1, double b2)
{
dmnsn_matrix2 m = { { { a1, a2 },
{ b1, b2 } } };
@@ -180,16 +178,16 @@ dmnsn_matrix2_inverse(dmnsn_matrix2 A)
{
/* 4 divisions, 2 multiplications, 1 addition */
double det = A.n[0][0]*A.n[1][1] - A.n[0][1]*A.n[1][0];
- return dmnsn_matrix2_construct( A.n[1][1]/det, -A.n[0][1]/det,
- -A.n[1][0]/det, A.n[0][0]/det);
+ return dmnsn_new_matrix2( A.n[1][1]/det, -A.n[0][1]/det,
+ -A.n[1][0]/det, A.n[0][0]/det);
}
/* Also basically a shorthand */
static dmnsn_matrix2
dmnsn_matrix2_negate(dmnsn_matrix2 A)
{
- return dmnsn_matrix2_construct(-A.n[0][0], -A.n[0][1],
- -A.n[1][0], -A.n[1][1]);
+ return dmnsn_new_matrix2(-A.n[0][0], -A.n[0][1],
+ -A.n[1][0], -A.n[1][1]);
}
/* 2x2 matrix subtraction */
@@ -197,7 +195,7 @@ static dmnsn_matrix2
dmnsn_matrix2_sub(dmnsn_matrix2 lhs, dmnsn_matrix2 rhs)
{
/* 4 additions */
- return dmnsn_matrix2_construct(
+ return dmnsn_new_matrix2(
lhs.n[0][0] - rhs.n[0][0], lhs.n[0][1] - rhs.n[0][1],
lhs.n[1][0] - rhs.n[1][0], lhs.n[1][1] - rhs.n[1][1]
);
@@ -208,7 +206,7 @@ static dmnsn_matrix2
dmnsn_matrix2_mul(dmnsn_matrix2 lhs, dmnsn_matrix2 rhs)
{
/* 8 multiplications, 4 additions */
- return dmnsn_matrix2_construct(
+ return dmnsn_new_matrix2(
lhs.n[0][0]*rhs.n[0][0] + lhs.n[0][1]*rhs.n[1][0],
lhs.n[0][0]*rhs.n[0][1] + lhs.n[0][1]*rhs.n[1][1],
lhs.n[1][0]*rhs.n[0][0] + lhs.n[1][1]*rhs.n[1][0],
diff --git a/libdimension/kD_splay_tree.c b/libdimension/kD_splay_tree.c
index 924d3a9..ca31b86 100644
--- a/libdimension/kD_splay_tree.c
+++ b/libdimension/kD_splay_tree.c
@@ -115,31 +115,31 @@ dmnsn_kD_splay_insert(dmnsn_kD_splay_tree *tree, dmnsn_object *object)
node->max = node->min;
dmnsn_vector corner;
- corner = dmnsn_vector_construct(object->min.x, object->min.y, object->max.z);
+ corner = dmnsn_new_vector(object->min.x, object->min.y, object->max.z);
corner = dmnsn_matrix_vector_mul(object->trans, corner);
dmnsn_kD_splay_node_swallow(node, corner, corner);
- corner = dmnsn_vector_construct(object->min.x, object->max.y, object->min.z);
+ corner = dmnsn_new_vector(object->min.x, object->max.y, object->min.z);
corner = dmnsn_matrix_vector_mul(object->trans, corner);
dmnsn_kD_splay_node_swallow(node, corner, corner);
- corner = dmnsn_vector_construct(object->min.x, object->max.y, object->max.z);
+ corner = dmnsn_new_vector(object->min.x, object->max.y, object->max.z);
corner = dmnsn_matrix_vector_mul(object->trans, corner);
dmnsn_kD_splay_node_swallow(node, corner, corner);
- corner = dmnsn_vector_construct(object->max.x, object->min.y, object->min.z);
+ corner = dmnsn_new_vector(object->max.x, object->min.y, object->min.z);
corner = dmnsn_matrix_vector_mul(object->trans, corner);
dmnsn_kD_splay_node_swallow(node, corner, corner);
- corner = dmnsn_vector_construct(object->max.x, object->min.y, object->max.z);
+ corner = dmnsn_new_vector(object->max.x, object->min.y, object->max.z);
corner = dmnsn_matrix_vector_mul(object->trans, corner);
dmnsn_kD_splay_node_swallow(node, corner, corner);
- corner = dmnsn_vector_construct(object->max.x, object->max.y, object->min.z);
+ corner = dmnsn_new_vector(object->max.x, object->max.y, object->min.z);
corner = dmnsn_matrix_vector_mul(object->trans, corner);
dmnsn_kD_splay_node_swallow(node, corner, corner);
- corner = dmnsn_vector_construct(object->max.x, object->max.y, object->max.z);
+ corner = dmnsn_new_vector(object->max.x, object->max.y, object->max.z);
corner = dmnsn_matrix_vector_mul(object->trans, corner);
dmnsn_kD_splay_node_swallow(node, corner, corner);
diff --git a/libdimension/objects.c b/libdimension/objects.c
index 845edfa..0a88561 100644
--- a/libdimension/objects.c
+++ b/libdimension/objects.c
@@ -42,8 +42,8 @@ dmnsn_new_sphere()
if (sphere) {
sphere->intersection_fn = &dmnsn_sphere_intersection_fn;
sphere->inside_fn = &dmnsn_sphere_inside_fn;
- sphere->min = dmnsn_vector_construct(-1.0, -1.0, -1.0);
- sphere->max = dmnsn_vector_construct(1.0, 1.0, 1.0);
+ sphere->min = dmnsn_new_vector(-1.0, -1.0, -1.0);
+ sphere->max = dmnsn_new_vector(1.0, 1.0, 1.0);
}
return sphere;
}
@@ -108,8 +108,8 @@ dmnsn_new_cube()
if (cube) {
cube->intersection_fn = &dmnsn_cube_intersection_fn;
cube->inside_fn = &dmnsn_cube_inside_fn;
- cube->min = dmnsn_vector_construct(-1.0, -1.0, -1.0);
- cube->max = dmnsn_vector_construct(1.0, 1.0, 1.0);
+ cube->min = dmnsn_new_vector(-1.0, -1.0, -1.0);
+ cube->max = dmnsn_new_vector(1.0, 1.0, 1.0);
}
return cube;
}
@@ -132,7 +132,7 @@ dmnsn_cube_intersection_fn(const dmnsn_object *cube, dmnsn_line line)
&& t_temp >= 0.0 && (t < 0.0 || t_temp < t))
{
t = t_temp;
- normal = dmnsn_vector_construct(-copysign(line.n.x, 1.0), 0.0, 0.0);
+ normal = dmnsn_new_vector(-copysign(line.n.x, 1.0), 0.0, 0.0);
}
/* x = 1.0 */
@@ -142,7 +142,7 @@ dmnsn_cube_intersection_fn(const dmnsn_object *cube, dmnsn_line line)
&& t_temp >= 0.0 && (t < 0.0 || t_temp < t))
{
t = t_temp;
- normal = dmnsn_vector_construct(-copysign(line.n.x, 1.0), 0.0, 0.0);
+ normal = dmnsn_new_vector(-copysign(line.n.x, 1.0), 0.0, 0.0);
}
}
@@ -154,7 +154,7 @@ dmnsn_cube_intersection_fn(const dmnsn_object *cube, dmnsn_line line)
&& t_temp >= 0.0 && (t < 0.0 || t_temp < t))
{
t = t_temp;
- normal = dmnsn_vector_construct(0.0, -copysign(line.n.y, 1.0), 0.0);
+ normal = dmnsn_new_vector(0.0, -copysign(line.n.y, 1.0), 0.0);
}
/* y = 1.0 */
@@ -164,7 +164,7 @@ dmnsn_cube_intersection_fn(const dmnsn_object *cube, dmnsn_line line)
&& t_temp >= 0.0 && (t < 0.0 || t_temp < t))
{
t = t_temp;
- normal = dmnsn_vector_construct(0.0, -copysign(line.n.y, 1.0), 0.0);
+ normal = dmnsn_new_vector(0.0, -copysign(line.n.y, 1.0), 0.0);
}
}
@@ -176,7 +176,7 @@ dmnsn_cube_intersection_fn(const dmnsn_object *cube, dmnsn_line line)
&& t_temp >= 0.0 && (t < 0.0 || t_temp < t))
{
t = t_temp;
- normal = dmnsn_vector_construct(0.0, 0.0, -copysign(line.n.z, 1.0));
+ normal = dmnsn_new_vector(0.0, 0.0, -copysign(line.n.z, 1.0));
}
/* z = 1.0 */
@@ -186,7 +186,7 @@ dmnsn_cube_intersection_fn(const dmnsn_object *cube, dmnsn_line line)
&& t_temp >= 0.0 && (t < 0.0 || t_temp < t))
{
t = t_temp;
- normal = dmnsn_vector_construct(0.0, 0.0, -copysign(line.n.z, 1.0));
+ normal = dmnsn_new_vector(0.0, 0.0, -copysign(line.n.z, 1.0));
}
}
diff --git a/libdimension/raytrace.c b/libdimension/raytrace.c
index 143c2bc..b37dff3 100644
--- a/libdimension/raytrace.c
+++ b/libdimension/raytrace.c
@@ -261,7 +261,7 @@ dmnsn_raytrace_scene_impl(dmnsn_progress *progress, dmnsn_scene *scene,
static dmnsn_line
dmnsn_line_add_epsilon(dmnsn_line l)
{
- return dmnsn_line_construct(
+ return dmnsn_new_line(
dmnsn_vector_add(
l.x0,
dmnsn_vector_mul(1.0e-9, l.n)
@@ -306,10 +306,7 @@ dmnsn_raytrace_light_ray(dmnsn_intersection *intersection, dmnsn_scene *scene,
*color = dmnsn_black;
dmnsn_vector x0 = dmnsn_line_point(intersection->ray, intersection->t);
- dmnsn_line shadow_ray = dmnsn_line_construct(
- x0,
- dmnsn_vector_sub(light->x0, x0)
- );
+ dmnsn_line shadow_ray = dmnsn_new_line(x0, dmnsn_vector_sub(light->x0, x0));
/* Add epsilon to avoid hitting ourselves with the shadow ray */
shadow_ray = dmnsn_line_add_epsilon(shadow_ray);
@@ -439,7 +436,7 @@ dmnsn_raytrace_shoot(dmnsn_line ray, dmnsn_scene *scene,
trans.filter = 0.0;
trans.trans = 0.0;
- dmnsn_line trans_ray = dmnsn_line_construct(
+ dmnsn_line trans_ray = dmnsn_new_line(
dmnsn_line_point(ray, intersection->t),
ray.n
);
diff --git a/tests/libdimension/kD_splay_tree.c b/tests/libdimension/kD_splay_tree.c
index eca684b..ea53550 100644
--- a/tests/libdimension/kD_splay_tree.c
+++ b/tests/libdimension/kD_splay_tree.c
@@ -34,14 +34,14 @@ main()
obj2 = dmnsn_new_object();
obj3 = dmnsn_new_object();
- obj1->min = dmnsn_vector_construct(0.0, 0.0, 0.0);
- obj1->max = dmnsn_vector_construct(1.0, 1.0, 1.0);
+ obj1->min = dmnsn_new_vector(0.0, 0.0, 0.0);
+ obj1->max = dmnsn_new_vector(1.0, 1.0, 1.0);
- obj2->min = dmnsn_vector_construct(-2.0, -2.0, -2.0);
- obj2->max = dmnsn_vector_construct(1.0, 1.0, 1.0);
+ obj2->min = dmnsn_new_vector(-2.0, -2.0, -2.0);
+ obj2->max = dmnsn_new_vector(1.0, 1.0, 1.0);
- obj3->min = dmnsn_vector_construct(-1.0, -1.0, -1.0);
- obj3->max = dmnsn_vector_construct(0.0, 0.0, 0.0);
+ obj3->min = dmnsn_new_vector(-1.0, -1.0, -1.0);
+ obj3->max = dmnsn_new_vector(0.0, 0.0, 0.0);
tree = dmnsn_new_kD_splay_tree();
diff --git a/tests/libdimension/tests.c b/tests/libdimension/tests.c
index c0bd11f..f632aa1 100644
--- a/tests/libdimension/tests.c
+++ b/tests/libdimension/tests.c
@@ -52,16 +52,16 @@ dmnsn_new_default_scene()
/* Set up the transformation matrix for the perspective camera */
dmnsn_matrix trans = dmnsn_scale_matrix(
- dmnsn_vector_construct(
+ dmnsn_new_vector(
((double)scene->canvas->x)/scene->canvas->y, 1.0, 1.0
)
);
trans = dmnsn_matrix_mul(
- dmnsn_translation_matrix(dmnsn_vector_construct(0.0, 0.0, -4.0)),
+ dmnsn_translation_matrix(dmnsn_new_vector(0.0, 0.0, -4.0)),
trans
);
trans = dmnsn_matrix_mul(
- dmnsn_rotation_matrix(dmnsn_vector_construct(0.0, 1.0, 0.0)),
+ dmnsn_rotation_matrix(dmnsn_new_vector(0.0, 1.0, 0.0)),
trans
);
@@ -94,7 +94,7 @@ dmnsn_new_default_scene()
return NULL;
}
- sphere->trans = dmnsn_scale_matrix(dmnsn_vector_construct(1.25, 1.25, 1.25));
+ sphere->trans = dmnsn_scale_matrix(dmnsn_new_vector(1.25, 1.25, 1.25));
dmnsn_object *cube = dmnsn_new_cube();
if (!cube) {
@@ -118,12 +118,12 @@ dmnsn_new_default_scene()
return NULL;
}
- cube->trans = dmnsn_rotation_matrix(dmnsn_vector_construct(0.75, 0.0, 0.0));
+ cube->trans = dmnsn_rotation_matrix(dmnsn_new_vector(0.75, 0.0, 0.0));
/* Now make a light */
dmnsn_light *light = dmnsn_new_point_light(
- dmnsn_vector_construct(-15.0, 20.0, 10.0),
+ dmnsn_new_vector(-15.0, 20.0, 10.0),
dmnsn_cyan
);
if (!light) {