X-Git-Url: http://git.megacz.com/?p=anneal.git;a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fqfat%2FMesh.java;h=f6357548443e2ce607fae54316eed82bfd3ae35f;hp=08d89e7a5d16f2993d7b092368e6177e3fafb089;hb=b6875b8bd79c804e15eb75bc64044ca2c770b07d;hpb=116e33cf3c02f4935571766ed5509d0ed95551b8 diff --git a/src/edu/berkeley/qfat/Mesh.java b/src/edu/berkeley/qfat/Mesh.java index 08d89e7..f635754 100644 --- a/src/edu/berkeley/qfat/Mesh.java +++ b/src/edu/berkeley/qfat/Mesh.java @@ -126,11 +126,11 @@ public class Mesh implements Iterable { E e; // some edge *leaving* this point Vert bound_to = this; - int watch_count; - float watch_x; - float watch_y; - float watch_z; - Vert watch; + int nearest_vert_in_other_mesh_count; + float nearest_vert_in_other_mesh_x; + float nearest_vert_in_other_mesh_y; + float nearest_vert_in_other_mesh_z; + Vert nearest_vert_in_other_mesh; Matrix binding = new Matrix(); float oldscore = 0; boolean inserted = false; @@ -154,47 +154,47 @@ public class Mesh implements Iterable { } public float score() { return oldscore; } public void unscore() { - if (watch == null) return; - watch.watch_x -= p.x; - watch.watch_y -= p.y; - watch.watch_z -= p.z; - watch.watch_count--; - if (watch.watch_count==0) { - watch.watch_x = 0; - watch.watch_y = 0; - watch.watch_z = 0; + if (nearest_vert_in_other_mesh == null) return; + nearest_vert_in_other_mesh.nearest_vert_in_other_mesh_x -= p.x; + nearest_vert_in_other_mesh.nearest_vert_in_other_mesh_y -= p.y; + nearest_vert_in_other_mesh.nearest_vert_in_other_mesh_z -= p.z; + nearest_vert_in_other_mesh.nearest_vert_in_other_mesh_count--; + if (nearest_vert_in_other_mesh.nearest_vert_in_other_mesh_count==0) { + nearest_vert_in_other_mesh.nearest_vert_in_other_mesh_x = 0; + nearest_vert_in_other_mesh.nearest_vert_in_other_mesh_y = 0; + nearest_vert_in_other_mesh.nearest_vert_in_other_mesh_z = 0; } - watch = null; + nearest_vert_in_other_mesh = null; } - public Vert partner() { return watch==null ? this : watch; } - public Point watchback() { return watch_count==0 ? partner().p : - new Point(watch_x/watch_count, watch_y/watch_count, watch_z/watch_count); } + public Vert partner() { return nearest_vert_in_other_mesh==null ? this : nearest_vert_in_other_mesh; } + public Point nearest_vert_in_other_mesh() { return nearest_vert_in_other_mesh_count==0 ? partner().p : + new Point(nearest_vert_in_other_mesh_x/nearest_vert_in_other_mesh_count, nearest_vert_in_other_mesh_y/nearest_vert_in_other_mesh_count, nearest_vert_in_other_mesh_z/nearest_vert_in_other_mesh_count); } public void rescore() { if (score_against == null) return; score -= oldscore; oldscore = 0; - if (watch != null) unscore(); + if (nearest_vert_in_other_mesh != null) unscore(); Vert po = this; - if (watch == null) { - watch = score_against.nearest(po.p); + if (nearest_vert_in_other_mesh == null) { + nearest_vert_in_other_mesh = score_against.nearest(po.p); // don't attract to vertices that face the other way - if (watch.e == null || watch.norm().dot(norm()) < 0) { - watch = null; + if (nearest_vert_in_other_mesh.e == null || nearest_vert_in_other_mesh.norm().dot(norm()) < 0) { + nearest_vert_in_other_mesh = null; } else { - watch.watch_x += po.p.x; - watch.watch_y += po.p.y; - watch.watch_z += po.p.z; - watch.watch_count++; + nearest_vert_in_other_mesh.nearest_vert_in_other_mesh_x += po.p.x; + nearest_vert_in_other_mesh.nearest_vert_in_other_mesh_y += po.p.y; + nearest_vert_in_other_mesh.nearest_vert_in_other_mesh_z += po.p.z; + nearest_vert_in_other_mesh.nearest_vert_in_other_mesh_count++; } } double s1, s2; - if (watch_count==0) s1 = 0; - else s1 = p.distance(watch_x/watch_count, watch_y/watch_count, watch_z/watch_count); - s2 = watch==null ? 0 : po.p.distance(watch.p); + if (nearest_vert_in_other_mesh_count==0) s1 = 0; + else s1 = p.distance(nearest_vert_in_other_mesh_x/nearest_vert_in_other_mesh_count, nearest_vert_in_other_mesh_y/nearest_vert_in_other_mesh_count, nearest_vert_in_other_mesh_z/nearest_vert_in_other_mesh_count); + s2 = nearest_vert_in_other_mesh==null ? 0 : po.p.distance(nearest_vert_in_other_mesh.p); oldscore = (float)(s1 + s2); score += oldscore; }