From b4d3de088d4bcc4f56bb5e6599bd7a953322e5cd Mon Sep 17 00:00:00 2001 From: clifford Date: Mon, 4 Jan 2010 17:36:47 +0000 Subject: Clifford Wolf: Core 2d subsystem more or less finished git-svn-id: http://svn.clifford.at/openscad/trunk@200 b57f626f-c46c-0410-a088-ec61d464b74c diff --git a/examples/example015.scad b/examples/example015.scad index ddf907a..a39d384 100644 --- a/examples/example015.scad +++ b/examples/example015.scad @@ -1,9 +1,18 @@ -union() { - difference() { - square(100, true); - square(50, true); +difference() +{ + translate([ -35, -35 ]) intersection() + { + union() { + difference() { + square(100, true); + square(50, true); + } + translate([ 50, 50 ]) + square(15, true); + } + rotate(45) translate([ 0, -15 ]) square([ 100, 30 ]); } - translate([50, 50]) - square(15, true); -} \ No newline at end of file + + rotate(-45) scale([ 0.7, 1.3 ]) circle(5); +} diff --git a/primitives.cc b/primitives.cc index 893a0aa..90a22ba 100644 --- a/primitives.cc +++ b/primitives.cc @@ -27,7 +27,8 @@ enum primitive_type_e { SPHERE, CYLINDER, POLYHEDRON, - SQUARE + SQUARE, + CIRCLE }; class PrimitiveModule : public AbstractModule @@ -76,6 +77,9 @@ AbstractNode *PrimitiveModule::evaluate(const Context *ctx, const ModuleInstanci if (type == SQUARE) { argnames = QVector() << "size" << "center"; } + if (type == CIRCLE) { + argnames = QVector() << "r"; + } Context c(ctx); c.args(argnames, argexpr, inst->argnames, inst->argvalues); @@ -145,6 +149,13 @@ AbstractNode *PrimitiveModule::evaluate(const Context *ctx, const ModuleInstanci } } + if (type == CIRCLE) { + Value r = c.lookup_variable("r"); + if (r.type == Value::NUMBER) { + node->r1 = r.num; + } + } + return node; } @@ -155,6 +166,7 @@ void register_builtin_primitives() builtin_modules["cylinder"] = new PrimitiveModule(CYLINDER); builtin_modules["polyhedron"] = new PrimitiveModule(POLYHEDRON); builtin_modules["square"] = new PrimitiveModule(SQUARE); + builtin_modules["circle"] = new PrimitiveModule(CIRCLE); } int get_fragments_from_r(double r, double fn, double fs, double fa) @@ -395,6 +407,28 @@ sphere_next_r2: p->append_vertex(x1, y2); } + if (type == CIRCLE) + { + int fragments = get_fragments_from_r(r1, fn, fs, fa); + + struct point2d { + double x, y; + }; + + point2d circle[fragments]; + + for (int i=0; iis2d = true; + p->append_poly(); + for (int i=0; iappend_vertex(circle[i].x, circle[i].y); + } + return p; } diff --git a/transform.cc b/transform.cc index ff27e80..b7408d7 100644 --- a/transform.cc +++ b/transform.cc @@ -83,6 +83,8 @@ AbstractNode *TransformModule::evaluate(const Context *ctx, const ModuleInstanci v.getnum(node->m[5]); v.getnum(node->m[10]); v.getv3(node->m[0], node->m[5], node->m[10]); + if (node->m[10] <= 0) + node->m[10] = 1; } if (type == ROTATE) { -- cgit v0.10.1