use of org.antlr.xjlib.appkit.gview.base.Vector2D in project antlrworks by antlr.
the class SLinkArc method setFlatenessByMouse.
public void setFlatenessByMouse(Vector2D mouse) {
Vector2D corde = getEndWithOffset().sub(getStartWithOffset());
double dot = mouse.sub(getStartWithOffset()).dot(corde.normalize());
corde.setLength(dot);
Vector2D z = getStartWithOffset().add(corde);
Vector2D f = mouse.sub(z);
double cross = corde.cross(f);
if (cross == 0)
setFlateness(0);
else
setFlateness(-2 * f.length() * cross / Math.abs(cross));
}
use of org.antlr.xjlib.appkit.gview.base.Vector2D in project antlrworks by antlr.
the class SLinkBezier method bspline.
/** This method comes from:
*
Code used from BSpline.java (c) Leen Ammeraal with its authorization (see e-mail below)
http://home.wxs.nl/~ammeraal/grjava.html
Hello Jean,
Thank you for your interest in my program Bspline.java. Yes, you can use it in your software,
preferably giving me credit in the about box, as you suggest. If this cannot be done, I trust you
will refer to my book in other ways, as you think appropriate.
Best wishes,
Leen Ammeraal
*/
public void bspline(Graphics g) {
g.setColor(color);
int n = controlPointsAbs.length;
double xA, yA, xB, yB, xC, yC, xD, yD, a0, a1, a2, a3, b0, b1, b2, b3, x = 0, y = 0, x0, y0;
// this chooses how many point to go trough the curve, smaller number, more points.
double time_delta = 0.1;
boolean first = true;
double fx = 0, fy = 0;
for (int i = 1; i < n - 2; i++) {
// Loop Through Control Points
Vector2D p0 = controlPointsAbs[i - 1];
Vector2D p1 = controlPointsAbs[i];
Vector2D p2 = controlPointsAbs[i + 1];
Vector2D p3 = controlPointsAbs[i + 2];
xA = p0.x;
xB = p1.x;
xC = p2.x;
xD = p3.x;
yA = p0.y;
yB = p1.y;
yC = p2.y;
yD = p3.y;
a3 = (-xA + 3 * (xB - xC) + xD) / 6;
b3 = (-yA + 3 * (yB - yC) + yD) / 6;
a2 = (xA - 2 * xB + xC) / 2;
b2 = (yA - 2 * yB + yC) / 2;
a1 = (xC - xA) / 2;
b1 = (yC - yA) / 2;
a0 = (xA + 4 * xB + xC) / 6;
b0 = (yA + 4 * yB + yC) / 6;
for (double t = 0; t <= 1.0; t += time_delta) {
x0 = x;
y0 = y;
double x1 = ((a3 * t + a2) * t + a1) * t + a0;
double y1 = ((b3 * t + b2) * t + b1) * t + b0;
x = (int) Math.round(x1);
y = (int) Math.round(y1);
if (first) {
first = false;
fx = x;
fy = y;
} else {
g.drawLine((int) x0, (int) y0, (int) x, (int) y);
}
//g.setColor(Color.red);
//g.fillRect((int)(x-2), (int)(y-2), 4, 4);
}
}
// Perimeter of the source to the first point of the bezier curve
Vector2D p0 = controlPointsAbs[0];
g.drawLine((int) p0.getX(), (int) p0.getY(), (int) fx, (int) fy);
// Last point of the bezier curve to the perimeter of the target
Vector2D p1 = controlPointsAbs[n - 1];
g.drawLine((int) x, (int) y, (int) p1.getX(), (int) p1.getY());
arrow.setAnchor(p1.getX(), p1.getY());
arrow.setDirection(new Vector2D(x - p1.getX(), y - p1.getY()));
arrow.draw(g);
}
use of org.antlr.xjlib.appkit.gview.base.Vector2D in project antlrworks by antlr.
the class SLinkBezier method lines.
/** Debug method used to print only the control points
*
*/
public void lines(Graphics g) {
g.setColor(color);
for (int i = 0; i < controlPointsAbs.length; i++) {
Vector2D pt = controlPointsAbs[i];
double x = pt.x;
double y = pt.y;
g.fillRect((int) (x - 2), (int) (y - 2), 4, 4);
}
}
use of org.antlr.xjlib.appkit.gview.base.Vector2D in project antlrworks by antlr.
the class SLinkBezier method absToRel.
public Vector2D absToRel(Vector2D p) {
if (selfLoop) {
return p.sub(start);
} else {
Vector2D z = end.sub(start);
Vector2D a = p.sub(start);
double lb = a.dot(z) / z.length();
Vector2D b = z.normalize().setLength(lb);
Vector2D c = a.sub(b);
double lc = c.length() * (a.crossSign(z));
return new Vector2D(lb, lc);
}
}
use of org.antlr.xjlib.appkit.gview.base.Vector2D in project antlrworks by antlr.
the class SLinkElbowBottomBottom method buildHorizontalPath.
public void buildHorizontalPath(int direction) {
Vector2D start_ = link.getStartWithOffset();
Vector2D end_ = link.getEndWithOffset();
if (link.offsetToMouse != null) {
double y = link.offsetToMouse.y + link.start.y;
start_.y = end_.y = y;
}
double farest_y = 0;
if (direction == BOTTOM_BOTTOM)
farest_y = Math.max(start_.y, end_.y);
else
farest_y = Math.min(start_.y, end_.y);
Vector2D p1 = start_.add(new Vector2D(0, farest_y - start_.y));
Vector2D p2 = end_.add(new Vector2D(0, farest_y - end_.y));
path.add(link.start);
path.add(start_);
path.add(p1);
path.add(p2);
path.add(end_);
path.add(link.end);
if (direction == BOTTOM_BOTTOM)
link.label.setPosition(p1.add(p2.sub(p1).stretch(0.5)).shift(0, LABEL_OFFSET));
else
link.label.setPosition(p1.add(p2.sub(p1).stretch(0.5)).shift(0, -LABEL_OFFSET));
}
Aggregations