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);
}
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());
}
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()));
}
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) };
}
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);
}
}
}
Aggregations