summaryrefslogtreecommitdiff
path: root/src/primitives.cc
diff options
context:
space:
mode:
authorMarius Kintel <marius@kintel.net>2011-04-12 18:35:44 (GMT)
committerMarius Kintel <marius@kintel.net>2011-04-12 18:35:44 (GMT)
commitd24b3cc84d0701a5423925765e515db7df9614c5 (patch)
tree0d63867d8b5a3c6ffe107371caa6b29cf8ad0f02 /src/primitives.cc
parent633343c47e0d2bced64d47f62e814489b8e76dc2 (diff)
parent1754a970a76c071fff91cc7c716aa0b78b4ac6be (diff)
Ported recent changes to master into the visitor branch
Diffstat (limited to 'src/primitives.cc')
-rw-r--r--src/primitives.cc44
1 files changed, 26 insertions, 18 deletions
diff --git a/src/primitives.cc b/src/primitives.cc
index 2c1cf1f..7232dc2 100644
--- a/src/primitives.cc
+++ b/src/primitives.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
@@ -93,6 +94,7 @@ public:
bool center;
double x, y, z, h, r1, r2;
+ static const double F_MINIMUM = 0.01;
double fn, fs, fa;
primitive_type_e type;
int convexity;
@@ -143,6 +145,16 @@ AbstractNode *PrimitiveModule::evaluate(const Context *ctx, const ModuleInstanti
node->fs = c.lookup_variable("$fs").num;
node->fa = c.lookup_variable("$fa").num;
+ if (node->fs < PrimitiveNode::F_MINIMUM) {
+ PRINTF("WARNING: $fs too small - clamping to %f", PrimitiveNode::F_MINIMUM);
+ node->fs = PrimitiveNode::F_MINIMUM;
+ }
+ if (node->fa < PrimitiveNode::F_MINIMUM) {
+ PRINTF("WARNING: $fa too small - clamping to %f", PrimitiveNode::F_MINIMUM);
+ node->fa = PrimitiveNode::F_MINIMUM;
+ }
+
+
if (type == CUBE) {
Value size = c.lookup_variable("size");
Value center = c.lookup_variable("center");
@@ -317,7 +329,7 @@ PolySet *PrimitiveNode::render_polyset(render_mode_e, class PolySetRenderer *) c
};
int rings = get_fragments_from_r(this->r1, this->fn, this->fs, this->fa);
- ring_s ring[rings];
+ ring_s *ring = new ring_s[rings];
for (int i = 0; i < rings; i++) {
double phi = (M_PI * (i + 0.5)) / rings;
@@ -370,6 +382,8 @@ sphere_next_r2:
p->append_poly();
for (int i = 0; i < ring[rings-1].fragments; i++)
p->insert_vertex(ring[rings-1].points[i].x, ring[rings-1].points[i].y, ring[rings-1].z);
+
+ delete[] ring;
}
if (this->type == CYLINDER &&
@@ -390,8 +404,8 @@ sphere_next_r2:
double x, y;
};
- point2d circle1[fragments];
- point2d circle2[fragments];
+ point2d *circle1 = new point2d[fragments];
+ point2d *circle2 = new point2d[fragments];
for (int i=0; i<fragments; i++) {
double phi = (M_PI*2*i) / fragments;
@@ -438,6 +452,9 @@ sphere_next_r2:
for (int i=0; i<fragments; i++)
p->append_vertex(circle2[i].x, circle2[i].y, z2);
}
+
+ delete[] circle1;
+ delete[] circle2;
}
if (this->type == POLYHEDRON)
@@ -483,22 +500,13 @@ sphere_next_r2:
{
int fragments = get_fragments_from_r(this->r1, this->fn, this->fs, this->fa);
- struct point2d {
- double x, y;
- };
-
- point2d circle[fragments];
+ p->is2d = true;
+ p->append_poly();
- for (int i=0; i<fragments; i++) {
+ for (int i=0; i < fragments; i++) {
double phi = (M_PI*2*i) / fragments;
- circle[i].x = this->r1*cos(phi);
- circle[i].y = this->r1*sin(phi);
+ p->append_vertex(this->r1*cos(phi), this->r1*sin(phi));
}
-
- p->is2d = true;
- p->append_poly();
- for (int i=0; i<fragments; i++)
- p->append_vertex(circle[i].x, circle[i].y);
}
if (this->type == POLYGON)
contact: Jan Huwald // Impressum