Search in sources :

Example 11 with Vector2

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

the class OrientableRectangularAreaShape method make.

private void make(Backend bck, boolean forShadow, DefaultCamera2D camera) {
    if (oriented) {
        Vector2 theDirection = new Vector2(orientable.target.x - area.theCenter.x, orientable.target.y - area.theCenter.y);
        theDirection.normalize();
        double x = area.theCenter.x;
        double y = area.theCenter.y;
        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);
        w = camera.getMetrics().lengthToPx(area.theSize.x, Units.GU);
        h = camera.getMetrics().lengthToPx(area.theSize.y, Units.GU);
        ((Form) theShape()).setFrame(0, 0, w, h);
    } else {
        if (forShadow)
            super.makeShadow(bck, camera);
        else
            super.make(bck, camera);
    }
}
Also used : Vector2(org.graphstream.ui.geom.Vector2)

Example 12 with Vector2

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

the class SpriteArrowShape method makeShadow.

@Override
public void makeShadow(Backend backend, DefaultCamera2D camera) {
    double x = area.theCenter.x + shadowable.theShadowOff.x;
    double y = area.theCenter.y + shadowable.theShadowOff.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 + shadowable.theShadowWidth.x);
    per.scalarMult((area.theSize.y + shadowable.theShadowWidth.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)

Example 13 with Vector2

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

the class SpriteFlowShape method make.

private void make(GraphicsContext graphics2d, DefaultCamera2D camera, double shx, double shy) {
    // we only need to compute the perpendicular vector once, hence this code.
    if (connectorSkel != null) {
        if (connectorSkel.isCurve()) {
            Point3 P0 = connectorSkel.apply(0);
            if (reverse)
                P0 = connectorSkel.apply(3);
            Point3 P1 = connectorSkel.apply(1);
            if (reverse)
                P1 = connectorSkel.apply(2);
            Point3 P2 = connectorSkel.apply(2);
            if (reverse)
                P2 = connectorSkel.apply(1);
            Point3 P3 = connectorSkel.apply(3);
            if (reverse)
                P3 = connectorSkel.apply(0);
            double inc = 0.01;
            double t = 0.0;
            Vector2 dir = new Vector2(P3.x - P0.x, P3.y - P0.y);
            Vector2 per = new Vector2(dir.y() + shx, -dir.x() + shy);
            per.normalize();
            per.scalarMult(offset);
            theShape = new Path2D((int) (along / inc) + 3, false);
            theShape.moveTo(P0.x + per.x(), P0.y + per.y());
            while (t <= along) {
                theShape.lineTo(CubicCurve.eval(P0.x + per.x(), P1.x + per.x(), P2.x + per.x(), P3.x + per.x(), t), CubicCurve.eval(P0.y + per.y(), P1.y + per.y(), P2.y + per.y(), P3.y + per.y(), t));
                t += inc;
            }
        } else if (connectorSkel.isPoly()) {
            Point3 P0 = connectorSkel.from();
            if (reverse)
                P0 = connectorSkel.to();
            Point3 P1 = connectorSkel.to();
            if (reverse)
                P1 = connectorSkel.from();
            double a = along;
            if (reverse)
                a = 1 - along;
            Triplet<Integer, Double, Double> triplet = connectorSkel.wichSegment(a);
            int i = triplet.i;
            double sum = triplet.sum;
            double ps = triplet.ps;
            Vector2 dir = new Vector2(P1.x - P0.x, P1.y - P0.y);
            Vector2 per = new Vector2(dir.y() + shx, -dir.x() + shy);
            per.normalize();
            per.scalarMult(offset);
            theShape = new Path2D(i + 3, false);
            if (reverse) {
                int n = connectorSkel.size();
                sum = connectorSkel.length() - sum;
                ps = 1 - ps;
                theShape.moveTo(P1.x + per.x(), P1.y + per.y());
                for (int j = n - 2; j < i; j--) {
                    theShape.lineTo(connectorSkel.apply(j).x + per.x(), connectorSkel.apply(j).y + per.y());
                }
                Point3 PX = connectorSkel.pointOnShape(along);
                theShape.lineTo(PX.x + per.x(), PX.y + per.y());
            } else {
                theShape.moveTo(P0.x + per.x(), P0.y + per.y());
                for (int j = 1; j <= i; j++) {
                    theShape.lineTo(connectorSkel.apply(j).x + per.x(), connectorSkel.apply(j).y + per.y());
                }
                Point3 PX = connectorSkel.pointOnShape(along);
                theShape.lineTo(PX.x + per.x(), PX.y + per.y());
            }
        } else {
            Point3 P0 = connectorSkel.from();
            if (reverse)
                P0 = connectorSkel.to();
            Point3 P1 = connectorSkel.to();
            if (reverse)
                P1 = connectorSkel.from();
            Vector2 dir = new Vector2(P1.x - P0.x, P1.y - P0.y);
            Vector2 per = new Vector2(dir.y() + shx, -dir.x() + shy);
            per.normalize();
            per.scalarMult(offset);
            dir.scalarMult(along);
            theShape = new Path2D(5, false);
            theShape.moveTo(P0.x + per.x(), P0.y + per.y());
            theShape.lineTo(P0.x + dir.x() + per.x(), P0.y + dir.y() + per.y());
        }
    }
// if( connectorSkel != null ) {
// var P0  = if( reverse ) connectorSkel.to else connectorSkel.from
// var P3  = if( reverse ) connectorSkel.from else connectorSkel.to
// val dir = Vector2( P3.x-P0.x, P3.y-P0.y )
// val per = Vector2( dir.y + shx, -dir.x + shy )
// 
// per.normalize
// per.scalarMult( offset )
// theShape.reset
// theShape.moveTo( P0.x + per.x, P0.y + per.y  )
// 
// if( connectorSkel.isCurve ) {
// val P1  = if( reverse ) connectorSkel(2) else connectorSkel(1)
// val P2  = if( reverse ) connectorSkel(1) else connectorSkel(2)
// val inc = 0.01f
// var t   = 0f
// 
// while( t <= along ) {
// theShape.lineTo(
// CubicCurve.eval( P0.x + per.x, P1.x + per.x, P2.x + per.x, P3.x + per.x, t ),
// CubicCurve.eval( P0.y + per.y, P1.y + per.y, P2.y + per.y, P3.y + per.y, t )
// )
// 
// t += inc
// }
// } else {
// val dir = Vector2( P3.x-P0.x, P3.y-P0.y )
// dir.scalarMult( along )
// theShape.lineTo( P0.x + dir.x + per.x, P0.y + dir.y + per.y )
// }
// }
}
Also used : Point3(org.graphstream.ui.geom.Point3) Vector2(org.graphstream.ui.geom.Vector2) Triplet(org.graphstream.ui.javafx.renderer.Skeleton.Triplet) Path2D(org.graphstream.ui.javafx.renderer.shape.javafx.baseShapes.Form.Path2D)

Example 14 with Vector2

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

the class DefaultCamera method getSpritePositionEdge.

/**
 * Compute the position of a sprite if attached to an edge.
 *
 * @param sprite
 *            The sprite.
 * @param pos
 *            Where to stored the computed position, if null, the position
 *            is created.
 * @param units
 *            The units the computed position must be given into.
 * @return The same instance as pos, or a new one if pos was null.
 */
protected Point2D getSpritePositionEdge(GraphicSprite sprite, Point2D pos, Units units) {
    GraphicEdge edge = sprite.getEdgeAttachment();
    if (edge.isCurve()) {
        double[] ctrl = edge.getControlPoints();
        Point2 p0 = new Point2(edge.from.getX(), edge.from.getY());
        Point2 p1 = new Point2(ctrl[0], ctrl[1]);
        Point2 p2 = new Point2(ctrl[1], ctrl[2]);
        Point2 p3 = new Point2(edge.to.getX(), edge.to.getY());
        Vector2 perp = CubicCurve.perpendicular(p0, p1, p2, p3, sprite.getX());
        double y = metrics.lengthToGu(sprite.getY(), sprite.getUnits());
        perp.normalize();
        perp.scalarMult(y);
        double X = CubicCurve.eval(p0.x, p1.x, p2.x, p3.x, sprite.getX()) - perp.data[0];
        double Y = CubicCurve.eval(p0.y, p1.y, p2.y, p3.y, sprite.getX()) - perp.data[1];
        pos = new Point2D(X, Y);
    } else {
        double x = ((GraphicNode) edge.getSourceNode()).x;
        double y = ((GraphicNode) edge.getSourceNode()).y;
        double dx = ((GraphicNode) edge.getTargetNode()).x - x;
        double dy = ((GraphicNode) edge.getTargetNode()).y - y;
        // Percent on the edge.
        double d = sprite.getX();
        double o = metrics.lengthToGu(sprite.getY(), sprite.getUnits());
        // Offset from the position given by percent, perpendicular to the
        // edge.
        d = d > 1 ? 1 : d;
        d = d < 0 ? 0 : d;
        x += dx * d;
        y += dy * d;
        d = (double) Math.sqrt(dx * dx + dy * dy);
        dx /= d;
        dy /= d;
        x += -dy * o;
        y += dx * o;
        pos = new Point2D(x, y);
        if (units == Units.PX) {
            pos = Tx.transform(pos.getX(), pos.getY());
        }
    }
    return pos;
}
Also used : Point2(org.graphstream.ui.geom.Point2) Vector2(org.graphstream.ui.geom.Vector2) Point2D(javafx.geometry.Point2D) GraphicEdge(org.graphstream.ui.graphicGraph.GraphicEdge) GraphicNode(org.graphstream.ui.graphicGraph.GraphicNode)

Example 15 with Vector2

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

the class Orientable method setTargetOnLineEdge.

private void setTargetOnLineEdge(DefaultCamera2D camera, GraphicSprite sprite, GraphicEdge ge) {
    Vector2 dir = new Vector2(ge.to.getX() - ge.from.getX(), ge.to.getY() - ge.from.getY());
    dir.scalarMult(sprite.getX());
    target.set(ge.from.getX() + dir.x(), ge.from.getY() + dir.y());
}
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