Java Code Examples for org.eclipse.draw2d.geometry.PrecisionPoint#setPreciseX()

The following examples show how to use org.eclipse.draw2d.geometry.PrecisionPoint#setPreciseX() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RubberBandRoutingSupport.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Find first intersection with target box, walking from start to end.
 *
 * @param points
 * @param rect
 * @param isSelfAssoc
 */
protected void cutOffEnd(List<PrecisionPoint> points, Rectangle rect, boolean isSelfAssoc) {
	// determine top, right, bottom, and left sides
	final List<Line> segs = geom.getOutlineSegments(geom.toRectangle(rect));

	// need four points for self-associations
	int startIndex = isSelfAssoc ? 3 : 1;
	if (startIndex >= points.size()) {
		return;
	}

	// walk from start to end
	PrecisionPoint p1 = geom.toPP(points.get(startIndex - 1));
	for (int i = startIndex; i < points.size(); i++) {
		final PrecisionPoint p2 = geom.toPP(points.get(i));
		final Line line = new Line(p1, p2);
		final PrecisionPoint poi = geom.findNearestIntersection(line, segs, p1);
		if (poi != null) {
			for (int j = points.size() - 1; j >= i; j--) {
				points.remove(j);
			}
			if (p1.preciseX() == p2.preciseX()) {
				poi.setPreciseX(p1.preciseX());
			} else {
				poi.setPreciseY(p1.preciseY());
			}
			points.add(poi);
			return;
		}
		p1 = p2;
	}
}
 
Example 2
Source File: RubberBandRoutingSupport.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Find first intersection with source box, walking from end to start.
 *
 * @param points
 * @param rect
 * @param isSelfAssoc
 */
protected void cutOffStart(List<PrecisionPoint> points, Rectangle rect, boolean isSelfAssoc) {
	// determine top, right, bottom, and left sides
	final List<Line> segs = geom.getOutlineSegments(geom.toRectangle(rect));

	// need at least four points for self-assocs
	int startIndex = isSelfAssoc ? points.size() - 4 : points.size() - 2;
	if ((startIndex < 0) || ((startIndex + 1) >= points.size())) {
		return;
	}

	// walk from end to start
	PrecisionPoint p2 = geom.toPP(points.get(startIndex + 1));
	for (int i = startIndex; i >= 0; i--) {
		final PrecisionPoint p1 = geom.toPP(points.get(i));
		final Line line = new Line(p1, p2);
		final PrecisionPoint poi = geom.findNearestIntersection(line, segs, p2);
		if (poi != null) {
			for (int j = i; j >= 0; j--) {
				points.remove(j);
			}
			if (p1.preciseX() == p2.preciseX()) {
				poi.setPreciseX(p1.preciseX());
			} else {
				poi.setPreciseY(p1.preciseY());
			}
			points.add(0, poi);
			return;
		}
		p2 = p1;
	}
}