+ public float stretchRatio() {
+ Vertex nearest = error_against.nearest(midpoint());
+ float nearest_distance = midpoint().distance(nearest.p);
+ float other_distance =
+ (v1.p.distance(error_against.nearest(v1.p).p)+
+ v2.p.distance(error_against.nearest(v2.p).p))/2;
+ return nearest_distance/other_distance;
+ }
+ public float comparator() {
+ return length();
+ }
+ public int compareTo(E e) {
+ return e.comparator() > comparator() ? 1 : -1;
+ }
+ public void bindEdge(E e, Matrix m) {
+ _bindEdge(e, m);
+ pair._bindEdge(e.pair, m);
+ }
+ public void _bindEdge(E e, Matrix m) {
+ e = e.pair;
+ /*
+ //assumes edges are identical length at binding time
+ Vec reflectionPlaneNormal = e.v2.p.minus(e.v1.p).norm();
+ float a = reflectionPlaneNormal.x;
+ float b = reflectionPlaneNormal.y;
+ float c = reflectionPlaneNormal.z;
+ Matrix reflectionMatrix =
+ new Matrix( 1-2*a*a, -2*a*b, -2*a*c, 0,
+ -2*a*b, 1-2*b*b, -2*b*c, 0,
+ -2*a*c, -2*b*c, 1-2*c*c, 0,
+ 0, 0, 0, 1);
+ m = m.times(Matrix.translate(e.midpoint().minus(Point.ORIGIN))
+ .times(reflectionMatrix)
+ .times(Matrix.translate(Point.ORIGIN.minus(e.midpoint()))));
+ System.out.println(reflectionPlaneNormal);
+ System.out.println(" " + v1.p + " " + m.times(e.v1.p));
+ System.out.println(" " + v2.p + " " + m.times(e.v2.p));
+ */
+ /*
+ if (m.times(e.v1.p).minus(v1.p).mag() > EPSILON) throw new Error();
+ if (m.times(e.v2.p).minus(v2.p).mag() > EPSILON) throw new Error();
+ */
+ this.bindTo(m, e);
+ }
+
+ public void dobind() {
+ for(E e : (Iterable<E>)getBoundPeers()) {
+ if (e==this) continue;
+ v1.bindTo(getBindingMatrix(e), e.v1);
+ v2.bindTo(getBindingMatrix(e), e.v2);
+ /*
+ e.v1.setConstraint(getConstraint());
+ e.v2.setConstraint(getConstraint());
+ */
+ }
+ }
+
+ public Vertex shatter() {
+ if (shattered || destroyed) return nearest(midpoint());
+ shattered = true;
+ E first = null;
+ E firste = null;
+ E firstx = null;
+ E firstq = null;
+ for(E e : (Iterable<E>)getBoundPeers()) {
+ E enext = e.next;
+ E eprev = e.prev;
+ E pnext = e.pair.next;
+ E pprev = e.pair.prev;
+ Point mid = e.midpoint();
+ Vertex r = e.next.v2;
+ Vertex l = e.pair.next.v2;
+ if (!e.destroyed) {
+ e.destroy();
+ e.pair.destroy();
+ newT(r.p, e.v1.p, mid, null, 0);
+ newT(r.p, mid, e.v2.p, null, 0);
+ newT(l.p, mid, e.v1.p, null, 0);
+ newT(l.p, e.v2.p, mid, null, 0);
+ }
+ }
+ for(E e : (Iterable<E>)getBoundPeers()) {
+ Point mid = e.midpoint();
+ if (first==null) {
+ first = e.v1.getE(mid);
+ firste = e;
+ firstx = e.pair;
+ firstq = e.v2.getE(mid).pair;
+ continue;
+ }
+ e.v1.getE(mid). bindTo(e.getBindingMatrix(firste), first);
+ e.v1.getE(mid).pair. bindTo(e.getBindingMatrix(firste), first.pair);
+ e.v2.getE(mid).pair. bindTo(e.getBindingMatrix(firste), firstq);
+ e.v2.getE(mid).pair.pair.bindTo(e.getBindingMatrix(firste), firstq.pair);
+ }
+ /*
+ first.setConstraint(firste.getConstraint());
+ firstq.setConstraint(firste.getConstraint());
+ */
+ return nearest(midpoint());