From: adam Date: Sat, 2 Jul 2005 10:04:18 +0000 (+0000) Subject: added ITERATE_* and iterateTriangles() in Mesh X-Git-Tag: 01-July-2005~2 X-Git-Url: http://git.megacz.com/?p=org.ibex.core.git;a=commitdiff_plain;h=a523360b6bafb7ce98d0913259a46441ad8cd129 added ITERATE_* and iterateTriangles() in Mesh darcs-hash:20050702100418-5007d-675d827adf9e6381039f215c22500572efe9b951.gz --- diff --git a/src/org/ibex/graphics/Mesh.java b/src/org/ibex/graphics/Mesh.java index 4693b64..6fc2349 100644 --- a/src/org/ibex/graphics/Mesh.java +++ b/src/org/ibex/graphics/Mesh.java @@ -29,8 +29,8 @@ public final class Mesh { private static final float epsilon2 = (float)0.001; private static final boolean debug = false; - private Vector triangles = new Vector(); - private Hash edges = new Hash(); + private Vector triangles = new Vector(); /* we no longer need this */ + private Hash edges = new Hash(); /* we no longer need this either */ private int numvertices = 0; private Triangle triangle0 = null; private Vertex vertex0 = null; @@ -82,13 +82,17 @@ public final class Mesh { public void add(Mesh m, Affine a) { iterateTriangles(ITERATE_ADD, m, a); } public static long seekTime = 0; - public static final int ITERATE_SUBTRACT = 1; - public static final int ITERATE_INTERSECT = 2; - public static final int ITERATE_ADD = 3; + public static final int ITERATE_SUBTRACT = 1; + public static final int ITERATE_INTERSECT = 2; + public static final int ITERATE_ADD = 3; + public static final int ITERATE_CLEAR_WASSET = 4; + public static final int ITERATE_CLEAR = 5; + public static final int ITERATE_STROKE = 6; int tick = 0; Triangle[] iter = new Triangle[100]; - private void iterateTriangles(int mode, Mesh m, Affine a) { + private void iterateTriangles(int mode, Mesh m, Affine a) { iterateTriangles(mode, m, a, null, 0); } + private void iterateTriangles(int mode, Mesh m, Affine a, PixelBuffer buf, int color) { tick++; int numiter = 0; if (iter.length < triangles.size()) iter = new Triangle[triangles.size()]; @@ -97,6 +101,9 @@ public final class Mesh { Triangle t = iter[--numiter]; if (t.tick >= this.tick) continue; switch(mode) { + case ITERATE_STROKE: t.stroke(buf, a, color); break; + case ITERATE_CLEAR: t.clear(); break; + case ITERATE_CLEAR_WASSET: t.inWasSet = false; break; case ITERATE_INTERSECT: case ITERATE_SUBTRACT: { if (!t.in) break; @@ -257,8 +264,11 @@ public final class Mesh { // Edge ////////////////////////////////////////////////////////////////////////////// public Edge newEdge(Vertex v1, Vertex v2) { + return getEdge(v1,v2); + /* if (v1==v2) throw new Error(); Edge ret = (Edge)edges.get(v1,v2); + //if (ret != null) throw new Error("tried to get an edge that already exists!"); if (ret == null) ret = new Edge(v1,v2); return ret; } @@ -315,7 +325,12 @@ public final class Mesh { public boolean hasVertex(Vertex v) { return v1==v || v2==v; } public boolean hasTriangle(Triangle t) { return t==t1 || t==t2; } public String toString() { return v(1) + "--" + v(2); } - public void rmTriangle(Triangle t) { if (t1==t) t1 = null; else if (t2==t) t2 = null; else throw new Error(); } + public void rmTriangle(Triangle t) { + if (t1==t) t1 = null; + else if (t2==t) t2 = null; + else throw new Error(); + if (t1==null && t2==null) delete(); + } public boolean convex() { return this.intersects(t1.opposingVertex(t2), t2.opposingVertex(t1)); } public boolean colinear(Point v) { return area(v,v1,v2)<=epsilon; } @@ -812,20 +827,19 @@ public final class Mesh { // Drawing ////////////////////////////////////////////////////////////////////////////// public void setIn(boolean evenOdd) { - for (int i=0; i