diff options
25 files changed, 180 insertions, 38 deletions
| diff --git a/openscad.appdata.xml b/openscad.appdata.xml index 8334d37..0378d15 100644 --- a/openscad.appdata.xml +++ b/openscad.appdata.xml @@ -10,7 +10,7 @@   </description>   <screenshots>    <screenshot type="default" width="800" height="437">http://www.openscad.org/images/appdata-screenshot-1.png</screenshot> -  <screenshot type="default" width="800" height="465">http://www.openscad.org/images/appdata-screenshot-2.png</screenshot> +  <screenshot width="800" height="465">http://www.openscad.org/images/appdata-screenshot-2.png</screenshot>   </screenshots>   <url type="homepage">http://www.openscad.org/</url>  </application> diff --git a/openscad.pro b/openscad.pro index ec5af20..5c39928 100644 --- a/openscad.pro +++ b/openscad.pro @@ -206,6 +206,7 @@ HEADERS += src/typedefs.h \             src/OpenCSGWarningDialog.h \             src/AboutDialog.h \             src/builtin.h \ +           src/calc.h \             src/context.h \             src/modcontext.h \             src/evalcontext.h \ @@ -324,6 +325,7 @@ SOURCES += src/version_check.cc \             src/AutoUpdater.cc \             \             src/builtin.cc \ +           src/calc.cc \             src/export.cc \             src/export_png.cc \             src/import.cc \ @@ -416,10 +418,18 @@ applications.path = $$PREFIX/share/applications  applications.files = icons/openscad.desktop  INSTALLS += applications +appdata.path = $$PREFIX/share/appdata +appdata.files = openscad.appdata.xml +INSTALLS += appdata +  icons.path = $$PREFIX/share/pixmaps  icons.files = icons/openscad.png  INSTALLS += icons +man.path = $$PREFIX/share/man/man1 +man.files = doc/openscad.1 +INSTALLS += man +  CONFIG(winconsole) {    include(winconsole.pri)  } diff --git a/src/PolySetCGALEvaluator.cc b/src/PolySetCGALEvaluator.cc index a2d896d..0b57de1 100644 --- a/src/PolySetCGALEvaluator.cc +++ b/src/PolySetCGALEvaluator.cc @@ -13,10 +13,10 @@  #include "dxfdata.h"  #include "dxftess.h"  #include "module.h" +#include "calc.h"  #include "svg.h"  #include "printutils.h" -#include "openscad.h" // get_fragments_from_r()  #include <boost/foreach.hpp>  #include <vector> @@ -469,7 +469,7 @@ PolySet *PolySetCGALEvaluator::rotateDxfData(const RotateExtrudeNode &node, DxfD  			}  		} -		int fragments = get_fragments_from_r(max_x-min_x, node.fn, node.fs, node.fa); +		int fragments = Calc::get_fragments_from_r(max_x-min_x, node.fn, node.fs, node.fa);  		double ***points;  		points = new double**[fragments]; diff --git a/src/calc.cc b/src/calc.cc new file mode 100644 index 0000000..bdae085 --- /dev/null +++ b/src/calc.cc @@ -0,0 +1,40 @@ +/* + *  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 + *  the Free Software Foundation; either version 2 of the License, or + *  (at your option) any later version. + * + *  As a special exception, you have permission to link this program + *  with the CGAL library and distribute executables, as long as you + *  follow the requirements of the GNU GPL in regard to all of the + *  software in the executable aside from CGAL. + * + *  This program is distributed in the hope that it will be useful, + *  but WITHOUT ANY WARRANTY; without even the implied warranty of + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + *  GNU General Public License for more details. + * + *  You should have received a copy of the GNU General Public License + *  along with this program; if not, write to the Free Software + *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA + * + */ + +#include "calc.h" +#include "grid.h" + +/*! +	Returns the number of subdivision of a whole circle, given radius and +	the three special variables $fn, $fs and $fa +*/ +int Calc::get_fragments_from_r(double r, double fn, double fs, double fa) +{ +	if (r < GRID_FINE) return 3; +	if (fn > 0.0) return (int)(fn >= 3 ? fn : 3); +	return (int)ceil(fmax(fmin(360.0 / fa, r*2*M_PI / fs), 5)); +} + diff --git a/src/calc.h b/src/calc.h new file mode 100644 index 0000000..1ac9e17 --- /dev/null +++ b/src/calc.h @@ -0,0 +1,8 @@ +#ifndef CALC_H_ +#define CALC_H_ + +namespace Calc { +	int get_fragments_from_r(double r, double fn, double fs, double fa); +} + +#endif diff --git a/src/dxfdata.cc b/src/dxfdata.cc index 8415228..9b61b93 100644 --- a/src/dxfdata.cc +++ b/src/dxfdata.cc @@ -28,7 +28,7 @@  #include "grid.h"  #include "printutils.h"  #include "handle_dep.h" -#include "openscad.h" // get_fragments_from_r() +#include "calc.h"  #include <fstream>  #include "mathc99.h" @@ -189,7 +189,7 @@ DxfData::DxfData(double fn, double fs, double fa,  				}  			}  			else if (mode == "CIRCLE") { -				int n = get_fragments_from_r(radius, fn, fs, fa); +				int n = Calc::get_fragments_from_r(radius, fn, fs, fa);  				Vector2d center(xverts[0], yverts[0]);  				for (int i = 0; i < n; i++) {  					double a1 = (2*M_PI*i)/n; @@ -200,7 +200,7 @@ DxfData::DxfData(double fn, double fs, double fa,  			}  			else if (mode == "ARC") {  				Vector2d center(xverts[0], yverts[0]); -				int n = get_fragments_from_r(radius, fn, fs, fa); +				int n = Calc::get_fragments_from_r(radius, fn, fs, fa);  				while (arc_start_angle > arc_stop_angle)  					arc_stop_angle += 360.0;  				n = (int)ceil(n * (arc_stop_angle-arc_start_angle) / 360); @@ -237,7 +237,7 @@ DxfData::DxfData(double fn, double fs, double fa,  				// the ratio stored in 'radius; due to the parser code not checking entity type  				double r_minor = r_major * radius;  				double sweep_angle = ellipse_stop_angle-ellipse_start_angle; -				int n = get_fragments_from_r(r_major, fn, fs, fa); +				int n = Calc::get_fragments_from_r(r_major, fn, fs, fa);  				n = (int)ceil(n * sweep_angle / (2 * M_PI));  //				Vector2d p1;  				Vector2d p1; p1 << 0,0; diff --git a/src/linearextrude.cc b/src/linearextrude.cc index c5d4529..1812504 100644 --- a/src/linearextrude.cc +++ b/src/linearextrude.cc @@ -32,7 +32,7 @@  #include "fileutils.h"  #include "builtin.h"  #include "PolySetEvaluator.h" -#include "openscad.h" // get_fragments_from_r() +#include "calc.h"  #include "mathc99.h"   #include <sstream> @@ -113,7 +113,7 @@ AbstractNode *LinearExtrudeModule::instantiate(const Context *ctx, const ModuleI  		if (slices.type() == Value::NUMBER) {  			node->slices = (int)slices.toDouble();  		} else { -			node->slices = (int)fmax(2, fabs(get_fragments_from_r(node->height, +			node->slices = (int)fmax(2, fabs(Calc::get_fragments_from_r(node->height,  					node->fn, node->fs, node->fa) * node->twist / 360));  		}  		node->has_twist = true; diff --git a/src/openscad.h b/src/openscad.h index dd379a9..0d146c1 100644 --- a/src/openscad.h +++ b/src/openscad.h @@ -28,7 +28,6 @@  #define OPENSCAD_H  extern class FileModule *parse(const char *text, const char *path, int debug); -extern int get_fragments_from_r(double r, double fn, double fs, double fa);  #include <string>  extern std::string commandline_commands; diff --git a/src/primitives.cc b/src/primitives.cc index f1a4ba7..53b2e19 100644 --- a/src/primitives.cc +++ b/src/primitives.cc @@ -34,6 +34,7 @@  #include "printutils.h"  #include "visitor.h"  #include "context.h" +#include "calc.h"  #include <sstream>  #include <assert.h>  #include <boost/assign/std/vector.hpp> @@ -275,17 +276,6 @@ AbstractNode *PrimitiveModule::instantiate(const Context *ctx, const ModuleInsta  	return node;  } -/*! -	Returns the number of subdivision of a whole circle, given radius and -	the three special variables $fn, $fs and $fa -*/ -int get_fragments_from_r(double r, double fn, double fs, double fa) -{ -	if (r < GRID_FINE) return 3; -	if (fn > 0.0) return (int)(fn >= 3 ? fn : 3); -	return (int)ceil(fmax(fmin(360.0 / fa, r*2*M_PI / fs), 5)); -} -  struct point2d {  	double x, y;  }; @@ -364,7 +354,7 @@ PolySet *PrimitiveNode::evaluate_polyset(class PolySetEvaluator *) const  			double z;  		}; -		int fragments = get_fragments_from_r(r1, fn, fs, fa); +		int fragments = Calc::get_fragments_from_r(r1, fn, fs, fa);  		int rings = (fragments+1)/2;  // Uncomment the following three lines to enable experimental sphere tesselation  //		if (rings % 2 == 0) rings++; // To ensure that the middle ring is at phi == 0 degrees @@ -427,7 +417,7 @@ sphere_next_r2:  	if (this->type == CYLINDER &&   			this->h > 0 && this->r1 >=0 && this->r2 >= 0 && (this->r1 > 0 || this->r2 > 0))  	{ -		int fragments = get_fragments_from_r(fmax(this->r1, this->r2), this->fn, this->fs, this->fa); +		int fragments = Calc::get_fragments_from_r(fmax(this->r1, this->r2), this->fn, this->fs, this->fa);  		double z1, z2;  		if (this->center) { @@ -525,7 +515,7 @@ sphere_next_r2:  	if (this->type == CIRCLE)  	{ -		int fragments = get_fragments_from_r(this->r1, this->fn, this->fs, this->fa); +		int fragments = Calc::get_fragments_from_r(this->r1, this->fn, this->fs, this->fa);  		p->is2d = true;  		p->append_poly(); diff --git a/testdata/scad/features/difference-2d-tests.scad b/testdata/scad/features/difference-2d-tests.scad new file mode 100644 index 0000000..bb798c2 --- /dev/null +++ b/testdata/scad/features/difference-2d-tests.scad @@ -0,0 +1,29 @@ +difference() { +  square(10, center=true); +  circle(r=4); +} + +translate([12,0]) difference() { +  square(10, center=true); +  translate([2,2]) circle(r=2); +  translate([-2,-2]) circle(r=2); +} + +// Subtracting something from nothing +translate([12,12]) difference() { +  square([0,10], center=true); +  # circle(r=4); +} + +// Non-geometry (echo) statement as first child should be ignored +translate([0,12]) difference() { +  echo("difference-2d-tests"); +  square(10, center=true); +  circle(r=4); +} + +// Subtract 3D from 2D +translate([24,0]) difference() { +  square(10, center=true); +  sphere(r=4); +} diff --git a/testdata/scad/features/difference-tests.scad b/testdata/scad/features/difference-tests.scad index b770764..0751213 100644 --- a/testdata/scad/features/difference-tests.scad +++ b/testdata/scad/features/difference-tests.scad @@ -3,27 +3,26 @@ difference();  // No children  difference() { } +// Basic  difference() {    cube([10,10,10], center=true);    cylinder(r=4, h=20, center=true);  } -translate([12,0,0]) difference() { -  cube([10,10,10], center=true); -  cylinder(r=4, h=10.5, center=true); -} - +// Two negative objects  translate([0,12,0]) difference() {    cube([10,10,10], center=true);    cylinder(r=4, h=11, center=true);    rotate([0,90,0]) cylinder(r=4, h=11, center=true);  } +// Not intersecting  translate([12,12,0]) difference() {    cube([10,10,10], center=true);    translate([0,0,7.01]) cylinder(r=4, h=4, center=true);  } +// Barely intersecting  translate([24,0,0]) difference() {    cube([10,10,10], center=true);    translate([0,0,6.99]) cylinder(r=4, h=4, center=true); @@ -34,3 +33,16 @@ translate([24,12,0]) difference() {    cube([0,10,10], center=true);    # cylinder(r=4, h=20, center=true);  } + +// Non-geometry (echo) statement as first child should be ignored +translate([24,-12,0]) difference() { +  echo("difference-tests"); +  cube([10,10,10], center=true); +  cylinder(r=4, h=20, center=true); +} + +// Subtracting 2D from 3D +translate([12,0,0]) difference() { +  cube([10,10,10], center=true); +  circle(r=6); +} diff --git a/testdata/scad/features/linear_extrude-tests.scad b/testdata/scad/features/linear_extrude-tests.scad index 680bf53..fbd1858 100644 --- a/testdata/scad/features/linear_extrude-tests.scad +++ b/testdata/scad/features/linear_extrude-tests.scad @@ -9,7 +9,12 @@ linear_extrude(height=10) square([10,10]);  translate([19,5,0]) linear_extrude(height=10, center=true) difference() {circle(5); circle(3);}  translate([31.5,2.5,0]) linear_extrude(height=10, twist=-45) polygon(points = [[-5,-2.5], [5,-2.5], [0,2.5]]); -translate([0,20,0]) linear_extrude(height=20, twist=45, slices=2) square([10,10]); +translate([0,20,0]) linear_extrude(height=20, twist=30, slices=2) { +    difference() { +        square([10,10]); +        translate([1,1]) square([8,8]); +    } +}  translate([19,20,0]) linear_extrude(height=20, twist=45, slices=10) square([10,10]);  translate([0,-15,0]) linear_extrude(5) square([10,10]); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 70e56c6..0be819b 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -507,6 +507,7 @@ set(CORE_SOURCES    ../src/linalg.cc    ../src/handle_dep.cc     ../src/value.cc  +  ../src/calc.cc     ../src/expr.cc     ../src/func.cc     ../src/localscope.cc  diff --git a/tests/regression/cgalpngtest/difference-2d-tests-expected.png b/tests/regression/cgalpngtest/difference-2d-tests-expected.pngBinary files differ new file mode 100644 index 0000000..1476953 --- /dev/null +++ b/tests/regression/cgalpngtest/difference-2d-tests-expected.png diff --git a/tests/regression/cgalpngtest/difference-tests-expected.png b/tests/regression/cgalpngtest/difference-tests-expected.pngBinary files differ index e672c48..bd27d89 100644 --- a/tests/regression/cgalpngtest/difference-tests-expected.png +++ b/tests/regression/cgalpngtest/difference-tests-expected.png diff --git a/tests/regression/cgalpngtest/linear_extrude-tests-expected.png b/tests/regression/cgalpngtest/linear_extrude-tests-expected.pngBinary files differ index c85142e..597b148 100644 --- a/tests/regression/cgalpngtest/linear_extrude-tests-expected.png +++ b/tests/regression/cgalpngtest/linear_extrude-tests-expected.png diff --git a/tests/regression/dumptest/difference-2d-tests-expected.csg b/tests/regression/dumptest/difference-2d-tests-expected.csg new file mode 100644 index 0000000..7bc257d --- /dev/null +++ b/tests/regression/dumptest/difference-2d-tests-expected.csg @@ -0,0 +1,36 @@ +group() { +	difference() { +		square(size = [10, 10], center = true); +		circle($fn = 0, $fa = 12, $fs = 2, r = 4); +	} +	multmatrix([[1, 0, 0, 12], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) { +		difference() { +			square(size = [10, 10], center = true); +			multmatrix([[1, 0, 0, 2], [0, 1, 0, 2], [0, 0, 1, 0], [0, 0, 0, 1]]) { +				circle($fn = 0, $fa = 12, $fs = 2, r = 2); +			} +			multmatrix([[1, 0, 0, -2], [0, 1, 0, -2], [0, 0, 1, 0], [0, 0, 0, 1]]) { +				circle($fn = 0, $fa = 12, $fs = 2, r = 2); +			} +		} +	} +	multmatrix([[1, 0, 0, 12], [0, 1, 0, 12], [0, 0, 1, 0], [0, 0, 0, 1]]) { +		difference() { +			square(size = [0, 10], center = true); +			circle($fn = 0, $fa = 12, $fs = 2, r = 4); +		} +	} +	multmatrix([[1, 0, 0, 0], [0, 1, 0, 12], [0, 0, 1, 0], [0, 0, 0, 1]]) { +		difference() { +			group(); +			square(size = [10, 10], center = true); +			circle($fn = 0, $fa = 12, $fs = 2, r = 4); +		} +	} +	multmatrix([[1, 0, 0, 24], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) { +		difference() { +			square(size = [10, 10], center = true); +			sphere($fn = 0, $fa = 12, $fs = 2, r = 4); +		} +	} +} diff --git a/tests/regression/dumptest/difference-tests-expected.csg b/tests/regression/dumptest/difference-tests-expected.csg index d5d2bb3..8ff8a24 100644 --- a/tests/regression/dumptest/difference-tests-expected.csg +++ b/tests/regression/dumptest/difference-tests-expected.csg @@ -5,12 +5,6 @@ group() {  		cube(size = [10, 10, 10], center = true);  		cylinder($fn = 0, $fa = 12, $fs = 2, h = 20, r1 = 4, r2 = 4, center = true);  	} -	multmatrix([[1, 0, 0, 12], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) { -		difference() { -			cube(size = [10, 10, 10], center = true); -			cylinder($fn = 0, $fa = 12, $fs = 2, h = 10.5, r1 = 4, r2 = 4, center = true); -		} -	}  	multmatrix([[1, 0, 0, 0], [0, 1, 0, 12], [0, 0, 1, 0], [0, 0, 0, 1]]) {  		difference() {  			cube(size = [10, 10, 10], center = true); @@ -42,4 +36,17 @@ group() {  			cylinder($fn = 0, $fa = 12, $fs = 2, h = 20, r1 = 4, r2 = 4, center = true);  		}  	} +	multmatrix([[1, 0, 0, 24], [0, 1, 0, -12], [0, 0, 1, 0], [0, 0, 0, 1]]) { +		difference() { +			group(); +			cube(size = [10, 10, 10], center = true); +			cylinder($fn = 0, $fa = 12, $fs = 2, h = 20, r1 = 4, r2 = 4, center = true); +		} +	} +	multmatrix([[1, 0, 0, 12], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) { +		difference() { +			cube(size = [10, 10, 10], center = true); +			circle($fn = 0, $fa = 12, $fs = 2, r = 6); +		} +	}  } diff --git a/tests/regression/dumptest/linear_extrude-tests-expected.csg b/tests/regression/dumptest/linear_extrude-tests-expected.csg index a0deb81..539412d 100644 --- a/tests/regression/dumptest/linear_extrude-tests-expected.csg +++ b/tests/regression/dumptest/linear_extrude-tests-expected.csg @@ -21,8 +21,13 @@ group() {  		}  	}  	multmatrix([[1, 0, 0, 0], [0, 1, 0, 20], [0, 0, 1, 0], [0, 0, 0, 1]]) { -		linear_extrude(height = 20, center = false, convexity = 1, twist = 45, slices = 2, scale = [1, 1], $fn = 0, $fa = 12, $fs = 2) { -			square(size = [10, 10], center = false); +		linear_extrude(height = 20, center = false, convexity = 1, twist = 30, slices = 2, scale = [1, 1], $fn = 0, $fa = 12, $fs = 2) { +			difference() { +				square(size = [10, 10], center = false); +				multmatrix([[1, 0, 0, 1], [0, 1, 0, 1], [0, 0, 1, 0], [0, 0, 0, 1]]) { +					square(size = [8, 8], center = false); +				} +			}  		}  	}  	multmatrix([[1, 0, 0, 19], [0, 1, 0, 20], [0, 0, 1, 0], [0, 0, 0, 1]]) { diff --git a/tests/regression/opencsgtest/difference-2d-tests-expected.png b/tests/regression/opencsgtest/difference-2d-tests-expected.pngBinary files differ new file mode 100644 index 0000000..ec45e77 --- /dev/null +++ b/tests/regression/opencsgtest/difference-2d-tests-expected.png diff --git a/tests/regression/opencsgtest/difference-tests-expected.png b/tests/regression/opencsgtest/difference-tests-expected.pngBinary files differ index 8db2742..69a4ac2 100644 --- a/tests/regression/opencsgtest/difference-tests-expected.png +++ b/tests/regression/opencsgtest/difference-tests-expected.png diff --git a/tests/regression/opencsgtest/linear_extrude-tests-expected.png b/tests/regression/opencsgtest/linear_extrude-tests-expected.pngBinary files differ index cbbdc11..faba00e 100644 --- a/tests/regression/opencsgtest/linear_extrude-tests-expected.png +++ b/tests/regression/opencsgtest/linear_extrude-tests-expected.png diff --git a/tests/regression/throwntogethertest/difference-2d-tests-expected.png b/tests/regression/throwntogethertest/difference-2d-tests-expected.pngBinary files differ new file mode 100644 index 0000000..4aae3be --- /dev/null +++ b/tests/regression/throwntogethertest/difference-2d-tests-expected.png diff --git a/tests/regression/throwntogethertest/difference-tests-expected.png b/tests/regression/throwntogethertest/difference-tests-expected.pngBinary files differ index 7a61f42..0227306 100644 --- a/tests/regression/throwntogethertest/difference-tests-expected.png +++ b/tests/regression/throwntogethertest/difference-tests-expected.png diff --git a/tests/regression/throwntogethertest/linear_extrude-tests-expected.png b/tests/regression/throwntogethertest/linear_extrude-tests-expected.pngBinary files differ index cbbdc11..faba00e 100644 --- a/tests/regression/throwntogethertest/linear_extrude-tests-expected.png +++ b/tests/regression/throwntogethertest/linear_extrude-tests-expected.png | 
