diff options
author | don bright <hugh.m.bright@gmail.com> | 2011-11-05 18:17:06 (GMT) |
---|---|---|
committer | don bright <hugh.m.bright@gmail.com> | 2011-11-05 18:17:06 (GMT) |
commit | 273672c418e4ff2400a9cbc1dacb510a2452b734 (patch) | |
tree | 68d4cba8d98064482c1cdf68b514351468864b34 /src | |
parent | 88b8080f30d6ca1a9a74b8005a7408d4066f481b (diff) | |
parent | d14a24a2b63d7d3815e02a79ef9dacd76cd01f4d (diff) |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'src')
-rw-r--r-- | src/CGALEvaluator.cc | 35 | ||||
-rw-r--r-- | src/CGAL_Nef_polyhedron.cc | 13 | ||||
-rw-r--r-- | src/builtin.h | 2 | ||||
-rw-r--r-- | src/context.cc | 20 | ||||
-rw-r--r-- | src/lexer.l | 9 | ||||
-rw-r--r-- | src/mainwin.cc | 17 | ||||
-rw-r--r-- | src/openscad.cc | 16 |
7 files changed, 54 insertions, 58 deletions
diff --git a/src/CGALEvaluator.cc b/src/CGALEvaluator.cc index 550f300..797434f 100644 --- a/src/CGALEvaluator.cc +++ b/src/CGALEvaluator.cc @@ -56,20 +56,29 @@ void CGALEvaluator::process(CGAL_Nef_polyhedron &target, const CGAL_Nef_polyhedr if (src.empty()) return; // Empty polyhedron. This can happen for e.g. square([0,0]) if (target.dim != src.dim) return; // If someone tries to e.g. union 2d and 3d objects - switch (op) { - case CGE_UNION: - target += src; - break; - case CGE_INTERSECTION: - target *= src; - break; - case CGE_DIFFERENCE: - target -= src; - break; - case CGE_MINKOWSKI: - target.minkowski(src); - break; + CGAL::Failure_behaviour old_behaviour = CGAL::set_error_behaviour(CGAL::THROW_EXCEPTION); + try { + switch (op) { + case CGE_UNION: + target += src; + break; + case CGE_INTERSECTION: + target *= src; + break; + case CGE_DIFFERENCE: + target -= src; + break; + case CGE_MINKOWSKI: + target.minkowski(src); + break; + } + } + catch (CGAL::Assertion_exception e) { + // union && difference assert triggered by testdata/scad/bugs/rotate-diff-nonmanifold-crash.scad + std::string opstr = op == CGE_UNION ? "union" : op == CGE_INTERSECTION ? "intersection" : op == CGE_DIFFERENCE ? "difference" : op == CGE_MINKOWSKI ? "minkowski" : "UNKNOWN"; + PRINTF("CGAL error in CGAL_Nef_polyhedron's %s operator: %s", opstr.c_str(), e.what()); } + CGAL::set_error_behaviour(old_behaviour); } /*! diff --git a/src/CGAL_Nef_polyhedron.cc b/src/CGAL_Nef_polyhedron.cc index 975c9a4..2538b64 100644 --- a/src/CGAL_Nef_polyhedron.cc +++ b/src/CGAL_Nef_polyhedron.cc @@ -6,8 +6,6 @@ #include "dxfdata.h" #include "dxftess.h" #include <CGAL/minkowski_sum_3.h> -#include <CGAL/assertions_behaviour.h> -#include <CGAL/exceptions.h> CGAL_Nef_polyhedron& CGAL_Nef_polyhedron::operator+=(const CGAL_Nef_polyhedron &other) { @@ -34,15 +32,8 @@ extern CGAL_Nef_polyhedron2 minkowski2(const CGAL_Nef_polyhedron2 &a, const CGAL CGAL_Nef_polyhedron &CGAL_Nef_polyhedron::minkowski(const CGAL_Nef_polyhedron &other) { - CGAL::Failure_behaviour old_behaviour = CGAL::set_error_behaviour(CGAL::THROW_EXCEPTION); - try { - if (this->dim == 2) (*this->p2) = minkowski2(*this->p2, *other.p2); - else if (this->dim == 3) (*this->p3) = CGAL::minkowski_sum_3(*this->p3, *other.p3); - } - catch (CGAL::Assertion_exception e) { - PRINTF("CGAL error in minkowski %s", e.what()); - CGAL::set_error_behaviour(old_behaviour); - } + if (this->dim == 2) (*this->p2) = minkowski2(*this->p2, *other.p2); + else if (this->dim == 3) (*this->p3) = CGAL::minkowski_sum_3(*this->p3, *other.p3); return *this; } diff --git a/src/builtin.h b/src/builtin.h index ae526f2..643966b 100644 --- a/src/builtin.h +++ b/src/builtin.h @@ -26,4 +26,6 @@ extern void register_builtin_dxf_linear_extrude(); extern void register_builtin_dxf_rotate_extrude(); extern void initialize_builtin_dxf_dim(); +extern void register_builtin(class Context &ctx); + #endif diff --git a/src/context.cc b/src/context.cc index b4983f6..47b8a78 100644 --- a/src/context.cc +++ b/src/context.cc @@ -193,3 +193,23 @@ std::string Context::getAbsolutePath(const std::string &filename) const return filename; } } + +void register_builtin(Context &ctx) +{ + ctx.functions_p = &builtin_functions; + ctx.modules_p = &builtin_modules; + ctx.set_variable("$fn", Value(0.0)); + ctx.set_variable("$fs", Value(1.0)); + ctx.set_variable("$fa", Value(12.0)); + ctx.set_variable("$t", Value(0.0)); + + Value zero3; + zero3.type = Value::VECTOR; + zero3.append(new Value(0.0)); + zero3.append(new Value(0.0)); + zero3.append(new Value(0.0)); + ctx.set_variable("$vpt", zero3); + ctx.set_variable("$vpr", zero3); + + ctx.set_constant("PI",Value(M_PI)); +} diff --git a/src/lexer.l b/src/lexer.l index d9ccd76..2760b07 100644 --- a/src/lexer.l +++ b/src/lexer.l @@ -88,7 +88,8 @@ QString filepath; %x comment string %x include -DIGIT [0-9] +D [0-9] +E [Ee][+-]?{D}+ %% @@ -155,8 +156,10 @@ use[ \t\r\n>]*"<"[^\t\r\n>]+">" { "false" return TOK_FALSE; "undef" return TOK_UNDEF; -{DIGIT}+|{DIGIT}*\.{DIGIT}+|{DIGIT}+\.{DIGIT}* { parserlval.number = QString(yytext).toDouble(); return TOK_NUMBER; } -"$"?[a-zA-Z0-9_]+ { parserlval.text = strdup(yytext); return TOK_ID; } +{D}+{E}? | +{D}*\.{D}+{E}? | +{D}+\.{D}*{E}? { parserlval.number = QString(yytext).toDouble(); return TOK_NUMBER; } +"$"?[a-zA-Z0-9_]+ { parserlval.text = strdup(yytext); return TOK_ID; } \" { BEGIN(string); stringcontents = new QString(); } <string>{ diff --git a/src/mainwin.cc b/src/mainwin.cc index 9944f67..a6f5be6 100644 --- a/src/mainwin.cc +++ b/src/mainwin.cc @@ -143,22 +143,7 @@ MainWindow::MainWindow(const QString &filename) { setupUi(this); - root_ctx.functions_p = &builtin_functions; - root_ctx.modules_p = &builtin_modules; - root_ctx.set_variable("$fn", Value(0.0)); - root_ctx.set_variable("$fs", Value(1.0)); - root_ctx.set_variable("$fa", Value(12.0)); - root_ctx.set_variable("$t", Value(0.0)); - - root_ctx.set_constant("PI",Value(M_PI)); - - Value zero3; - zero3.type = Value::VECTOR; - zero3.append(new Value(0.0)); - zero3.append(new Value(0.0)); - zero3.append(new Value(0.0)); - root_ctx.set_variable("$vpt", zero3); - root_ctx.set_variable("$vpr", zero3); + register_builtin(root_ctx); root_module = NULL; absolute_root_node = NULL; diff --git a/src/openscad.cc b/src/openscad.cc index 9b45d21..84d6263 100644 --- a/src/openscad.cc +++ b/src/openscad.cc @@ -260,21 +260,7 @@ int main(int argc, char **argv) #ifdef ENABLE_CGAL Context root_ctx; - root_ctx.functions_p = &builtin_functions; - root_ctx.modules_p = &builtin_modules; - root_ctx.set_variable("$fn", Value(0.0)); - root_ctx.set_variable("$fs", Value(1.0)); - root_ctx.set_variable("$fa", Value(12.0)); - root_ctx.set_variable("$t", Value(0.0)); - - Value zero3; - zero3.type = Value::VECTOR; - zero3.append(new Value(0.0)); - zero3.append(new Value(0.0)); - zero3.append(new Value(0.0)); - root_ctx.set_variable("$vpt", zero3); - root_ctx.set_variable("$vpr", zero3); - + register_builtin(root_ctx); AbstractModule *root_module; ModuleInstantiation root_inst; |