summaryrefslogtreecommitdiff
path: root/src/PolySetCGALEvaluator.cc
diff options
context:
space:
mode:
authorMarius Kintel <marius@kintel.net>2013-05-10 16:01:50 (GMT)
committerMarius Kintel <marius@kintel.net>2013-05-10 16:01:50 (GMT)
commitadffb9121fbf5d12542ae0d8c5a010e78cc8a4f9 (patch)
treeb13fa35d6b9d807b3c2d7a4c195b49624c2c3297 /src/PolySetCGALEvaluator.cc
parent130e10778e9d74ceb07dfc813b85d75a52a71e10 (diff)
Added support for 2D scaling in linear_extrude
Diffstat (limited to 'src/PolySetCGALEvaluator.cc')
-rw-r--r--src/PolySetCGALEvaluator.cc55
1 files changed, 29 insertions, 26 deletions
diff --git a/src/PolySetCGALEvaluator.cc b/src/PolySetCGALEvaluator.cc
index 6d0704e..f0c274f 100644
--- a/src/PolySetCGALEvaluator.cc
+++ b/src/PolySetCGALEvaluator.cc
@@ -205,31 +205,32 @@ PolySet *PolySetCGALEvaluator::evaluatePolySet(const ProjectionNode &node)
static void add_slice(PolySet *ps, const DxfData &dxf, DxfData::Path &path,
double rot1, double rot2,
double h1, double h2,
- double scale1, double scale2)
+ double scale1_x, double scale1_y,
+ double scale2_x, double scale2_y)
{
// FIXME: If scale2 == 0 we need to handle tessellation separately
bool splitfirst = sin(rot2 - rot1) >= 0.0;
for (size_t j = 1; j < path.indices.size(); j++) {
int k = j - 1;
- double jx1 = scale1 * (dxf.points[path.indices[j]][0] * cos(rot1*M_PI/180) +
+ double jx1 = scale1_x * (dxf.points[path.indices[j]][0] * cos(rot1*M_PI/180) +
dxf.points[path.indices[j]][1] * sin(rot1*M_PI/180));
- double jy1 = scale1 * (dxf.points[path.indices[j]][0] * -sin(rot1*M_PI/180) +
+ double jy1 = scale1_y * (dxf.points[path.indices[j]][0] * -sin(rot1*M_PI/180) +
dxf.points[path.indices[j]][1] * cos(rot1*M_PI/180));
- double jx2 = scale2 * (dxf.points[path.indices[j]][0] * cos(rot2*M_PI/180) +
+ double jx2 = scale2_x * (dxf.points[path.indices[j]][0] * cos(rot2*M_PI/180) +
dxf.points[path.indices[j]][1] * sin(rot2*M_PI/180));
- double jy2 = scale2 * (dxf.points[path.indices[j]][0] * -sin(rot2*M_PI/180) +
+ double jy2 = scale2_y * (dxf.points[path.indices[j]][0] * -sin(rot2*M_PI/180) +
dxf.points[path.indices[j]][1] * cos(rot2*M_PI/180));
- double kx1 = scale1 * (dxf.points[path.indices[k]][0] * cos(rot1*M_PI/180) +
+ double kx1 = scale1_x * (dxf.points[path.indices[k]][0] * cos(rot1*M_PI/180) +
dxf.points[path.indices[k]][1] * sin(rot1*M_PI/180));
- double ky1 = scale1 * (dxf.points[path.indices[k]][0] * -sin(rot1*M_PI/180) +
+ double ky1 = scale1_y * (dxf.points[path.indices[k]][0] * -sin(rot1*M_PI/180) +
dxf.points[path.indices[k]][1] * cos(rot1*M_PI/180));
- double kx2 = scale2 * (dxf.points[path.indices[k]][0] * cos(rot2*M_PI/180) +
+ double kx2 = scale2_x * (dxf.points[path.indices[k]][0] * cos(rot2*M_PI/180) +
dxf.points[path.indices[k]][1] * sin(rot2*M_PI/180));
- double ky2 = scale2 * (dxf.points[path.indices[k]][0] * -sin(rot2*M_PI/180) +
+ double ky2 = scale2_y * (dxf.points[path.indices[k]][0] * -sin(rot2*M_PI/180) +
dxf.points[path.indices[k]][1] * cos(rot2*M_PI/180));
if (splitfirst) {
@@ -244,7 +245,7 @@ static void add_slice(PolySet *ps, const DxfData &dxf, DxfData::Path &path,
ps->insert_vertex(jx2, jy2, h2);
}
- if (scale2 > 0) {
+ if (scale2_x > 0 || scale2_y > 0) {
ps->append_poly();
if (path.is_inner) {
ps->append_vertex(kx2, ky2, h2);
@@ -269,7 +270,7 @@ static void add_slice(PolySet *ps, const DxfData &dxf, DxfData::Path &path,
ps->insert_vertex(kx2, ky2, h2);
}
- if (scale2 > 0) {
+ if (scale2_x > 0 || scale2_y > 0) {
ps->append_poly();
if (path.is_inner) {
ps->append_vertex(jx2, jy2, h2);
@@ -311,7 +312,7 @@ PolySet *PolySetCGALEvaluator::evaluatePolySet(const LinearExtrudeNode &node)
if (sum.isNull()) return NULL;
dxf = sum.convertToDxfData();;
} else {
- dxf = new DxfData(node.fn, node.fs, node.fa, node.filename, node.layername, node.origin_x, node.origin_y, node.scale);
+ dxf = new DxfData(node.fn, node.fs, node.fa, node.filename, node.layername, node.origin_x, node.origin_y, node.scale_x);
}
PolySet *ps = extrudeDxfData(node, *dxf);
@@ -343,39 +344,41 @@ PolySet *PolySetCGALEvaluator::extrudeDxfData(const LinearExtrudeNode &node, Dxf
first_open_path = false;
}
PRINTB(" %9.5f %10.5f ... %10.5f %10.5f",
- (dxf.points[dxf.paths[i].indices.front()][0] / node.scale + node.origin_x) %
- (dxf.points[dxf.paths[i].indices.front()][1] / node.scale + node.origin_y) %
- (dxf.points[dxf.paths[i].indices.back()][0] / node.scale + node.origin_x) %
- (dxf.points[dxf.paths[i].indices.back()][1] / node.scale + node.origin_y));
+ (dxf.points[dxf.paths[i].indices.front()][0] / node.scale_x + node.origin_x) %
+ (dxf.points[dxf.paths[i].indices.front()][1] / node.scale_y + node.origin_y) %
+ (dxf.points[dxf.paths[i].indices.back()][0] / node.scale_x + node.origin_x) %
+ (dxf.points[dxf.paths[i].indices.back()][1] / node.scale_y + node.origin_y));
}
if (node.has_twist) {
- dxf_tesselate(ps, dxf, 0, 1, false, true, h1);
- if (node.scale > 0) {
- dxf_tesselate(ps, dxf, node.twist, node.scale, true, true, h2);
+ dxf_tesselate(ps, dxf, 0, Vector2d(1,1), false, true, h1); // bottom
+ if (node.scale_x > 0 || node.scale_y > 0) {
+ dxf_tesselate(ps, dxf, node.twist, Vector2d(node.scale_x, node.scale_y), true, true, h2); // top
}
for (int j = 0; j < node.slices; j++) {
double t1 = node.twist*j / node.slices;
double t2 = node.twist*(j+1) / node.slices;
double g1 = h1 + (h2-h1)*j / node.slices;
double g2 = h1 + (h2-h1)*(j+1) / node.slices;
- double s1 = 1 - (1-node.scale)*j / node.slices;
- double s2 = 1 - (1-node.scale)*(j+1) / node.slices;
+ double s1x = 1 - (1-node.scale_x)*j / node.slices;
+ double s1y = 1 - (1-node.scale_y)*j / node.slices;
+ double s2x = 1 - (1-node.scale_x)*(j+1) / node.slices;
+ double s2y = 1 - (1-node.scale_y)*(j+1) / node.slices;
for (size_t i = 0; i < dxf.paths.size(); i++) {
if (!dxf.paths[i].is_closed) continue;
- add_slice(ps, dxf, dxf.paths[i], t1, t2, g1, g2, s1, s2);
+ add_slice(ps, dxf, dxf.paths[i], t1, t2, g1, g2, s1x, s1y, s2x, s2y);
}
}
}
else {
- dxf_tesselate(ps, dxf, 0, 1, false, true, h1);
- if (node.scale > 0) {
- dxf_tesselate(ps, dxf, 0, node.scale, true, true, h2);
+ dxf_tesselate(ps, dxf, 0, Vector2d(1,1), false, true, h1); //bottom
+ if (node.scale_x > 0 || node.scale_y > 0) {
+ dxf_tesselate(ps, dxf, 0, Vector2d(node.scale_x, node.scale_y), true, true, h2); // top
}
for (size_t i = 0; i < dxf.paths.size(); i++) {
if (!dxf.paths[i].is_closed) continue;
- add_slice(ps, dxf, dxf.paths[i], 0, 0, h1, h2, 1, node.scale);
+ add_slice(ps, dxf, dxf.paths[i], 0, 0, h1, h2, 1, 1, node.scale_x, node.scale_y);
}
}
contact: Jan Huwald // Impressum