diff options
Diffstat (limited to 'dimension')
-rw-r--r-- | dimension/common.nonterminals | 2 | ||||
-rw-r--r-- | dimension/common.rules | 34 | ||||
-rw-r--r-- | dimension/common.terminals | 4 | ||||
-rw-r--r-- | dimension/grammar.epilogue | 1 | ||||
-rw-r--r-- | dimension/lexer.l | 2 | ||||
-rw-r--r-- | dimension/parse.h | 1 | ||||
-rw-r--r-- | dimension/realize.c | 19 |
7 files changed, 61 insertions, 2 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; |