use of com.cburch.draw.model.Handle in project logisim-evolution by reds-heig.
the class Poly method getRandomBoundaryPoint.
private Location getRandomBoundaryPoint(Bounds bds, Random rand) {
Handle[] hs = handles;
double[] ls = lens;
if (ls == null) {
ls = new double[hs.length + (closed ? 1 : 0)];
double total = 0.0;
for (int i = 0; i < ls.length; i++) {
int j = (i + 1) % hs.length;
total += LineUtil.distance(hs[i].getX(), hs[i].getY(), hs[j].getX(), hs[j].getY());
ls[i] = total;
}
lens = ls;
}
double pos = ls[ls.length - 1] * rand.nextDouble();
for (int i = 0; true; i++) {
if (pos < ls[i]) {
Handle p = hs[i];
Handle q = hs[(i + 1) % hs.length];
double u = Math.random();
int x = (int) Math.round(p.getX() + u * (q.getX() - p.getX()));
int y = (int) Math.round(p.getY() + u * (q.getY() - p.getY()));
return Location.create(x, y);
}
}
}
use of com.cburch.draw.model.Handle in project logisim-evolution by reds-heig.
the class Poly method canInsertHandle.
@Override
public Handle canInsertHandle(Location loc) {
PolyUtil.ClosestResult result = PolyUtil.getClosestPoint(loc, closed, handles);
int thresh = Math.max(Line.ON_LINE_THRESH, getStrokeWidth() / 2);
if (result.getDistanceSq() < thresh * thresh) {
Location resLoc = result.getLocation();
if (result.getPreviousHandle().isAt(resLoc) || result.getNextHandle().isAt(resLoc)) {
return null;
} else {
return new Handle(this, result.getLocation());
}
} else {
return null;
}
}
use of com.cburch.draw.model.Handle in project logisim-evolution by reds-heig.
the class Poly method canDeleteHandle.
@Override
public Handle canDeleteHandle(Location loc) {
int minHandles = closed ? 3 : 2;
Handle[] hs = handles;
if (hs.length <= minHandles) {
return null;
} else {
int qx = loc.getX();
int qy = loc.getY();
int w = Math.max(Line.ON_LINE_THRESH, getStrokeWidth() / 2);
for (Handle h : hs) {
int hx = h.getX();
int hy = h.getY();
if (LineUtil.distance(qx, qy, hx, hy) < w * w) {
return h;
}
}
return null;
}
}
use of com.cburch.draw.model.Handle in project logisim-evolution by reds-heig.
the class Poly method translate.
@Override
public void translate(int dx, int dy) {
Handle[] hs = handles;
Handle[] is = new Handle[hs.length];
for (int i = 0; i < hs.length; i++) {
is[i] = new Handle(this, hs[i].getX() + dx, hs[i].getY() + dy);
}
setHandles(is);
}
use of com.cburch.draw.model.Handle in project logisim-evolution by reds-heig.
the class Poly method recomputeBounds.
private void recomputeBounds() {
Handle[] hs = handles;
int x0 = hs[0].getX();
int y0 = hs[0].getY();
int x1 = x0;
int y1 = y0;
for (int i = 1; i < hs.length; i++) {
int x = hs[i].getX();
int y = hs[i].getY();
if (x < x0)
x0 = x;
if (x > x1)
x1 = x;
if (y < y0)
y0 = y;
if (y > y1)
y1 = y;
}
Bounds bds = Bounds.create(x0, y0, x1 - x0 + 1, y1 - y0 + 1);
int stroke = getStrokeWidth();
bounds = stroke < 2 ? bds : bds.expand(stroke / 2);
}
Aggregations