Package com.cburch.draw.model

Examples of com.cburch.draw.model.Handle


            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);
            }
        }
    }
View Full Code Here


    @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);
    }
View Full Code Here

    public List<Handle> getHandles(HandleGesture gesture) {
        Handle[] hs = handles;
        if (gesture == null) {
            return UnmodifiableList.decorate(Arrays.asList(hs));
        } else {
            Handle g = gesture.getHandle();
            Handle[] ret = new Handle[hs.length];
            for (int i = 0, n = hs.length; i < n; i++) {
                Handle h = hs[i];
                if (h.equals(g)) {
                    int x = h.getX() + gesture.getDeltaX();
                    int y = h.getY() + gesture.getDeltaY();
                    Location r;
                    if (gesture.isShiftDown()) {
                        Location prev = hs[(i + n - 1) % n].getLocation();
                        Location next = hs[(i + 1) % n].getLocation();
                        if (!closed) {
                            if (i == 0) {
                                prev = null;
                            }

                            if (i == n - 1) {
                                next = null;
                            }

                        }
                        if (prev == null) {
                            r = LineUtil.snapTo8Cardinals(next, x, y);
                        } else if (next == null) {
                            r = LineUtil.snapTo8Cardinals(prev, x, y);
                        } else {
                            Location to = Location.create(x, y);
                            Location a = LineUtil.snapTo8Cardinals(prev, x, y);
                            Location b = LineUtil.snapTo8Cardinals(next, x, y);
                            int ad = a.manhattanDistanceTo(to);
                            int bd = b.manhattanDistanceTo(to);
                            r = ad < bd ? a : b;
                        }
                    } else {
                        r = Location.create(x, y);
                    }
                    ret[i] = new Handle(this, r);
                } else {
                    ret[i] = h;
                }
            }
            return UnmodifiableList.decorate(Arrays.asList(ret));
View Full Code Here

    @Override
    public Handle moveHandle(HandleGesture gesture) {
        List<Handle> hs = getHandles(gesture);
        Handle[] is = new Handle[hs.size()];
        Handle ret = null;
        int i = -1;
        for (Handle h : hs) {
            i++;
            is[i] = h;
        }
View Full Code Here

            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;
        }
    }
View Full Code Here

    @Override
    public void insertHandle(Handle desired, Handle previous) {
        Location loc = desired.getLocation();
        Handle[] hs = handles;
        Handle prev;
        if (previous == null) {
            PolyUtil.ClosestResult result = PolyUtil.getClosestPoint(loc,
                    closed, hs);
            prev = result.getPreviousHandle();
        } else {
View Full Code Here

    @Override
    public Handle deleteHandle(Handle handle) {
        Handle[] hs = handles;
        int n = hs.length;
        Handle[] is = new Handle[n - 1];
        Handle previous = null;
        boolean deleted = false;
        for (int i = 0; i < n; i++) {
            if (deleted) {
                is[i - 1] = hs[i];
            } else if (hs[i].equals(handle)) {
View Full Code Here

        int xq = loc.getX();
        int yq = loc.getY();
        ClosestResult ret = new ClosestResult();
        ret.dist = Double.MAX_VALUE;
        if (hs.length > 0) {
            Handle h0 = hs[0];
            int x0 = h0.getX();
            int y0 = h0.getY();
            int stop = closed ? hs.length : (hs.length - 1);
            for(int i = 0; i < stop; i++) {
                Handle h1 = hs[(i + 1) % hs.length];
                int x1 = h1.getX();
                int y1 = h1.getY();
                double d = LineUtil.ptDistSqSegment(x0, y0, x1, y1, xq, yq);
                if (d < ret.dist) {
                    ret.dist = d;
                    ret.prevHandle = h0;
                    ret.nextHandle = h1;
                }
                h0 = h1;
                x0 = x1;
                y0 = y1;
            }
        }
        if (ret.dist == Double.MAX_VALUE) {
            return null;
        } else {
            Handle h0 = ret.prevHandle;
            Handle h1 = ret.nextHandle;
            double[] p = LineUtil.nearestPointSegment(xq, yq,
                    h0.getX(), h0.getY(), h1.getX(), h1.getY());
            ret.loc = Location.create((int) Math.round(p[0]),
                    (int) Math.round(p[1]));
            return ret;
        }
    }
View Full Code Here

        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;
        }
    }
View Full Code Here

    }

    @Override
    public Handle moveHandle(HandleGesture gesture) {
        Handle[] hs = getHandleArray(gesture);
        Handle ret = null;
        if (!hs[0].equals(p0)) {
            p0 = hs[0].getLocation();
            ret = hs[0];
        }
        if (!hs[1].equals(p1)) {
View Full Code Here

TOP

Related Classes of com.cburch.draw.model.Handle

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.