Search in sources :

Example 6 with Vector2

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

the class AngleShape method makeOnLine.

private void makeOnLine(DefaultCamera2D camera, double sox, double soy, double swx, double swy) {
    double fromx = skel.from().x + sox;
    double fromy = skel.from().y + soy;
    double tox = skel.to().x + sox;
    double toy = skel.to().y + soy;
    Vector2 dir = new Vector2(tox - fromx, toy - fromy);
    Vector2 perp = new Vector2(dir.y(), -dir.x());
    // 1/2 perp vector to the from point.
    perp.normalize();
    perp.scalarMult((theSize + swx) / 2f);
    theShape = new Path2D(10, true);
    theShape.moveTo(fromx + perp.x(), fromy + perp.y());
    if (isDirected) {
        theShape.lineTo(tox, toy);
    } else {
        theShape.lineTo(tox + perp.x(), toy + perp.y());
        theShape.lineTo(tox - perp.x(), toy - perp.y());
    }
    theShape.lineTo(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 7 with Vector2

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

the class CubicCurveShape method makeSingle.

private void makeSingle(DefaultCamera2D camera, double sox, double soy, double swx, double swy) {
    double fromx = skel.from().x + sox;
    double fromy = skel.from().y + soy;
    double tox = skel.to().x + sox;
    double toy = skel.to().y + soy;
    Vector2 mainDir = new Vector2(skel.from(), skel.to());
    double length = mainDir.length();
    double angle = mainDir.y() / length;
    double c1x = 0.0;
    double c1y = 0.0;
    double c2x = 0.0;
    double c2y = 0.0;
    if (angle > 0.707107f || angle < -0.707107f) {
        // North or south.
        c1x = fromx + mainDir.x() / 2;
        c2x = c1x;
        c1y = fromy;
        c2y = toy;
    } else {
        // East or west.
        c1x = fromx;
        c2x = tox;
        c1y = fromy + mainDir.y() / 2;
        c2y = c1y;
    }
    theShape = new Path2D(5, false);
    theShape.moveTo(fromx, fromy);
    theShape.curveTo(c1x, c1y, c2x, c2y, tox, toy);
    if (sox == 0 && soy == 0) {
        skel.setCurve(fromx, fromy, 0, c1x, c1y, 0, c2x, c2y, 0, tox, toy, 0);
    }
}
Also used : Vector2(org.graphstream.ui.geom.Vector2) Path2D(org.graphstream.ui.javafx.renderer.shape.javafx.baseShapes.Form.Path2D)

Example 8 with Vector2

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

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

the class CircleOnEdge method makeOnLine.

private void makeOnLine(boolean forShadow, DefaultCamera2D camera) {
    double off = ShapeUtil.evalTargetRadius2D(theEdge, camera) + ((theSize.x + theSize.y) / 4);
    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);
    // val perp = new Vector2( theDirection(1), -theDirection(0) )
    // perp.normalize
    theDirection.scalarMult(theSize.x);
    if (forShadow) {
        x += shadowable.theShadowOff.x;
        y += shadowable.theShadowOff.y;
    }
    // Set the shape.
    theShape.setFrame(x - (theSize.x / 2), y - (theSize.y / 2), theSize.x, theSize.y);
}
Also used : Vector2(org.graphstream.ui.geom.Vector2)

Example 10 with Vector2

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

the class ImageOnEdge 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 iw = camera.getMetrics().lengthToGu(image.getWidth(), Units.PX) / 2;
    double x = theCenter.x - (theDirection.x() * (off + iw));
    double y = theCenter.y - (theDirection.y() * (off + iw));
    if (forShadow) {
        x += shadowable.theShadowOff.x;
        y += shadowable.theShadowOff.y;
    }
    // Pass to pixels, the image will be drawn in pixels.
    p = camera.transformGuToPx(x, y, 0);
    angle = Math.acos(theDirection.dotProduct(1, 0));
    if (// The angle is always computed for acute angles
    theDirection.y() > 0)
        angle = (Math.PI - angle);
}
Also used : Vector2(org.graphstream.ui.geom.Vector2)

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