diff options
author | clifford <clifford@b57f626f-c46c-0410-a088-ec61d464b74c> | 2010-01-04 17:36:47 (GMT) |
---|---|---|
committer | clifford <clifford@b57f626f-c46c-0410-a088-ec61d464b74c> | 2010-01-04 17:36:47 (GMT) |
commit | b4d3de088d4bcc4f56bb5e6599bd7a953322e5cd (patch) | |
tree | a862ab9521f14f5403d74b9d8a606680d5cabd54 /primitives.cc | |
parent | 11e6d83eaf3813442a72fb7ea5637de374ca53b9 (diff) |
Clifford Wolf:
Core 2d subsystem more or less finished
git-svn-id: http://svn.clifford.at/openscad/trunk@200 b57f626f-c46c-0410-a088-ec61d464b74c
Diffstat (limited to 'primitives.cc')
-rw-r--r-- | primitives.cc | 36 |
1 files changed, 35 insertions, 1 deletions
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<QString>() << "size" << "center"; } + if (type == CIRCLE) { + argnames = QVector<QString>() << "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; i<fragments; i++) { + double phi = (M_PI*2*i) / fragments; + circle[i].x = r1*cos(phi); + circle[i].y = 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); + } + return p; } |