diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/PolySetCGALEvaluator.cc | 4 | ||||
| -rw-r--r-- | src/calc.cc | 40 | ||||
| -rw-r--r-- | src/calc.h | 8 | ||||
| -rw-r--r-- | src/dxfdata.cc | 8 | ||||
| -rw-r--r-- | src/linearextrude.cc | 4 | ||||
| -rw-r--r-- | src/openscad.h | 1 | ||||
| -rw-r--r-- | src/primitives.cc | 18 | 
7 files changed, 60 insertions, 23 deletions
| 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(); | 
