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

The following examples show how to use org.eclipse.draw2d.geometry.PrecisionPoint#preciseX() . 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: GeometryUtil.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
public double getParameterAt(Straight s, PrecisionPoint p) {
	if (!contains(s, p)) {
		throw new IllegalArgumentException(
				"The given position Vector has to be on this Straight: getParameterAt(" + s + ", " + p + ")");
	}

	if (Math.abs(s.direction.preciseX()) > Math.abs(s.direction.preciseY())) {
		return (p.preciseX() - s.position.preciseX()) / s.direction.preciseX();
	}
	if (s.direction.preciseY() != 0) {
		return (p.preciseY() - s.position.preciseY()) / s.direction.preciseY();
	}

	throw new IllegalStateException(
			"The direction Vector of this Straight may not be (0, 0) for this computation: getParameterAt(" + s
					+ ", " + p + ")");
}
 
Example 2
Source File: ROIFigure.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
private PrecisionRectangle getGeoBoundsFromROI(Rectangle roiDataBounds){
	PrecisionPoint lt = ((GraphArea)getParent()).getGeoLocation(roiDataBounds.preciseX()-intensityGraphFigure.getCropLeft(), 
			roiDataBounds.preciseY()-intensityGraphFigure.getCropTop());
	PrecisionPoint rb = ((GraphArea)getParent()).getGeoLocation(
			roiDataBounds.preciseX() + roiDataBounds.preciseWidth() -intensityGraphFigure.getCropLeft(), 
			roiDataBounds.preciseY() + roiDataBounds.preciseHeight() -intensityGraphFigure.getCropTop());
	return new PrecisionRectangle(lt.preciseX()-getBounds().x, lt.preciseY()-getBounds().y, rb.preciseX() - lt.preciseX(), rb.preciseY() - lt.preciseY());			
}
 
Example 3
Source File: ConnData.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
private MaxMoveDelta getMaxMoveDelta(Rectangle bounds, boolean isVerticalSegment, PrecisionPoint anchorPoint) {
		if (isVerticalSegment) {
			// move in X
			double x = anchorPoint.preciseX();
			double bx = bounds.preciseX() + SideDistance;
			double bx2 = (bx + bounds.preciseWidth()) - SideDistance - SideDistance;
			if (x <= bx) {
				x = bx + 1;
			}
			if (x >= bx2) {
				x = bx2 - 1;
			}
			return new MaxMoveDelta(false, x - bx2, x - bx);
		} else {
			// move in Y
			double y = anchorPoint.preciseY();
			double by = bounds.preciseY() + SideDistance;
			double by2 = (by + bounds.preciseHeight()) - SideDistance - SideDistance;
//			System.out.println("Y at " + y + ", by=" + by + " to " + by2);
			if (y <= by) {
				y = by + 1;
			}
			if (y >= by2) {
				y = by2 - 1;
			}
			return new MaxMoveDelta(true, y - by2, y - by);
		}
	}
 
Example 4
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 5
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;
	}
}
 
Example 6
Source File: AdjustIdentityAnchorCommand.java    From statecharts with Eclipse Public License 1.0 4 votes vote down vote up
protected Point getAnchorRelativePoint(PrecisionPoint currentAnchorPoint, Rectangle bounds) {
	return new PrecisionPoint(bounds.width() * currentAnchorPoint.preciseX(),
			bounds.height() * currentAnchorPoint.preciseY());
}
 
Example 7
Source File: FixedConnectionAnchor.java    From statecharts with Eclipse Public License 1.0 4 votes vote down vote up
public FixedConnectionAnchor(IFigure owner, PrecisionPoint offset) {
	this(owner, offset.preciseX(), offset.preciseY());
}
 
Example 8
Source File: GeometryUtil.java    From statecharts with Eclipse Public License 1.0 4 votes vote down vote up
public PrecisionPoint getAdded(PrecisionPoint p, double dx, double dy) {
	return new PrecisionPoint(p.preciseX() + dx, p.preciseY() + dy);
}
 
Example 9
Source File: GeometryUtil.java    From statecharts with Eclipse Public License 1.0 4 votes vote down vote up
public PrecisionPoint getSubtracted(PrecisionPoint v, PrecisionPoint w) {
	return new PrecisionPoint(v.preciseX() - w.preciseX(), v.preciseY() - w.preciseY());
}
 
Example 10
Source File: CustomAnchor.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Point getOrthogonalLocation(Point orthoReference) {
    PrecisionPoint ownReference = new PrecisionPoint(getReferencePoint());
    //      PrecisionRectangle bounds = new PrecisionRectangle(getBox());
    PrecisionRectangle bounds = new PrecisionRectangle(CustomRectilinearRouter.getAnchorableFigureBounds(getOwner()));
    getOwner().translateToAbsolute(bounds);
    bounds.expand(0.000001, 0.000001);
    PrecisionPoint preciseOrthoReference = new PrecisionPoint(orthoReference);
    int orientation = PositionConstants.NONE;
    if (bounds.contains(preciseOrthoReference)) {
        int side = getClosestSide(ownReference, bounds);
        switch (side) {
            case PositionConstants.LEFT:
            case PositionConstants.RIGHT:
                ownReference.preciseY = preciseOrthoReference.preciseY();
                orientation = PositionConstants.HORIZONTAL;
                break;
            case PositionConstants.TOP:
            case PositionConstants.BOTTOM:
                ownReference.preciseX = preciseOrthoReference.preciseX();
                orientation = PositionConstants.VERTICAL;
                break;
        }
    } else if (preciseOrthoReference.preciseX >= bounds.preciseX
            && preciseOrthoReference.preciseX <= bounds.preciseX + bounds.preciseWidth) {
        ownReference.preciseX = preciseOrthoReference.preciseX;
        orientation = PositionConstants.VERTICAL;
    } else if (preciseOrthoReference.preciseY >= bounds.preciseY
            && preciseOrthoReference.preciseY <= bounds.preciseY + bounds.preciseHeight) {
        ownReference.preciseY = preciseOrthoReference.preciseY;
        orientation = PositionConstants.HORIZONTAL;
    }
    ownReference.updateInts();

    Point location = getLocation(ownReference, preciseOrthoReference);
    if (location == null) {
        location = getLocation(orthoReference);
        orientation = PositionConstants.NONE;
    }

    if (orientation != PositionConstants.NONE) {
        PrecisionPoint loc = new PrecisionPoint(location);
        if (orientation == PositionConstants.VERTICAL) {
            loc.preciseX = preciseOrthoReference.preciseX;
        } else {
            loc.preciseY = preciseOrthoReference.preciseY;
        }
        loc.updateInts();
        location = loc;
    }

    return location;
}