summaryrefslogtreecommitdiffstats
path: root/dimension
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2010-07-03 22:35:59 -0600
committerTavian Barnes <tavianator@gmail.com>2010-07-03 22:35:59 -0600
commitf0d866e2ad137b339eae91c49ce22630f3a9adf9 (patch)
treeadcedd46c6f5e81bf392fe5712d8081e217c0bac /dimension
parent2b5d6e5f42f625049e3f9df765e0cf3fbecc6520 (diff)
downloaddimension-f0d866e2ad137b339eae91c49ce22630f3a9adf9.tar.xz
New dmnsn_radians() and dmnsn_degrees() conversion functions.
Diffstat (limited to 'dimension')
-rw-r--r--dimension/parse.c14
-rw-r--r--dimension/realize.c8
2 files changed, 9 insertions, 13 deletions
diff --git a/dimension/parse.c b/dimension/parse.c
index fc067cf..7b33b1d 100644
--- a/dimension/parse.c
+++ b/dimension/parse.c
@@ -564,7 +564,7 @@ dmnsn_eval_zeroary(dmnsn_astnode astnode, dmnsn_symbol_table *symtable)
switch (astnode.type) {
case DMNSN_AST_PI:
- dmnsn_make_ast_float(&ret, 4*atan(1.0));
+ dmnsn_make_ast_float(&ret, M_PI);
break;
case DMNSN_AST_TRUE:
dmnsn_make_ast_integer(&ret, 1);
@@ -736,7 +736,7 @@ dmnsn_eval_unary(dmnsn_astnode astnode, dmnsn_symbol_table *symtable)
dmnsn_make_ast_float(&ret, cosh(n));
break;
case DMNSN_AST_DEGREES:
- dmnsn_make_ast_float(&ret, n*45.0/atan(1.0));
+ dmnsn_make_ast_float(&ret, dmnsn_degrees(n));
break;
case DMNSN_AST_EXP:
dmnsn_make_ast_float(&ret, exp(n));
@@ -754,7 +754,7 @@ dmnsn_eval_unary(dmnsn_astnode astnode, dmnsn_symbol_table *symtable)
dmnsn_make_ast_float(&ret, log(n)/log(10.0));
break;
case DMNSN_AST_RADIANS:
- dmnsn_make_ast_float(&ret, n*atan(1.0)/45.0);
+ dmnsn_make_ast_float(&ret, dmnsn_radians(n));
break;
case DMNSN_AST_SIN:
dmnsn_make_ast_float(&ret, sin(n));
@@ -840,7 +840,7 @@ dmnsn_eval_unary(dmnsn_astnode astnode, dmnsn_symbol_table *symtable)
dmnsn_make_ast_float(&ret, cosh(n));
break;
case DMNSN_AST_DEGREES:
- dmnsn_make_ast_float(&ret, n*45.0/atan(1.0));
+ dmnsn_make_ast_float(&ret, dmnsn_degrees(n));
break;
case DMNSN_AST_EXP:
dmnsn_make_ast_float(&ret, exp(n));
@@ -858,7 +858,7 @@ dmnsn_eval_unary(dmnsn_astnode astnode, dmnsn_symbol_table *symtable)
dmnsn_make_ast_float(&ret, log(n)/log(10.0));
break;
case DMNSN_AST_RADIANS:
- dmnsn_make_ast_float(&ret, n*atan(1.0)/45.0);
+ dmnsn_make_ast_float(&ret, dmnsn_radians(n));
break;
case DMNSN_AST_SIN:
dmnsn_make_ast_float(&ret, sin(n));
@@ -1141,7 +1141,7 @@ dmnsn_eval_binary(dmnsn_astnode astnode, dmnsn_symbol_table *symtable)
az.type == DMNSN_AST_INTEGER ? *(long *)az.ptr : *(double *)az.ptr
);
- axis = dmnsn_vector_mul(atan(1.0)/45.0, axis);
+ axis = dmnsn_vector_mul(dmnsn_radians(1.0), axis);
r = dmnsn_transform_vector(dmnsn_rotation_matrix(axis), r);
ret = dmnsn_copy_astnode(astnode);
@@ -1247,7 +1247,7 @@ dmnsn_eval_binary(dmnsn_astnode astnode, dmnsn_symbol_table *symtable)
az.type == DMNSN_AST_INTEGER ? *(long *)az.ptr : *(double *)az.ptr
);
- axis = dmnsn_vector_mul(atan(1.0)/45.0, axis);
+ axis = dmnsn_vector_mul(dmnsn_radians(1.0), axis);
r = dmnsn_transform_vector(
dmnsn_rotation_matrix(dmnsn_new_vector(axis.x, 0.0, 0.0)),
diff --git a/dimension/realize.c b/dimension/realize.c
index 563327c..967c5db 100644
--- a/dimension/realize.c
+++ b/dimension/realize.c
@@ -142,13 +142,11 @@ dmnsn_realize_rotation(dmnsn_astnode astnode)
{
dmnsn_assert(astnode.type == DMNSN_AST_ROTATION, "Expected a rotation.");
- const double deg2rad = atan(1.0)/45.0;
-
dmnsn_astnode angle_node;
dmnsn_array_get(astnode.children, 0, &angle_node);
dmnsn_vector angle = dmnsn_vector_mul(
- deg2rad,
+ dmnsn_radians(1.0),
dmnsn_realize_vector(angle_node)
);
@@ -266,8 +264,6 @@ dmnsn_realize_camera(dmnsn_astnode astnode)
{
dmnsn_assert(astnode.type == DMNSN_AST_CAMERA, "Expected a camera.");
- const double deg2rad = atan(1.0)/45.0;
-
dmnsn_astnode_type camera_type = DMNSN_AST_PERSPECTIVE;
dmnsn_vector location = dmnsn_new_vector(0.0, 0.0, 0.0);
dmnsn_vector direction = dmnsn_new_vector(0.0, 0.0, 1.0);
@@ -363,7 +359,7 @@ dmnsn_realize_camera(dmnsn_astnode astnode)
case DMNSN_AST_ANGLE:
{
dmnsn_array_get(item->children, 0, &child);
- double angle = deg2rad*dmnsn_realize_float(child);
+ double angle = dmnsn_radians(dmnsn_realize_float(child));
direction = dmnsn_vector_mul(
0.5*dmnsn_vector_norm(right)/tan(angle/2.0),
dmnsn_vector_normalize(direction)