summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--dimension/common.nonterminals2
-rw-r--r--dimension/common.rules34
-rw-r--r--dimension/common.terminals4
-rw-r--r--dimension/grammar.epilogue1
-rw-r--r--dimension/lexer.l2
-rw-r--r--dimension/parse.h1
-rw-r--r--dimension/realize.c19
-rw-r--r--tests/dimension/demo.pov23
-rwxr-xr-xtests/dimension/demo.sh30
9 files changed, 112 insertions, 4 deletions
diff --git a/dimension/common.nonterminals b/dimension/common.nonterminals
index ad95ccb..08a6141 100644
--- a/dimension/common.nonterminals
+++ b/dimension/common.nonterminals
@@ -44,6 +44,8 @@
%type <astnode> CYLINDER
%type <astnode> MAYBE_OPEN
%type <astnode> SPHERE
+%type <astnode> TORUS
+%type <astnode> TORUS_MODIFIERS
%type <astnode> INFINITE_SOLID_OBJECT
%type <astnode> PLANE
%type <astnode> CSG_OBJECT
diff --git a/dimension/common.rules b/dimension/common.rules
index 040f4a6..dc8d0b3 100644
--- a/dimension/common.rules
+++ b/dimension/common.rules
@@ -286,6 +286,7 @@ FINITE_SOLID_OBJECT: BOX
| CONE
| CYLINDER
| SPHERE
+ | TORUS
;
BOX: "box" "{"
@@ -328,6 +329,7 @@ MAYBE_OPEN: /* empty */ {
| "open" {
$$ = dmnsn_new_ast_integer(true);
}
+;
SPHERE: "sphere" "{"
VECTOR "," FLOAT
@@ -339,6 +341,38 @@ SPHERE: "sphere" "{"
}
;
+TORUS: "torus" "{"
+ FLOAT "," FLOAT
+ TORUS_MODIFIERS
+ "}"
+ {
+ dmnsn_astnode object = dmnsn_new_astnode2(DMNSN_AST_TORUS, @$, $3, $5);
+ $$ = dmnsn_new_astnode2(DMNSN_AST_OBJECT, @$, object, $6);
+ }
+;
+
+TORUS_MODIFIERS: /* empty */ {
+ $$ = dmnsn_new_astnode(DMNSN_AST_OBJECT_MODIFIERS, @$);
+ }
+ | TORUS_MODIFIERS OBJECT_MODIFIER {
+ $$ = $1;
+ dmnsn_array_push($$.children, &$2);
+ }
+ | TORUS_MODIFIERS "sturm" {
+ dmnsn_diagnostic(@2,
+ "WARNING: Dimension does not use 'sturm';"
+ " ignored.");
+ $$ = $1;
+ }
+ | TORUS_MODIFIERS "sturm" FLOAT {
+ dmnsn_diagnostic(@2,
+ "WARNING: Dimension does not use 'sturm';"
+ " ignored.");
+ dmnsn_delete_astnode($3);
+ $$ = $1;
+ }
+;
+
INFINITE_SOLID_OBJECT: PLANE
;
diff --git a/dimension/common.terminals b/dimension/common.terminals
index ffe13dc..256474f 100644
--- a/dimension/common.terminals
+++ b/dimension/common.terminals
@@ -421,7 +421,7 @@
%token DMNSN_T_STRLEN "strlen"
%token DMNSN_T_STRLWR
%token DMNSN_T_STRUPR
-%token DMNSN_T_STURM
+%token DMNSN_T_STURM "sturm"
%token DMNSN_T_SUBSTR
%token DMNSN_T_SUM
%token DMNSN_T_SUPERELLIPSOID
@@ -443,7 +443,7 @@
%token DMNSN_T_TILES
%token DMNSN_T_TOLERANCE
%token DMNSN_T_TOROIDAL
-%token DMNSN_T_TORUS
+%token DMNSN_T_TORUS "torus"
%token DMNSN_T_TRACE
%token DMNSN_T_TRANSFORM "transform"
%token DMNSN_T_TRANSLATE "translate"
diff --git a/dimension/grammar.epilogue b/dimension/grammar.epilogue
index 6e5a90b..a2bd743 100644
--- a/dimension/grammar.epilogue
+++ b/dimension/grammar.epilogue
@@ -142,6 +142,7 @@ dmnsn_astnode_string(dmnsn_astnode_type astnode_type)
dmnsn_astnode_map(DMNSN_AST_MERGE, "merge");
dmnsn_astnode_map(DMNSN_AST_PLANE, "plane");
dmnsn_astnode_map(DMNSN_AST_SPHERE, "sphere");
+ dmnsn_astnode_map(DMNSN_AST_TORUS, "torus");
dmnsn_astnode_map(DMNSN_AST_UNION, "union");
dmnsn_astnode_map(DMNSN_AST_OBJECT_MODIFIERS, "object-modifiers");
diff --git a/dimension/lexer.l b/dimension/lexer.l
index 56d165a..58a2dba 100644
--- a/dimension/lexer.l
+++ b/dimension/lexer.l
@@ -252,10 +252,12 @@ unsigned long wchar;
"sqrt" RETURN_TOKEN(DMNSN_T_SQRT);
"strcmp" RETURN_TOKEN(DMNSN_T_STRCMP);
"strlen" RETURN_TOKEN(DMNSN_T_STRLEN);
+"sturm" RETURN_TOKEN(DMNSN_T_STURM);
"t" RETURN_TOKEN(DMNSN_T_T);
"tan" RETURN_TOKEN(DMNSN_T_TAN);
"tanh" RETURN_TOKEN(DMNSN_T_TANH);
"texture" RETURN_TOKEN(DMNSN_T_TEXTURE);
+"torus" RETURN_TOKEN(DMNSN_T_TORUS);
"transform" RETURN_TOKEN(DMNSN_T_TRANSFORM);
"translate" RETURN_TOKEN(DMNSN_T_TRANSLATE);
"transmit" RETURN_TOKEN(DMNSN_T_TRANSMIT);
diff --git a/dimension/parse.h b/dimension/parse.h
index 556465e..482c4ad 100644
--- a/dimension/parse.h
+++ b/dimension/parse.h
@@ -56,6 +56,7 @@ typedef enum {
DMNSN_AST_MERGE,
DMNSN_AST_PLANE,
DMNSN_AST_SPHERE,
+ DMNSN_AST_TORUS,
DMNSN_AST_UNION,
DMNSN_AST_OBJECT_MODIFIERS,
diff --git a/dimension/realize.c b/dimension/realize.c
index b5f6e50..18de230 100644
--- a/dimension/realize.c
+++ b/dimension/realize.c
@@ -917,6 +917,22 @@ dmnsn_realize_sphere(dmnsn_astnode astnode)
}
static dmnsn_object *
+dmnsn_realize_torus(dmnsn_astnode astnode)
+{
+ dmnsn_assert(astnode.type == DMNSN_AST_TORUS, "Expected a torus.");
+
+ dmnsn_astnode major, minor;
+ dmnsn_array_get(astnode.children, 0, &major);
+ dmnsn_array_get(astnode.children, 1, &minor);
+
+ double R = dmnsn_realize_float(major);
+ double r = dmnsn_realize_float(minor);
+
+ dmnsn_object *torus = dmnsn_new_torus(R, r);
+ return torus;
+}
+
+static dmnsn_object *
dmnsn_realize_plane(dmnsn_astnode astnode)
{
dmnsn_assert(astnode.type == DMNSN_AST_PLANE, "Expected a plane.");
@@ -1064,6 +1080,9 @@ dmnsn_realize_object(dmnsn_astnode astnode, dmnsn_array *lights)
case DMNSN_AST_SPHERE:
object = dmnsn_realize_sphere(onode);
break;
+ case DMNSN_AST_TORUS:
+ object = dmnsn_realize_torus(onode);
+ break;
case DMNSN_AST_UNION:
object = dmnsn_realize_union(onode, modifiers, lights);
break;
diff --git a/tests/dimension/demo.pov b/tests/dimension/demo.pov
index 0ec053b..1d0ff53 100644
--- a/tests/dimension/demo.pov
+++ b/tests/dimension/demo.pov
@@ -86,6 +86,29 @@ union {
rotate -45*x
}
+union {
+ torus {
+ 0.15, 0.05
+ translate -y
+ sturm off
+ }
+ torus {
+ 0.15, 0.05
+ }
+ torus {
+ 0.15, 0.05
+ translate y
+ }
+
+ pigment {
+ color rgb <0, 0, 1>
+ }
+ finish {
+ ambient 1
+ }
+ rotate -45*x
+}
+
plane {
y, -2
pigment {
diff --git a/tests/dimension/demo.sh b/tests/dimension/demo.sh
index fc37226..20eebb9 100755
--- a/tests/dimension/demo.sh
+++ b/tests/dimension/demo.sh
@@ -102,13 +102,39 @@ demo_exp=$(echo -n \
(rotation (vector (integer -45) (integer 0) (integer 0)
(integer 0) (integer 0))))))
(object
+ (union
+ (object
+ (torus (float 0.15) (float 0.05))
+ (object-modifiers
+ (transformation
+ (translation (vector (integer 0) (integer -1) (integer 0)
+ (integer 0) (integer 0))))))
+ (object
+ (torus (float 0.15) (float 0.05))
+ object-modifiers)
+ (object
+ (torus (float 0.15) (float 0.05))
+ (object-modifiers
+ (transformation
+ (translation (vector (integer 0) (integer 1) (integer 0)
+ (integer 0) (integer 0)))))))
+ (object-modifiers
+ (pigment
+ (vector (integer 0) (integer 0) (integer 1) (integer 0) (integer 0))
+ pigment-modifiers)
+ (finish
+ (ambient
+ (vector (integer 1) (integer 1) (integer 1) (integer 1) (integer 1))))
+ (transformation
+ (rotation (vector (integer -45) (integer 0) (integer 0)
+ (integer 0) (integer 0))))))
+ (object
(plane
(vector (integer 0) (integer 1) (integer 0) (integer 0) (integer 0))
(integer -2))
(object-modifiers
(pigment
- (vector (integer 1) (integer 1) (integer 1)
- (integer 0) (integer 0))
+ (vector (integer 1) (integer 1) (integer 1) (integer 0) (integer 0))
pigment-modifiers))))' \
| tr '\n' ' ' | sed -r 's/[[:space:]]+/ /g')