[Bprocessor-commit] model/src/net/sourceforge/bprocessor/model Command.java, 1.38, 1.39
Status: Pre-Alpha
Brought to you by:
henryml
From: Michael L. <he...@us...> - 2007-11-26 07:29:05
|
Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv30870/src/net/sourceforge/bprocessor/model Modified Files: Command.java Log Message: extrude command Index: Command.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Command.java,v retrieving revision 1.38 retrieving revision 1.39 diff -C2 -d -r1.38 -r1.39 *** Command.java 24 Nov 2007 09:01:37 -0000 1.38 --- Command.java 26 Nov 2007 07:28:59 -0000 1.39 *************** *** 1341,1343 **** --- 1341,1426 ---- } + + /** + * Extrude + */ + public static class Extrude extends Command { + private Surface surface; + + /** + * Constructs Extrude command + * @param surface Surface to extrude + */ + public Extrude(Surface surface) { + this.surface = surface; + parameters.put("distance", 1.0); + } + + + /** {@inheritDoc} */ + @Override + public void evaluate() { + double distance = parameters.getDouble("distance"); + List<Surface> sides = new LinkedList(); + Surface bottom = (Surface) surface.copy(new HashMap()); + Vertex normal = bottom.normal(); + normal.scaleInPlace(distance); + List vertices = bottom.getVertices(); + List edges = bottom.getEdges(); + int n = vertices.size(); + Vertex[] v = new Vertex[n]; + Edge[] e = new Edge[n]; + Vertex[] vmap = new Vertex[n]; + Edge[] topmap = new Edge[n]; + Edge[] sidemap = new Edge[n]; + Surface[] facemap = new Surface[n]; + Surface top = null; + vertices.toArray(v); + edges.toArray(e); + + for (int i = 0; i < n; i++) { + vmap[i] = v[i].add(normal); + } + + for (int i = 0; i < n; i++) { + topmap[i] = new Edge(vmap[i], vmap[(i + 1) % n]); + } + + for (int i = 0; i < n; i++) { + sidemap[i] = new Edge(v[i], vmap[i]); + } + + for (int i = 0; i < n; i++) { + Edge b = e[i]; + Edge r = sidemap[i]; + Edge l = sidemap[(i + 1) % n]; + Edge t = topmap[i]; + List newEdges = new LinkedList(); + newEdges.add(r); + newEdges.add(t); + newEdges.add(l); + newEdges.add(b); + facemap[i] = new Surface(newEdges); + sides.add(facemap[i]); + } + + { + List newEdges = new LinkedList(); + for (int i = 0; i < n; i++) { + newEdges.add(topmap[n - i - 1]); + } + top = new Surface(newEdges); + } + + List<Surface> surfaces = new LinkedList(); + surfaces.add(bottom); + surfaces.addAll(sides); + surfaces.add(top); + + Space union = new Space("Extrusion", Space.CONSTRUCTION, true); + Shape.addTo(union, surfaces); + + surface.getOwner().add(union); + } + } } |