Search in sources :

Example 21 with Vector2

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

the class DiamondOnEdge method makeOnLine.

private void makeOnLine(boolean forShadow, DefaultCamera2D camera) {
    double off = ShapeUtil.evalTargetRadius2D(theEdge, camera);
    Vector2 theDirection = new Vector2(theConnector.toPos().x - theConnector.fromPos().x, theConnector.toPos().y - theConnector.fromPos().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 / 2);
    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() * 2, y - theDirection.y() * 2);
    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)

Example 22 with Vector2

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

the class AngleShape method makeMulti.

private void makeMulti(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 maindir = new Vector2(c2x - c1x, c2y - c1y);
    Vector2 perp = new Vector2(maindir.y(), -maindir.x());
    // 1/2 perp vector to the from point.
    perp.normalize();
    // 1/2 perp vector to the first control point.
    Vector2 perp1 = new Vector2(perp.x(), perp.y());
    // 1/2 perp vector to the second control point.
    Vector2 perp2 = new Vector2(perp.x(), perp.y());
    perp.scalarMult((theSize + swx) * 0.5f);
    if (isDirected) {
        perp1.scalarMult((theSize + swx) * 0.4f);
        perp2.scalarMult((theSize + swx) * 0.2f);
    } else {
        perp1.scalarMult((theSize + swx) * 0.5f);
        perp2.scalarMult((theSize + swx) * 0.5f);
    }
    // ctrl1           ctrl2
    // x---t-------t---x
    // /                 \
    // /                   \
    // X                     X
    // from                  to
    theShape = new Path2D(10, true);
    theShape.moveTo(fromx + perp.x(), fromy + perp.y());
    if (isDirected) {
        theShape.curveTo(c1x + perp1.x(), c1y + perp1.y(), c2x + perp2.x(), c2y + perp2.y(), tox, toy);
        theShape.curveTo(c2x - perp2.x(), c2y - perp2.y(), c1x - perp1.x(), c1y - perp1.y(), fromx - perp.x(), fromy - perp.y());
    } else {
        theShape.curveTo(c1x + perp.x(), c1y + perp.y(), c2x + perp.x(), c2y + perp.y(), tox + perp.x(), toy + perp.y());
        theShape.lineTo(tox - perp.x(), toy - perp.y());
        theShape.curveTo(c2x - perp.x(), c2y - perp.y(), c1x - perp.x(), c1y - perp.y(), fromx - perp.x(), fromy - perp.y());
    }
    theShape.closePath();
}
Also used : Vector2(org.graphstream.ui.geom.Vector2) Path2D(org.graphstream.ui.javafx.renderer.shape.javafx.baseShapes.Form.Path2D)

Example 23 with Vector2

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

Example 24 with Vector2

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

the class SpriteArrowShape method make.

@Override
public void make(Backend backend, DefaultCamera2D camera) {
    double x = area.theCenter.x;
    double y = area.theCenter.y;
    Vector2 dir = new Vector2(orientable.target.x - x, orientable.target.y - y);
    dir.normalize();
    Vector2 per = new Vector2(dir.y(), -dir.x());
    dir.scalarMult(area.theSize.x);
    per.scalarMult(area.theSize.y / 2);
    theShape = new Path2D(5, true);
    theShape().moveTo(x + per.x(), y + per.y());
    theShape().lineTo(x + dir.x(), y + dir.y());
    theShape().lineTo(x - per.x(), y - per.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