Search in sources :

Example 1 with Straight

use of org.eclipse.draw2d.geometry.Straight in project statecharts by Yakindu.

the class EdgeLabelQuery method getSameLineStatus.

/**
 * Check if the <code>segment</code> is on the same line as the
 * <code>referenceSegment</code> and if it is in the same direction or not.
 *
 * @param referenceSegment
 *            The reference segment.
 * @param segment
 *            The segment to test
 * @return one of these statuses {@link #NOT_ON_SAME_LINE},
 *         {@link #ON_SAME_LINE_SAME_DIRECTION} or
 *         {@link #ON_SAME_LINE_OPPOSITE_DIRECTION}.
 */
private int getSameLineStatus(LineSeg referenceSegment, LineSeg segment) {
    int result = NOT_ON_SAME_LINE;
    if (segment.length() != 0) {
        Vector referenceVector = new Vector(referenceSegment.getTerminus().x - referenceSegment.getOrigin().x, referenceSegment.getTerminus().y - referenceSegment.getOrigin().y);
        Vector vector = new Vector(segment.getTerminus().x - segment.getOrigin().x, segment.getTerminus().y - segment.getOrigin().y);
        double angle = referenceVector.getAngle(vector);
        if (angle == 0 || angle == 180) {
            Straight straight = new Straight(new PrecisionPoint(segment.getOrigin()), new PrecisionPoint(segment.getTerminus()));
            double distToInfiniteLine = straight.getDistance(new Vector(referenceSegment.getOrigin().x, referenceSegment.getOrigin().y));
            if (distToInfiniteLine < DISTANCE_TOLERANCE) {
                if (angle == 180) {
                    result = ON_SAME_LINE_OPPOSITE_DIRECTION;
                } else {
                    result = ON_SAME_LINE_SAME_DIRECTION;
                }
            }
        }
    }
    return result;
}
Also used : Vector(org.eclipse.draw2d.geometry.Vector) Point(org.eclipse.draw2d.geometry.Point) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint) Straight(org.eclipse.draw2d.geometry.Straight)

Aggregations

Point (org.eclipse.draw2d.geometry.Point)1 PrecisionPoint (org.eclipse.draw2d.geometry.PrecisionPoint)1 Straight (org.eclipse.draw2d.geometry.Straight)1 Vector (org.eclipse.draw2d.geometry.Vector)1