From 46d1812436a175a0011d1691484c508df41e8bb3 Mon Sep 17 00:00:00 2001 From: adam Date: Sat, 1 Dec 2007 17:18:10 -0800 Subject: [PATCH] fixed bugs darcs-hash:20071202011810-5007d-f0a2c151cd7e40d8d31780cf1f8dbf85b9800636.gz --- src/Geom.java | 62 +++++++++++++++++++-------------------------------------- src/Main.java | 1 + 2 files changed, 22 insertions(+), 41 deletions(-) diff --git a/src/Geom.java b/src/Geom.java index 3a5f4a6..f3c37f4 100644 --- a/src/Geom.java +++ b/src/Geom.java @@ -47,7 +47,11 @@ public class Geom implements Iterable { e23.makeAdjacent(e31); e31.makeAdjacent(e12); } - return e12.newT(); + T ret = e12.newT(); + if (e12.t == null) throw new Error(); + if (e23.t == null) throw new Error(); + if (e31.t == null) throw new Error(); + return ret; } private char allname = 'A'; @@ -65,20 +69,20 @@ public class Geom implements Iterable { public E makeE(P p2) { E e = getE(p2); if (e != null) return e; + e = p2.getE(this); if (this.e == null && p2.e == null) return this.e = new E(this, p2); if (this.e == null && p2.e != null) return p2.makeE(this).pair; - - e = getFreeIncident(); - if (e==null) throw new Error("could not find free incident to " + this); - return new E(e, p2); + return new E(getFreeIncident(), p2); } public E getFreeIncident() { E ret = getFreeIncident(e, e); if (ret != null) return ret; ret = getFreeIncident(e.pair.next, e.pair.next); + if (ret == null) throw new Error("unable to find free incident to " + this); return ret; } + public E getFreeIncident(E start, E before) { E e = start; do { @@ -88,15 +92,6 @@ public class Geom implements Iterable { return null; } - public E listIncidents(E start, E before) { - E e = start; - do { - if (e.pair.p2 == this && e.pair.t == null) System.out.println(e.pair + " / " + e.pair.t); - e = e.pair.next; - } while(e != before); - return null; - } - public E getE(P p2) { E e = this.e; do { @@ -176,13 +171,13 @@ public class Geom implements Iterable { Float.floatToIntBits(z); } public void glVertex(GL gl) { gl.glVertex3f(x, y, z); } - public String toString() { return ""+name; } - //{ return "("+x+","+y+","+z+")"; } + //public String toString() { return ""+name; } + public String toString() { return "("+x+","+y+","+z+")"; } public V norm() { V norm = new V(0, 0, 0); E e = this.e; do { - norm = norm.plus(e.t.norm().times((float)e.prev.angle())); + if (e.t != null) norm = norm.plus(e.t.norm().times((float)e.prev.angle())); e = e.pair.next; } while(e != this.e); return norm.norm(); @@ -213,21 +208,13 @@ public class Geom implements Iterable { E next; E pair; - private void syncm() { + private void sync() { this.prev.next = this; this.next.prev = this; this.pair.pair = this; if (this.next.p1 != p2) throw new Error(); if (this.prev.p2 != p1) throw new Error(); - } - private void sync() { - syncm(); - this.p1.e = this; - System.out.println("make " + this); - /* - if (next != this && next.next != this && next.next.next == this) - newT(); - */ + if (this.p1.e == null) this.p1.e = this; } public T newT() { @@ -247,9 +234,7 @@ public class Geom implements Iterable { if (p2 != e.p1) throw new Error("cannot make adjacent -- no shared vertex"); if (t != null || e.t != null) throw new Error("cannot make adjacent -- edges not both free"); - System.out.println(this + ".makeAdjacent("+e+") -- from " + this.next); - E freeIncident = p2.getFreeIncident(); - if (freeIncident==null) throw new Error("unable to find freeIncident"); + E freeIncident = p2.getFreeIncident(e, this); e.prev.next = freeIncident.next; freeIncident.next.prev = e.prev; @@ -260,10 +245,8 @@ public class Geom implements Iterable { this.next = e; e.prev = this; - syncm(); - freeIncident.syncm(); - - //throw new Error("makeAdjacent() failed"); + sync(); + freeIncident.sync(); } /** creates an isolated edge out in the middle of space */ @@ -280,19 +263,16 @@ public class Geom implements Iterable { this.p1 = prev.p2; this.p2 = p2; this.prev = prev; + if (p2.getE(p1) != null) throw new Error(); if (p2.e==null) { this.next = this.pair = new E(this, this, prev.next); } else { E q = p2.getFreeIncident(); - if (q==null) { - System.out.println("listing:"); - p2.listIncidents(p2.e, p2.e); - p2.listIncidents(p2.e.pair.next, p2.e.pair.next); - throw new Error("could not find free incident to " + p2 + " from " + p2.e); - } this.next = q.next; this.next.prev = this; - this.pair = new E(q, this, prev.next); + E z = prev.next; + this.prev.next = this; + this.pair = new E(q, this, z); } sync(); } diff --git a/src/Main.java b/src/Main.java index fc8d2ee..c5192db 100644 --- a/src/Main.java +++ b/src/Main.java @@ -221,6 +221,7 @@ public class Main implements GLEventListener { centroid.glVertex(gl); centroid.plus(t.norm().times(t.diameter())).glVertex(gl); */ + t.p1().glVertex(gl); t.p1().plus(t.p1().norm().times(t.diameter())).glVertex(gl); t.p2().glVertex(gl); -- 1.7.10.4