return UnmodifiableList.decorate(Arrays.asList(getHandleArray(gesture)));
}
private Handle[] getHandleArray(HandleGesture gesture) {
if (gesture == null) {
return new Handle[] { new Handle(this, p0), new Handle(this, p1),
new Handle(this, p2) };
} else {
Handle g = gesture.getHandle();
int gx = g.getX() + gesture.getDeltaX();
int gy = g.getY() + gesture.getDeltaY();
Handle[] ret = { new Handle(this, p0), new Handle(this, p1),
new Handle(this, p2) };
if (g.isAt(p0)) {
if (gesture.isShiftDown()) {
Location p = LineUtil.snapTo8Cardinals(p2, gx, gy);
ret[0] = new Handle(this, p);
} else {
ret[0] = new Handle(this, gx, gy);
}
} else if (g.isAt(p2)) {
if (gesture.isShiftDown()) {
Location p = LineUtil.snapTo8Cardinals(p0, gx, gy);
ret[2] = new Handle(this, p);
} else {
ret[2] = new Handle(this, gx, gy);
}
} else if (g.isAt(p1)) {
if (gesture.isShiftDown()) {
double x0 = p0.getX();
double y0 = p0.getY();
double x1 = p2.getX();
double y1 = p2.getY();
double midx = (x0 + x1) / 2;
double midy = (y0 + y1) / 2;
double dx = x1 - x0;
double dy = y1 - y0;
double[] p = LineUtil.nearestPointInfinite(gx, gy,
midx, midy, midx - dy, midy + dx);
gx = (int) Math.round(p[0]);
gy = (int) Math.round(p[1]);
}
if (gesture.isAltDown()) {
double[] e0 = { p0.getX(), p0.getY() };
double[] e1 = { p2.getX(), p2.getY() };
double[] mid = { gx, gy };
double[] ct = CurveUtil.interpolate(e0, e1, mid);
gx = (int) Math.round(ct[0]);
gy = (int) Math.round(ct[1]);
}
ret[1] = new Handle(this, gx, gy);
}
return ret;
}
}