Search in sources :

Example 11 with PrecisionPoint

use of org.eclipse.draw2d.geometry.PrecisionPoint in project yamcs-studio by yamcs.

the class PointsUtil method rotate.

/**
 * Rotates the given {@link Point} with the given angle relative to the rotation point.
 * Converts the given point to a {@link PrecisionPoint} and calls {@link #doRotate(PrecisionPoint, double, PrecisionPoint)}.
 * @param point The {@link Point} to rotate
 * @param angle The angle to rotate (in Degrees)
 * @param rotationPoint The rotation point
 * @return The rotated Point
 */
public static PrecisionPoint rotate(final Point point, final double angle, final Point rotationPoint) {
    PrecisionPoint pPoint = point instanceof PrecisionPoint ? (PrecisionPoint) point : new PrecisionPoint(point);
    PrecisionPoint pRotationPoint = rotationPoint instanceof PrecisionPoint ? (PrecisionPoint) rotationPoint : new PrecisionPoint(rotationPoint);
    return doRotate(pPoint, angle, pRotationPoint);
}
Also used : PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint)

Example 12 with PrecisionPoint

use of org.eclipse.draw2d.geometry.PrecisionPoint in project yamcs-studio by yamcs.

the class ROIFigure method getGeoBoundsFromROI.

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());
}
Also used : PrecisionRectangle(org.eclipse.draw2d.geometry.PrecisionRectangle) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint) GraphArea(org.csstudio.swt.widgets.figures.IntensityGraphFigure.GraphArea)

Example 13 with PrecisionPoint

use of org.eclipse.draw2d.geometry.PrecisionPoint in project yamcs-studio by yamcs.

the class ROIFigure method getROIFromGeoBounds.

private Rectangle getROIFromGeoBounds(PrecisionRectangle roiBounds) {
    PrecisionPoint lt = ((GraphArea) getParent()).getDataLocation(roiBounds.preciseX(), roiBounds.preciseY());
    PrecisionPoint rb = ((GraphArea) getParent()).getDataLocation(roiBounds.preciseX() + roiBounds.preciseWidth(), roiBounds.preciseY() + roiBounds.preciseHeight());
    return new Rectangle((int) Math.round(lt.preciseX()) + intensityGraphFigure.getCropLeft(), (int) Math.round(lt.preciseY()) + intensityGraphFigure.getCropTop(), (int) Math.ceil(rb.preciseX() - lt.preciseX()), (int) Math.ceil(rb.preciseY() - lt.preciseY()));
}
Also used : PrecisionRectangle(org.eclipse.draw2d.geometry.PrecisionRectangle) Rectangle(org.eclipse.draw2d.geometry.Rectangle) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint) GraphArea(org.csstudio.swt.widgets.figures.IntensityGraphFigure.GraphArea)

Example 14 with PrecisionPoint

use of org.eclipse.draw2d.geometry.PrecisionPoint in project archi by archimatetool.

the class RoundedRectangleAnchor method ellipseAnchorGetLocation.

/**
 * Calculation of intersections points of one ellipse, represented by r, and
 * the line between ref and c.
 *
 * @param reference
 *            reference point for line end (end of the line)
 * @param r
 *            the rectangle of the ellipse, where the intersection points
 *            are wanted for
 * @param center
 *            center of the figure (start of the line)
 * @return Two intersection points of circle with the line. They could be
 *         equal, if the line only tangents. Returns null, if no
 *         intersection was found.
 */
private static Point[] ellipseAnchorGetLocation(final Point ref, final Rectangle r, Point c) {
    // Move the coordinates so that the center of ellipse is in the origin.
    final PrecisionPoint reference = new PrecisionPoint(r.getCenter().negate().translate(ref));
    final PrecisionPoint center = new PrecisionPoint(r.getCenter().negate().translate(c));
    // Transform the coordinate axis, to make the ellipse a circle with
    // radius 1.
    final double referenceX = reference.preciseX() * 2.0 / r.width;
    final double referenceY = reference.preciseY() * 2.0 / r.height;
    final double centerX = center.preciseX() * 2.0 / r.width;
    final double centerY = center.preciseY() * 2.0 / r.height;
    // the line is y=a*x+b detemine a and b
    final double a = (referenceY - centerY) / (referenceX - centerX);
    final double b = centerY - (centerX * a);
    // circle is x^2+y^2=1. With the line this leads to
    // 
    // x_{1/2} = +-Sqrt( (1-b*b)/((a*a+1)^2) + (a*a*b*b)/(a*a+1) ) -
    // (a*b)/a*a+1
    // 
    // y = a*x+b
    final double bSqr = Math.pow(b, 2);
    final double aSqr = Math.pow(a, 2);
    final double xSqrt = Math.sqrt((1 - bSqr) / (aSqr + 1) + (aSqr * bSqr) / (Math.pow(aSqr + 1, 2)));
    if (xSqrt == Double.NaN) {
        // no intersection found
        return null;
    }
    final double x1 = -xSqrt - (a * b) / (Math.pow(a, 2) + 1);
    final double x2 = +xSqrt - (a * b) / (Math.pow(a, 2) + 1);
    final double y1 = a * x1 + b;
    final double y2 = a * x2 + b;
    final Point p1 = new PrecisionPoint(x1 * r.width / 2.0, y1 * r.height / 2.0);
    final Point p2 = new PrecisionPoint(x2 * r.width / 2.0, y2 * r.height / 2.0);
    return new Point[] { r.getCenter().translate(p1), r.getCenter().translate(p2) };
}
Also used : Point(org.eclipse.draw2d.geometry.Point) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint)

Example 15 with PrecisionPoint

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

the class AdjustIdentityAnchorCommand method handleEdge.

private void handleEdge(Edge edge, EditPart editPart, boolean sourceAnchor) {
    Anchor anchorToModify;
    if (sourceAnchor) {
        anchorToModify = edge.getSourceAnchor();
    } else {
        anchorToModify = edge.getTargetAnchor();
    }
    String terminalString = composeTerminalString(DEFAULT_POINT);
    if (anchorToModify instanceof IdentityAnchor) {
        terminalString = ((IdentityAnchor) anchorToModify).getId();
    }
    PrecisionPoint anchorPoint = BaseSlidableAnchor.parseTerminalString(terminalString);
    PrecisionPoint newPoint = computeNewAnchor(anchorPoint, editPart);
    String newTerminalString = new SlidableAnchor(null, newPoint).getTerminal();
    if (anchorToModify instanceof IdentityAnchor) {
        ((IdentityAnchor) anchorToModify).setId(newTerminalString);
    } else if (anchorToModify == null) {
        // Create a new one
        IdentityAnchor newAnchor = NotationFactory.eINSTANCE.createIdentityAnchor();
        newAnchor.setId(newTerminalString);
        if (sourceAnchor) {
            edge.setSourceAnchor(newAnchor);
        } else {
            edge.setTargetAnchor(newAnchor);
        }
    }
}
Also used : IdentityAnchor(org.eclipse.gmf.runtime.notation.IdentityAnchor) SlidableAnchor(org.eclipse.gmf.runtime.gef.ui.figures.SlidableAnchor) IdentityAnchor(org.eclipse.gmf.runtime.notation.IdentityAnchor) Anchor(org.eclipse.gmf.runtime.notation.Anchor) BaseSlidableAnchor(org.eclipse.gmf.runtime.draw2d.ui.figures.BaseSlidableAnchor) SlidableAnchor(org.eclipse.gmf.runtime.gef.ui.figures.SlidableAnchor) BaseSlidableAnchor(org.eclipse.gmf.runtime.draw2d.ui.figures.BaseSlidableAnchor) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint)

Aggregations

PrecisionPoint (org.eclipse.draw2d.geometry.PrecisionPoint)20 Point (org.eclipse.draw2d.geometry.Point)9 Vector (org.eclipse.draw2d.geometry.Vector)7 PointList (org.eclipse.draw2d.geometry.PointList)5 Rectangle (org.eclipse.draw2d.geometry.Rectangle)5 PrecisionRectangle (org.eclipse.draw2d.geometry.PrecisionRectangle)3 LineSeg (org.eclipse.gmf.runtime.draw2d.ui.geometry.LineSeg)3 List (java.util.List)2 GraphArea (org.csstudio.swt.widgets.figures.IntensityGraphFigure.GraphArea)2 IFigure (org.eclipse.draw2d.IFigure)2 Dimension (org.eclipse.draw2d.geometry.Dimension)1 Straight (org.eclipse.draw2d.geometry.Straight)1 Transform (org.eclipse.draw2d.geometry.Transform)1 GraphicalEditPart (org.eclipse.gef.GraphicalEditPart)1 ZoomManager (org.eclipse.gef.editparts.ZoomManager)1 HandleBounds (org.eclipse.gef.handles.HandleBounds)1 ChangeBoundsRequest (org.eclipse.gef.requests.ChangeBoundsRequest)1 CreateRequest (org.eclipse.gef.requests.CreateRequest)1 IGraphicalEditPart (org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart)1 BaseSlidableAnchor (org.eclipse.gmf.runtime.draw2d.ui.figures.BaseSlidableAnchor)1