summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--RELEASE_NOTES2
-rw-r--r--doc/TODO.txt2
-rw-r--r--src/CGALEvaluator.cc35
-rw-r--r--src/CGAL_Nef_polyhedron.cc13
-rw-r--r--src/builtin.h2
-rw-r--r--src/context.cc20
-rw-r--r--src/lexer.l9
-rw-r--r--src/mainwin.cc17
-rw-r--r--src/openscad.cc16
-rw-r--r--testdata/scad/bugs/rotate-diff-nonmanifold-crash.scad9
-rw-r--r--testdata/scad/misc/builtin-tests.scad1
-rw-r--r--testdata/scad/misc/parser-tests.scad7
-rw-r--r--tests/CMakeLists.txt4
-rw-r--r--tests/cgalpngtest.cc21
-rw-r--r--tests/cgaltest.cc21
-rw-r--r--tests/csgtermtest.cc21
-rw-r--r--tests/csgtestcore.cc16
-rw-r--r--tests/csgtexttest.cc21
-rw-r--r--tests/dumptest.cc16
-rw-r--r--tests/echotest.cc16
-rw-r--r--tests/regression/echotest/builtin-tests-expected.txt1
-rw-r--r--tests/regression/echotest/parser-tests-expected.txt5
22 files changed, 101 insertions, 174 deletions
diff --git a/RELEASE_NOTES b/RELEASE_NOTES
index 3e10eec..cc6d99e 100644
--- a/RELEASE_NOTES
+++ b/RELEASE_NOTES
@@ -14,6 +14,7 @@ o The version() function will return the OpenSCAD version as a vector, e.g. [201
o The version_num() function will return the OpenSCAD version as a number, e.g. 20110923
o Added PI constant.
o Now uses standard shortcuts for save and reload on Linux and Windows. F2/F3 will still work but is deprecated.
+o Number literals in scientific notation are now accepted by the parser
Bugfixes:
o square() crashed if any of the dimensions were zero
@@ -21,6 +22,7 @@ o Flush Caches didn't flush cached USE'd modules
o STL export should be a bit more robust
o Dropping a file into the editor under Windows didn't work (double C:/C:/ problem)
o On some platforms it was possible to insertion rich text in the editor, causing confusion.
+o Less crashes due to CGAL assertions
Deprecations:
o dxf_linear_extrude() and dxf_rotate_extrude() are now deprecated.
diff --git a/doc/TODO.txt b/doc/TODO.txt
index 26dd6c8..c869681 100644
--- a/doc/TODO.txt
+++ b/doc/TODO.txt
@@ -230,7 +230,5 @@ o Use a logging framework to get debugging/info output more under control?
MISC
----
-o Streamline the cmd-line interface a bit
- - Implicit output file format
o Write checklists for typical extension work (add new module, add new function)
-> make sure new test files are added
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;
diff --git a/testdata/scad/bugs/rotate-diff-nonmanifold-crash.scad b/testdata/scad/bugs/rotate-diff-nonmanifold-crash.scad
new file mode 100644
index 0000000..754a2a6
--- /dev/null
+++ b/testdata/scad/bugs/rotate-diff-nonmanifold-crash.scad
@@ -0,0 +1,9 @@
+difference() {
+ rotate_extrude($fn=5) translate([4,0,0]) square([10, 10], center=true);
+ translate([6,6,6]) sphere(r=10);
+}
+
+union() {
+ rotate_extrude($fn=5) translate([4,0,0]) square([10, 10], center=true);
+ cylinder(h=5,r=3);
+}
diff --git a/testdata/scad/misc/builtin-tests.scad b/testdata/scad/misc/builtin-tests.scad
new file mode 100644
index 0000000..6b5eac1
--- /dev/null
+++ b/testdata/scad/misc/builtin-tests.scad
@@ -0,0 +1 @@
+p = PI; echo(p);
diff --git a/testdata/scad/misc/parser-tests.scad b/testdata/scad/misc/parser-tests.scad
new file mode 100644
index 0000000..03cbded
--- /dev/null
+++ b/testdata/scad/misc/parser-tests.scad
@@ -0,0 +1,7 @@
+// Number literals
+
+a = .1; echo(a);
+b = 2.; echo(b);
+c = 11e+2; echo(c);
+d = 21.e-3; echo(d);
+e = .11e-12; echo(e);
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 259ec76..3167792 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -353,7 +353,9 @@ list(APPEND DUMPTEST_FILES ${MINIMAL_FILES}
list(APPEND ECHO_FILES
${CMAKE_SOURCE_DIR}/../testdata/scad/minimal/echo.scad
- ${CMAKE_SOURCE_DIR}/../testdata/scad/features/echo-tests.scad)
+ ${CMAKE_SOURCE_DIR}/../testdata/scad/features/echo-tests.scad
+ ${CMAKE_SOURCE_DIR}/../testdata/scad/misc/parser-tests.scad
+ ${CMAKE_SOURCE_DIR}/../testdata/scad/misc/builtin-tests.scad)
# Add echotest tests to CTest
add_cmdline_test(echotest txt ${ECHO_FILES})
diff --git a/tests/cgalpngtest.cc b/tests/cgalpngtest.cc
index 734f6eb..bb65fa0 100644
--- a/tests/cgalpngtest.cc
+++ b/tests/cgalpngtest.cc
@@ -1,6 +1,7 @@
/*
- * OpenSCAD (www.openscad.at)
- * Copyright (C) 2009 Clifford Wolf <clifford@clifford.at>
+ * OpenSCAD (www.openscad.org)
+ * Copyright (C) 2009-2011 Clifford Wolf <clifford@clifford.at> and
+ * Marius Kintel <marius@kintel.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -127,21 +128,7 @@ int main(int argc, char **argv)
}
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;
diff --git a/tests/cgaltest.cc b/tests/cgaltest.cc
index 2c83cc8..242b7b7 100644
--- a/tests/cgaltest.cc
+++ b/tests/cgaltest.cc
@@ -1,6 +1,7 @@
/*
- * OpenSCAD (www.openscad.at)
- * Copyright (C) 2009 Clifford Wolf <clifford@clifford.at>
+ * OpenSCAD (www.openscad.org)
+ * Copyright (C) 2009-2011 Clifford Wolf <clifford@clifford.at> and
+ * Marius Kintel <marius@kintel.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -111,21 +112,7 @@ int main(int argc, char **argv)
}
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;
diff --git a/tests/csgtermtest.cc b/tests/csgtermtest.cc
index 98134f7..08002e2 100644
--- a/tests/csgtermtest.cc
+++ b/tests/csgtermtest.cc
@@ -1,6 +1,7 @@
/*
- * OpenSCAD (www.openscad.at)
- * Copyright (C) 2009 Clifford Wolf <clifford@clifford.at>
+ * OpenSCAD (www.openscad.org)
+ * Copyright (C) 2009-2011 Clifford Wolf <clifford@clifford.at> and
+ * Marius Kintel <marius@kintel.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -96,21 +97,7 @@ int main(int argc, char **argv)
}
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;
diff --git a/tests/csgtestcore.cc b/tests/csgtestcore.cc
index 2390f06..8460a59 100644
--- a/tests/csgtestcore.cc
+++ b/tests/csgtestcore.cc
@@ -106,21 +106,7 @@ int csgtestcore(int argc, char *argv[], test_type_e test_type)
}
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;
diff --git a/tests/csgtexttest.cc b/tests/csgtexttest.cc
index fe94497..afa5bbe 100644
--- a/tests/csgtexttest.cc
+++ b/tests/csgtexttest.cc
@@ -1,6 +1,7 @@
/*
- * OpenSCAD (www.openscad.at)
- * Copyright (C) 2009 Clifford Wolf <clifford@clifford.at>
+ * OpenSCAD (www.openscad.org)
+ * Copyright (C) 2009-2011 Clifford Wolf <clifford@clifford.at> and
+ * Marius Kintel <marius@kintel.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -99,21 +100,7 @@ int main(int argc, char **argv)
}
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;
diff --git a/tests/dumptest.cc b/tests/dumptest.cc
index 8e48d24..7344f95 100644
--- a/tests/dumptest.cc
+++ b/tests/dumptest.cc
@@ -118,21 +118,7 @@ int main(int argc, char **argv)
}
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;
diff --git a/tests/echotest.cc b/tests/echotest.cc
index 046f883..329aac2 100644
--- a/tests/echotest.cc
+++ b/tests/echotest.cc
@@ -104,21 +104,7 @@ int main(int argc, char **argv)
}
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;
diff --git a/tests/regression/echotest/builtin-tests-expected.txt b/tests/regression/echotest/builtin-tests-expected.txt
new file mode 100644
index 0000000..e8b2027
--- /dev/null
+++ b/tests/regression/echotest/builtin-tests-expected.txt
@@ -0,0 +1 @@
+ECHO: 3.141592653589793
diff --git a/tests/regression/echotest/parser-tests-expected.txt b/tests/regression/echotest/parser-tests-expected.txt
new file mode 100644
index 0000000..fb04907
--- /dev/null
+++ b/tests/regression/echotest/parser-tests-expected.txt
@@ -0,0 +1,5 @@
+ECHO: 0.1
+ECHO: 2
+ECHO: 1100
+ECHO: 0.021
+ECHO: 1.1e-13
contact: Jan Huwald // Impressum