Search in sources :

Example 1 with Triplet

use of org.graphstream.ui.javafx.renderer.Skeleton.Triplet 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)

Aggregations

Point3 (org.graphstream.ui.geom.Point3)1 Vector2 (org.graphstream.ui.geom.Vector2)1 Triplet (org.graphstream.ui.javafx.renderer.Skeleton.Triplet)1 Path2D (org.graphstream.ui.javafx.renderer.shape.javafx.baseShapes.Form.Path2D)1