Search in sources :

Example 1 with Point2

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();
}
Also used : Point3(org.graphstream.ui.geom.Point3) Point2(org.graphstream.ui.geom.Point2) Vector2(org.graphstream.ui.geom.Vector2) Path2D(org.graphstream.ui.javafx.renderer.shape.javafx.baseShapes.Form.Path2D) Style(org.graphstream.ui.graphicGraph.stylesheet.Style)

Example 2 with Point2

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);
}
Also used : Point3(org.graphstream.ui.geom.Point3) Point2(org.graphstream.ui.geom.Point2) Vector2(org.graphstream.ui.geom.Vector2) Style(org.graphstream.ui.graphicGraph.stylesheet.Style)

Example 3 with Point2

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()));
}
Also used : Point2(org.graphstream.ui.geom.Point2)

Example 4 with Point2

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;
}
Also used : Point2(org.graphstream.ui.geom.Point2)

Example 5 with Point2

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);
}
Also used : Point3(org.graphstream.ui.geom.Point3) Point2(org.graphstream.ui.geom.Point2) Vector2(org.graphstream.ui.geom.Vector2) Style(org.graphstream.ui.graphicGraph.stylesheet.Style)

Aggregations

Point2 (org.graphstream.ui.geom.Point2)7 Vector2 (org.graphstream.ui.geom.Vector2)5 Style (org.graphstream.ui.graphicGraph.stylesheet.Style)4 Point3 (org.graphstream.ui.geom.Point3)3 Path2D (org.graphstream.ui.javafx.renderer.shape.javafx.baseShapes.Form.Path2D)2 Point2D (javafx.geometry.Point2D)1 GraphicEdge (org.graphstream.ui.graphicGraph.GraphicEdge)1 GraphicNode (org.graphstream.ui.graphicGraph.GraphicNode)1