use of org.eclipse.draw2d.geometry.PointList in project cogtool by cogtool.
the class BezierPolylineConnection method generateBezierPoints.
/**
* Generates the Bezier curve points
* @param start the start of the curve
* @param end the end of the curve
*/
public void generateBezierPoints(Point start, Point end) {
PointList newPoints = new PointList();
// the vertical space between the line start/end
int spacing = 25;
// and the middle two points
Point[] bezierPoints = new Point[4];
int position = 0;
if ((start.x <= end.x) && (start.y > end.y)) {
position = 1;
} else if ((start.x > end.x) && (start.y > end.y)) {
position = 2;
} else if ((start.x > end.x) && (start.y <= end.y)) {
position = 3;
} else if ((start.x <= end.x) && (start.y <= end.y)) {
position = 4;
}
// Set the start and end
bezierPoints[0] = start;
bezierPoints[3] = end;
// Set the middle points
// Diagram at: http://cogtool.hcii.cs.cmu.edu/trac/browser/docs/Design%20%26%20Architecture/bezierPoints.ppt
// distance between the two points
double Mh = 0;
// x distance between the two points
double Mx = 0;
// y distance between the two points
double My = 0;
// the angle MhMx
double Ma = 0;
// distance between the start point and P1
double P1h = 0;
// x value of the point below B1 (Bezier middle point 1)
double P1x = 0;
// y value of the point below B1 (Bezier middle point 1)
double P1y = 0;
// distance between P1 and B1
double B1h = 0;
// x distance between P1 and B1
double B1x = 0;
// y distance between P1 and B1
double B1y = 0;
// distance between the start point and P2
double P2h = 0;
// x value of the point below B2 (Bezier middle point 2)
double P2x = 0;
// y value of the point below B2 (Bezier middle point 2)
double P2y = 0;
// distance between P2 and B2
double B2h = 0;
// x distance between P1 and B2
double B2x = 0;
// y distance between P1 and B2
double B2y = 0;
Mx = Math.abs(end.x - start.x);
My = Math.abs(end.y - start.y);
Mh = Math.sqrt((Math.pow(Mx, 2) + Math.pow(My, 2)));
Ma = Math.atan((My / Mx));
P1h = (0.25 * Mh);
P2h = (0.75 * Mh);
if (position == 1) {
P1x = start.x + (Math.cos(Ma) * P1h);
P1y = start.y - (Math.sin(Ma) * P1h);
P2x = start.x + (Math.cos(Ma) * P2h);
P2y = start.y - (Math.sin(Ma) * P2h);
} else if (position == 2) {
P1x = start.x - (Math.cos(Ma) * P1h);
P1y = start.y - (Math.sin(Ma) * P1h);
P2x = start.x - (Math.cos(Ma) * P2h);
P2y = start.y - (Math.sin(Ma) * P2h);
} else if (position == 3) {
P1x = start.x - (Math.cos(Ma) * P1h);
P1y = start.y + (Math.sin(Ma) * P1h);
P2x = start.x - (Math.cos(Ma) * P2h);
P2y = start.y + (Math.sin(Ma) * P2h);
} else if (position == 4) {
P1x = start.x + (Math.cos(Ma) * P1h);
P1y = start.y + (Math.sin(Ma) * P1h);
P2x = start.x + (Math.cos(Ma) * P2h);
P2y = start.y + (Math.sin(Ma) * P2h);
}
boolean above = (connections % 2) == 0;
B1h = spacing * (connections / 2);
B2h = spacing * (connections / 2);
B1x = Math.sin(Ma) * B1h;
B1y = Math.cos(Ma) * B1h;
B2x = Math.sin(Ma) * B2h;
B2y = Math.cos(Ma) * B2h;
if (position == 1) {
if (above) {
bezierPoints[1] = new Point((int) (P1x - B1x), (int) (P1y - B1y));
bezierPoints[2] = new Point((int) (P2x - B2x), (int) (P2y - B2y));
} else {
bezierPoints[1] = new Point((int) (P1x + B1x), (int) (P1y + B1y));
bezierPoints[2] = new Point((int) (P2x + B2x), (int) (P2y + B2y));
}
} else if (position == 2) {
if (above) {
bezierPoints[1] = new Point((int) (P1x - B1x), (int) (P1y + B1y));
bezierPoints[2] = new Point((int) (P2x - B2x), (int) (P2y + B2y));
} else {
bezierPoints[1] = new Point((int) (P1x + B1x), (int) (P1y - B1y));
bezierPoints[2] = new Point((int) (P2x + B2x), (int) (P2y - B2y));
}
} else if (position == 3) {
if (above) {
bezierPoints[1] = new Point((int) (P1x + B1x), (int) (P1y + B1y));
bezierPoints[2] = new Point((int) (P2x + B2x), (int) (P2y + B2y));
} else {
bezierPoints[1] = new Point((int) (P1x - B1x), (int) (P1y - B1y));
bezierPoints[2] = new Point((int) (P2x - B2x), (int) (P2y - B2y));
}
} else if (position == 4) {
if (above) {
bezierPoints[1] = new Point((int) (P1x + B1x), (int) (P1y - B1y));
bezierPoints[2] = new Point((int) (P2x + B2x), (int) (P2y - B2y));
} else {
bezierPoints[1] = new Point((int) (P1x - B1x), (int) (P1y + B1y));
bezierPoints[2] = new Point((int) (P2x - B2x), (int) (P2y + B2y));
}
}
// Calculate the bezier curve
double x1 = bezierPoints[0].x;
double y1 = bezierPoints[0].y;
double x2;
double y2;
double t = 0;
double k = 0.025;
for (t = k; t <= 1 + k; t += k) {
// Use Berstein polynomials
x2 = (bezierPoints[0].x + t * (-bezierPoints[0].x * 3 + t * (3 * bezierPoints[0].x - bezierPoints[0].x * t))) + t * (3 * bezierPoints[1].x + t * (-6 * bezierPoints[1].x + bezierPoints[1].x * 3 * t)) + t * t * (bezierPoints[2].x * 3 - bezierPoints[2].x * 3 * t) + bezierPoints[3].x * t * t * t;
y2 = (bezierPoints[0].y + t * (-bezierPoints[0].y * 3 + t * (3 * bezierPoints[0].y - bezierPoints[0].y * t))) + t * (3 * bezierPoints[1].y + t * (-6 * bezierPoints[1].y + bezierPoints[1].y * 3 * t)) + t * t * (bezierPoints[2].y * 3 - bezierPoints[2].y * 3 * t) + bezierPoints[3].y * t * t * t;
// Add the point to the curve
newPoints.addPoint(new org.eclipse.draw2d.geometry.Point((int) x1, (int) y1));
x1 = x2;
y1 = y2;
}
// Add the end point
newPoints.addPoint(bezierPoints[3]);
// Update line to the new points
setPoints(newPoints);
}
use of org.eclipse.draw2d.geometry.PointList in project dbeaver by serge-rider.
the class GraphAnimation method playbackState.
public static boolean playbackState(Connection conn) {
if (!PLAYBACK)
return false;
PointList list1 = (PointList) initialStates.get(conn);
PointList list2 = (PointList) finalStates.get(conn);
if (list1 == null) {
conn.setVisible(false);
return true;
}
if (list1.size() == list2.size()) {
Point pt1 = new Point(), pt2 = new Point();
PointList points = conn.getPoints();
points.removeAllPoints();
for (int i = 0; i < list1.size(); i++) {
list1.getPoint(pt2, i);
list2.getPoint(pt1, i);
pt1.x = (int) Math.round(pt1.x * progress + (1 - progress) * pt2.x);
pt1.y = (int) Math.round(pt1.y * progress + (1 - progress) * pt2.y);
points.addPoint(pt1);
}
conn.setPoints(points);
}
return true;
}
use of org.eclipse.draw2d.geometry.PointList in project tdi-studio-se by Talend.
the class DocumentBusinessItemShapeFigure method drawFigure.
private void drawFigure(Rectangle r, Graphics graphics) {
int sinHeight = r.height / 8;
// PTODO mhelleboid handle zoom and size
// PTODO mhelleboid have a look at graphics.drawArc
int sinPoints = 14;
PointList pointList = new PointList();
pointList.removeAllPoints();
pointList.addPoint(r.x + r.width, r.y + r.height - sinHeight / 2);
pointList.addPoint(r.x + r.width, r.y);
pointList.addPoint(r.x, r.y);
pointList.addPoint(r.x, r.y + r.height - sinHeight / 2);
for (int i = 0; i < sinPoints; i = i + 1) {
double rad = 2 * i * Math.PI / sinPoints;
int x = r.x + i * r.width / sinPoints;
int y = (int) (r.y + r.height - sinHeight / 2 + sinHeight * Math.sin(rad) / 2);
pointList.addPoint(x, y);
}
graphics.fillPolygon(pointList);
graphics.drawPolygon(pointList);
}
use of org.eclipse.draw2d.geometry.PointList in project tdi-studio-se by Talend.
the class GearBusinessItemShapeFigure method drawFigure.
private void drawFigure(Rectangle r, Graphics graphics) {
int nbTeeth = 8;
double teethAngle = 0.23;
double innerExternalRatio = 0.80;
Point center = new Point(r.x + r.width / 2, r.y + r.height / 2);
int horizontalExternalRadius = r.width / 2;
int verticalExternalRadius = r.height / 2;
int horizontalInnerRadius = (int) (horizontalExternalRadius * innerExternalRatio);
int verticalInnerRadius = (int) (verticalExternalRadius * innerExternalRatio);
PointList pointList = new PointList();
boolean externalFirst = false;
for (double i = 0; i < 2 * Math.PI; i = i + Math.PI * 2 / (nbTeeth * 2)) {
double j = (externalFirst ? i - Math.PI / nbTeeth * teethAngle : i + Math.PI / nbTeeth * teethAngle);
Point externalPoint = center.getTranslated((int) (Math.cos(j) * horizontalExternalRadius), (int) (Math.sin(j) * verticalExternalRadius));
Point internalPoint = center.getTranslated((int) (Math.cos(i) * horizontalInnerRadius), (int) (Math.sin(i) * verticalInnerRadius));
if (externalFirst) {
pointList.addPoint(externalPoint);
pointList.addPoint(internalPoint);
} else {
pointList.addPoint(internalPoint);
pointList.addPoint(externalPoint);
}
externalFirst = !externalFirst;
}
graphics.drawPolygon(pointList);
graphics.fillPolygon(pointList);
}
use of org.eclipse.draw2d.geometry.PointList in project tdi-studio-se by Talend.
the class DataBusinessItemShapeFigure method drawFigure.
private void drawFigure(Rectangle r, Graphics graphics) {
int offset = (int) (r.width * 0.15);
PointList pointList = new PointList();
pointList.removeAllPoints();
pointList.addPoint(r.x + offset, r.y);
pointList.addPoint(r.x + r.width, r.y);
pointList.addPoint(r.x + r.width - offset, r.y + r.height);
pointList.addPoint(r.x, r.y + r.height);
graphics.fillPolygon(pointList);
graphics.drawPolygon(pointList);
}
Aggregations