Login | Register
My pages Projects Community openCollabNet

Discussions > issues > [Issue 293] Placing 2 vertices of a polyline on top of eachother should merge

gef
Discussion topic

Back to topic list

[Issue 293] Placing 2 vertices of a polyline on top of eachother should merge

Reply

Author tfmorris
Full name Tom Morris
Date 2006-11-18 13:29:10 PST
Message http://gef.tigris.or​g/issues/show_bug.cg​i?id=293






------- Additional comments from tfmorris at tigris dot org Sat Nov 18 13:29:10 -0800 2006 -------
Attached is the prototype code that I was working on. Since I don't have access
to GEF, the experimentation was being done in the context of ArgoUML's
FigEdgeModelElement. I know it still had some problems, but I don't remember
exactly what they were.

In addition to removing vertices which are dropped (close enough to) on top of
each other, I think they should also disappear of dropped on the figure attached
to end of the line. That piece I hadn't yet attempted to address.

    final static double EPSILON_ANGLE = 7.0; // degrees
    final static double EPSILON_DISTANCE = 5 * 5; // screen pixels (squared)
    
    /*
     * Traverse the edge and see if there are any handles which should
     * be removed because they are either so close together as to be
     * considered colocated or so
     */
    private void mergeHandles() {

        FigPoly poly = (FigPoly) getFig();
        int pointCount = poly.getNumPoints();
        Point[] points = poly.getPoints();
        
        for (int i = 1; i < pointCount - 1; i++) {
            Point previous = points[i - 1];
            Point current = points[i];
            Point next = points[i + 1];

            // TODO: Remove points which are enclosed in endpoint fig

            // remove points that are too close to each other
            if (squaredDistance(previous, current) < EPSILON_DISTANCE
                    || squaredDistance(current, next) < EPSILON_DISTANCE ) {
                poly.removePoint(i);
                break;
            }
            // remove points that are too close to each other
            if (squaredDistance(previous, current) < EPSILON_DISTANCE
                    || squaredDistance(current, next) < EPSILON_DISTANCE ) {
                poly.removePoint(i);
                break;
            }

            double segment1Angle = Geometry.segmentAngle(previous, current);
            double segment2Angle = Geometry.segmentAngle(current, next);
            double difference =
                Geometry.diffAngle(s​egment1Angle, segment2Angle);

            if (difference < EPSILON_ANGLE) {
                //poly.removePoint(i);
            }
        }

        calcBounds();
    }

« Previous message in topic | 1 of 1 | Next message in topic »

Messages

Show all messages in topic

[Issue 293] Placing 2 vertices of a polyline on top of eachother should merge tfmorris Tom Morris 2006-11-18 13:29:10 PST
Messages per page: