public class Mesh implements Iterable<Mesh.T> {
- private KDTree kd = new KDTree(3);
public static float EPSILON = (float)0.0001;
public static Random random = new Random();
- private HashMap<Point,Vert> verts = new HashMap<Point,Vert>();
+ private PointSet<Vert> pointset = new PointSet<Vert>();
+ public Vert nearest(Point p) { return pointset.nearest(p); }
+ private HashMap<Point,Vert> verts = new HashMap<Point,Vert>();
public Iterable<E> edges() {
return
for(T t : this)
for(Vert p : new Vert[] { t.v1(), t.v2(), t.v3() })
p.kdremove();
- kd = new KDTree(3);
+ pointset.clear();
for(T t : this)
for(Vert p : new Vert[] { t.v1(), t.v2(), t.v3() })
p.kdinsert();
return (float)total;
}
- public Vert nearest(Point p) {
- Object[] results;
- try { results = kd.nearest(new double[]{p.x,p.y,p.z},1); } catch (Exception e) { throw new Error(e); }
- return (Vert)results[0];
- }
public class BindingGroup {
public HashSet<E> es = new HashSet<E>();
}
public Vert register(Point p) { Vert v = verts.get(p); return v==null ? new Vert(p) : v; }
- public final class Vert {
+ public final class Vert extends HasPoint {
public Point p;
+ public Point getPoint() { return p; }
private Vert(Point p) {
this.p = p;
if (verts.get(p) != null) throw new Error();
public void kdremove() {
if (!inserted) return;
inserted = false;
- try { kd.delete(new double[]{p.x,p.y,p.z}); } catch (Exception e) { }
+ pointset.remove(this);
}
public void kdinsert() {
if (inserted) return;
inserted = true;
- try { kd.insert(new double[]{p.x,p.y,p.z},this); } catch (Exception e) { throw new Error(e); }
+ pointset.add(this);
}
public float score() { return oldscore; }