use of org.graphstream.ui.geom.Point2 in project gs-ui-javafx by graphstream.
the class ArrowOnEdge method makeOnCurve.
private void makeOnCurve(boolean forShadow, DefaultCamera2D camera) {
Tuple<Point2, Double> tuple = CubicCurve.approxIntersectionPointOnCurve(theEdge, theConnector, camera);
Point2 p1 = tuple.x;
double t = tuple.y;
Style style = theEdge.getStyle();
Point3 p2 = CubicCurve.eval(theConnector.fromPos(), theConnector.byPos1(), theConnector.byPos2(), theConnector.toPos(), t - 0.05f);
// XXX The choice of the number above (0.05f) is problematic
Vector2 dir = new Vector2(p1.x - p2.x, p1.y - p2.y);
// Clearly it should be chosen according to the length
dir.normalize();
// of the arrow compared to the length of the curve, however
dir.scalarMult(theSize.x);
// computing the curve length (see CubicCurve) is costly. XXX
Vector2 per = new Vector2(dir.y(), -dir.x());
per.normalize();
per.scalarMult(theSize.y);
// Create a polygon.
theShape = new Path2D(5, true);
theShape.moveTo(p1.x, p1.y);
theShape.lineTo(p1.x - dir.x() + per.x(), p1.y - dir.y() + per.y());
theShape.lineTo(p1.x - dir.x() - per.x(), p1.y - dir.y() - per.y());
theShape.closePath();
}
use of org.graphstream.ui.geom.Point2 in project gs-ui-javafx by graphstream.
the class CircleOnEdge method makeOnCurve.
private void makeOnCurve(boolean forShadow, DefaultCamera2D camera) {
Tuple<Point2, Double> tuple = CubicCurve.approxIntersectionPointOnCurve(theEdge, theConnector, camera);
Point2 p1 = tuple.x;
double t = tuple.y;
Style style = theEdge.getStyle();
Point3 p2 = CubicCurve.eval(theConnector.fromPos(), theConnector.byPos1(), theConnector.byPos2(), theConnector.toPos(), t - 0.1f);
Vector2 dir = new Vector2(p1.x - p2.x, p1.y - p2.y);
dir.normalize();
dir.scalarMult(theSize.x / 2);
// Create a polygon.
theShape.setFrame((p1.x - dir.x()) - (theSize.x / 2), (p1.y - dir.y()) - (theSize.y / 2), theSize.x, theSize.y);
}
use of org.graphstream.ui.geom.Point2 in project gs-ui-javafx by graphstream.
the class CubicCurve method approxLengthOfCurveQuick.
/**
* Evaluate the length of a Bézier curve by taking four points on the curve and summing the lengths of
* the five segments thus defined.
*/
public static double approxLengthOfCurveQuick(Connector c) {
Point2 ip0 = CubicCurve.eval(c.fromPos(), c.byPos1(), c.byPos2(), c.toPos(), 0.1f);
Point2 ip1 = CubicCurve.eval(c.fromPos(), c.byPos1(), c.byPos2(), c.toPos(), 0.3f);
Point2 ip2 = CubicCurve.eval(c.fromPos(), c.byPos1(), c.byPos2(), c.toPos(), 0.7f);
Point2 ip3 = CubicCurve.eval(c.fromPos(), c.byPos1(), c.byPos2(), c.toPos(), 0.9f);
return (c.fromPos().distance(ip0) + ip0.distance(ip1) + ip1.distance(ip2) + ip2.distance(ip3) + ip3.distance(c.toPos()));
}
use of org.graphstream.ui.geom.Point2 in project gs-ui-javafx by graphstream.
the class CubicCurve method approxLengthOfCurve.
/**
* Evaluate the length of a Bézier curve by taking n points on the curve and summing the lengths of
* the n+1 segments thus defined.
*/
public static double approxLengthOfCurve(Connector c) {
double inc = 0.1;
double i = inc;
double len = 0.0;
Point2 p0 = c.fromPos();
while (i < 1f) {
Point2 p = CubicCurve.eval(c.fromPos(), c.byPos1(), c.byPos2(), c.toPos(), i);
i += inc;
len += p0.distance(p);
p0 = p;
}
len += p0.distance(c.toPos());
return len;
}
use of org.graphstream.ui.geom.Point2 in project gs-ui-javafx by graphstream.
the class ImageOnEdge method makeOnCurve.
private void makeOnCurve(boolean forShadow, DefaultCamera2D camera) {
Tuple<Point2, Double> tuple = CubicCurve.approxIntersectionPointOnCurve(theEdge, theConnector, camera);
Point2 p1 = tuple.x;
double t = tuple.y;
Style style = theEdge.getStyle();
Point3 p2 = CubicCurve.eval(theConnector.fromPos(), theConnector.byPos1(), theConnector.byPos2(), theConnector.toPos(), t - 0.1f);
Vector2 dir = new Vector2(p1.x - p2.x, p1.y - p2.y);
dir.normalize();
double iw = camera.getMetrics().lengthToGu(image.getWidth(), Units.PX) / 2;
double x = p1.x - (dir.x() * iw);
double y = p1.y - (dir.y() * iw);
if (forShadow) {
x += shadowable.theShadowOff.x;
y += shadowable.theShadowOff.y;
}
p = camera.transformGuToPx(x, y, 0);
angle = Math.acos(dir.dotProduct(1, 0));
if (dir.y() > 0)
angle = (Math.PI - angle);
}
Aggregations