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