Search in sources :

Example 26 with Handle

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);
        }
    }
}
Also used : Handle(com.cburch.draw.model.Handle)

Example 27 with Handle

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;
    }
}
Also used : Location(com.cburch.logisim.data.Location) Handle(com.cburch.draw.model.Handle)

Example 28 with Handle

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;
    }
}
Also used : Handle(com.cburch.draw.model.Handle)

Example 29 with Handle

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);
}
Also used : Handle(com.cburch.draw.model.Handle)

Example 30 with Handle

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);
}
Also used : Bounds(com.cburch.logisim.data.Bounds) Handle(com.cburch.draw.model.Handle)

Aggregations

Handle (com.cburch.draw.model.Handle)39 CanvasObject (com.cburch.draw.model.CanvasObject)9 Location (com.cburch.logisim.data.Location)9 Selection (com.cburch.draw.canvas.Selection)7 HandleGesture (com.cburch.draw.model.HandleGesture)7 Bounds (com.cburch.logisim.data.Bounds)5 ModelDeleteHandleAction (com.cburch.draw.actions.ModelDeleteHandleAction)1 ModelInsertHandleAction (com.cburch.draw.actions.ModelInsertHandleAction)1 ModelMoveHandleAction (com.cburch.draw.actions.ModelMoveHandleAction)1 ModelTranslateAction (com.cburch.draw.actions.ModelTranslateAction)1 CanvasModel (com.cburch.draw.model.CanvasModel)1 Circuit (com.cburch.logisim.circuit.Circuit)1 AppearanceElement (com.cburch.logisim.circuit.appear.AppearanceElement)1 Project (com.cburch.logisim.proj.Project)1 Graphics (java.awt.Graphics)1 Graphics2D (java.awt.Graphics2D)1 GeneralPath (java.awt.geom.GeneralPath)1 Map (java.util.Map)1 Element (org.w3c.dom.Element)1