Search in sources :

Example 1 with Vector2

use of org.graphstream.ui.geom.Vector2 in project gs-ui-javafx by graphstream.

the class ConnectorSkeleton method pointOnShapeAndPerpendicular.

/**
 * Compute a point at a given percent on the shape and push it from the shape perpendicular
 * to it at a given distance in GU. The percent must be a number between 0 and 1. The result
 * is stored in target and also returned.
 */
public Point3 pointOnShapeAndPerpendicular(double percent, double perpendicular, Point3 target) {
    double at = percent;
    if (percent > 1)
        at = 1;
    if (at < 0)
        at = 0;
    if (isCurve()) {
        Point3 p0 = points.get(0);
        Point3 p1 = points.get(1);
        Point3 p2 = points.get(2);
        Point3 p3 = points.get(3);
        Vector2 perp = CubicCurve.perpendicular(p0, p1, p2, p3, at);
        perp.normalize();
        perp.scalarMult(perpendicular);
        target.x = CubicCurve.eval(p0.x, p1.x, p2.x, p3.x, at) - perp.data[0];
        target.y = CubicCurve.eval(p0.y, p1.y, p2.y, p3.y, at) - perp.data[1];
        target.z = 0;
    } else if (isPoly()) {
        Triplet<Integer, Double, Double> triplet = wichSegment(at);
        int i = triplet.i;
        double sum = triplet.sum;
        double ps = triplet.ps;
        Vector3 dir = new Vector3(points.get(i + 1).x - points.get(i).x, points.get(i + 1).y - points.get(i).y, 0);
        Vector3 perp = new Vector3(dir.data[1], -dir.data[0], 0);
        perp.normalize();
        perp.scalarMult(perpendicular);
        dir.scalarMult(ps);
        target.set(points.get(i).x + dir.data[0] + perp.data[0], points.get(i).y + dir.data[1] + perp.data[1], points.get(i).z);
    } else {
        Vector3 dir = new Vector3(to().x - from().x, to().y - from().y, 0);
        Vector3 perp = new Vector3(dir.data[1], -dir.data[0], 0);
        perp.normalize();
        perp.scalarMult(perpendicular);
        dir.scalarMult(at);
        target.set(from().x + dir.data[0] + perp.data[0], from().y + dir.data[1] + perp.data[1], from().z);
    }
    return target;
}
Also used : Point3(org.graphstream.ui.geom.Point3) Vector2(org.graphstream.ui.geom.Vector2) Vector3(org.graphstream.ui.geom.Vector3)

Example 2 with Vector2

use of org.graphstream.ui.geom.Vector2 in project gs-ui-javafx by graphstream.

the class ArrowOnEdge method makeOnLine.

private void makeOnLine(boolean forShadow, DefaultCamera2D camera) {
    ConnectorSkeleton skel = theConnector.skel;
    double off = 0;
    Vector2 theDirection;
    if (skel.isPoly()) {
        off = ShapeUtil.evalTargetRadius2D(skel.apply(skel.size() - 2), skel.to(), theEdge.to, camera);
        theDirection = new Vector2(skel.to().x - skel.apply(skel.size() - 2).x, skel.to().y - skel.apply(skel.size() - 2).y);
    } else {
        off = ShapeUtil.evalTargetRadius2D(skel.from(), skel.to(), theEdge.to, camera);
        theDirection = new Vector2(skel.to().x - skel.from().x, skel.to().y - skel.from().y);
    }
    theDirection.normalize();
    double x = theCenter.x - (theDirection.x() * off);
    double y = theCenter.y - (theDirection.y() * off);
    Vector2 perp = new Vector2(theDirection.y(), -theDirection.x());
    perp.normalize();
    theDirection.scalarMult(theSize.x);
    perp.scalarMult(theSize.y);
    if (forShadow) {
        x += shadowable.theShadowOff.x;
        y += shadowable.theShadowOff.y;
    }
    // Create a polygon.
    theShape = new Path2D(5, true);
    theShape.moveTo(x, y);
    theShape.lineTo(x - theDirection.x() + perp.x(), y - theDirection.y() + perp.y());
    theShape.lineTo(x - theDirection.x() - perp.x(), y - theDirection.y() - perp.y());
    theShape.closePath();
}
Also used : Vector2(org.graphstream.ui.geom.Vector2) Path2D(org.graphstream.ui.javafx.renderer.shape.javafx.baseShapes.Form.Path2D) ConnectorSkeleton(org.graphstream.ui.javafx.renderer.ConnectorSkeleton)

Example 3 with Vector2

use of org.graphstream.ui.geom.Vector2 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 4 with Vector2

use of org.graphstream.ui.geom.Vector2 in project gs-ui-javafx by graphstream.

the class Tuple method renderAlong.

@Override
public void renderAlong(Backend backend, DefaultCamera2D camera, IconAndText iconAndText, double x0, double y0, double x1, double y1) {
    Vector2 dir = new Vector2(x1 - x0, y1 - y0);
    dir.scalarMult(0.5f);
    renderGu2Px(backend, camera, iconAndText, x0 + dir.x(), y0 + dir.y(), 0, positionTextAndIconPx);
}
Also used : Vector2(org.graphstream.ui.geom.Vector2)

Example 5 with Vector2

use of org.graphstream.ui.geom.Vector2 in project gs-ui-javafx by graphstream.

the class AngleShape method makeLoop.

private void makeLoop(DefaultCamera2D camera, double sox, double soy, double swx, double swy) {
    double fromx = skel.apply(0).x + sox;
    double fromy = skel.apply(0).y + soy;
    double tox = skel.apply(3).x + sox;
    double toy = skel.apply(3).y + soy;
    double c1x = skel.apply(1).x + sox;
    double c1y = skel.apply(1).y + soy;
    double c2x = skel.apply(2).x + sox;
    double c2y = skel.apply(2).y + soy;
    Vector2 dirFrom = new Vector2(c1x - fromx, c1y - fromy);
    Vector2 dirTo = new Vector2(tox - c2x, toy - c2y);
    Vector2 mainDir = new Vector2(c2x - c1x, c2y - c1y);
    Vector2 perpFrom = new Vector2(dirFrom.y(), -dirFrom.x());
    perpFrom.normalize();
    Vector2 mid1 = new Vector2(dirFrom);
    mid1.sub(mainDir);
    mid1.normalize();
    Vector2 mid2 = new Vector2(mainDir);
    mid2.sub(dirTo);
    mid2.normalize();
    perpFrom.scalarMult(theSize * 0.5f);
    if (isDirected) {
        mid1.scalarMult(theSize * 0.8f);
        mid2.scalarMult(theSize * 0.6f);
    } else {
        mid1.scalarMult(theSize * 0.99f);
        mid2.scalarMult(theSize * 0.99f);
    }
    theShape = new Path2D(20, true);
    theShape.moveTo(fromx + perpFrom.x(), fromy + perpFrom.y());
    if (isDirected) {
        theShape.curveTo(c1x + mid1.x(), c1y + mid1.y(), c2x + mid2.x(), c2y + mid2.y(), tox, toy);
        theShape.curveTo(c2x - mid2.x(), c2y - mid2.y(), c1x - mid1.x(), c1y - mid1.y(), fromx - perpFrom.x(), fromy - perpFrom.y());
    } else {
        Vector2 perpTo = new Vector2(dirTo.y(), -dirTo.x());
        perpTo.normalize();
        perpTo.scalarMult(theSize * 0.5f);
        theShape.curveTo(c1x + mid1.x(), c1y + mid1.y(), c2x + mid2.x(), c2y + mid2.y(), tox + perpTo.x(), toy + perpTo.y());
        theShape.lineTo(tox - perpTo.x(), toy - perpTo.y());
        theShape.curveTo(c2x - mid2.x(), c2y - mid2.y(), c1x - mid1.x(), c1y - mid1.y(), fromx - perpFrom.x(), fromy - perpFrom.y());
    }
    theShape.closePath();
}
Also used : Vector2(org.graphstream.ui.geom.Vector2) Path2D(org.graphstream.ui.javafx.renderer.shape.javafx.baseShapes.Form.Path2D)

Aggregations

Vector2 (org.graphstream.ui.geom.Vector2)24 Path2D (org.graphstream.ui.javafx.renderer.shape.javafx.baseShapes.Form.Path2D)15 Point3 (org.graphstream.ui.geom.Point3)6 Point2 (org.graphstream.ui.geom.Point2)5 Style (org.graphstream.ui.graphicGraph.stylesheet.Style)4 Point2D (javafx.geometry.Point2D)1 Vector3 (org.graphstream.ui.geom.Vector3)1 GraphicEdge (org.graphstream.ui.graphicGraph.GraphicEdge)1 GraphicNode (org.graphstream.ui.graphicGraph.GraphicNode)1 ConnectorSkeleton (org.graphstream.ui.javafx.renderer.ConnectorSkeleton)1 Triplet (org.graphstream.ui.javafx.renderer.Skeleton.Triplet)1