Search in sources :

Example 16 with Path2D

use of org.graphstream.ui.javafx.renderer.shape.javafx.baseShapes.Form.Path2D in project gs-ui-javafx by graphstream.

the class CrossShape method make.

@Override
public void make(Backend backend, DefaultCamera2D camera) {
    double x = area.theCenter.x;
    double y = area.theCenter.y;
    double h2 = area.theSize.x / 2;
    double w2 = area.theSize.y / 2;
    double w1 = area.theSize.x * 0.2f;
    double h1 = area.theSize.y * 0.2f;
    double w4 = area.theSize.x * 0.3f;
    double h4 = area.theSize.y * 0.3f;
    theShape = new Path2D(20, true);
    theShape().moveTo(x - w2, y + h4);
    theShape().lineTo(x - w4, y + h2);
    theShape().lineTo(x, y + h1);
    theShape().lineTo(x + w4, y + h2);
    theShape().lineTo(x + w2, y + h4);
    theShape().lineTo(x + w1, y);
    theShape().lineTo(x + w2, y - h4);
    theShape().lineTo(x + w4, y - h2);
    theShape().lineTo(x, y - h1);
    theShape().lineTo(x - w4, y - h2);
    theShape().lineTo(x - w2, y - h4);
    theShape().lineTo(x - w1, y);
    theShape().closePath();
}
Also used : Path2D(org.graphstream.ui.javafx.renderer.shape.javafx.baseShapes.Form.Path2D)

Example 17 with Path2D

use of org.graphstream.ui.javafx.renderer.shape.javafx.baseShapes.Form.Path2D in project gs-ui-javafx by graphstream.

the class TriangleShape 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;
    double w2 = (area.theSize.x + shadowable.theShadowWidth.x) / 2;
    double h2 = (area.theSize.y + shadowable.theShadowWidth.y) / 2;
    theShape = new Path2D(5, true);
    theShape().moveTo(x, y + h2);
    theShape().lineTo(x + w2, y - h2);
    theShape().lineTo(x - w2, y - h2);
    theShape.closePath();
}
Also used : Path2D(org.graphstream.ui.javafx.renderer.shape.javafx.baseShapes.Form.Path2D)

Example 18 with Path2D

use of org.graphstream.ui.javafx.renderer.shape.javafx.baseShapes.Form.Path2D in project gs-ui-javafx by graphstream.

the class TriangleShape method make.

@Override
public void make(Backend backend, DefaultCamera2D camera) {
    double x = area.theCenter.x;
    double y = area.theCenter.y;
    double w2 = area.theSize.x / 2;
    double h2 = area.theSize.y / 2;
    theShape = new Path2D(5, true);
    theShape().moveTo(x, y + h2);
    theShape().lineTo(x + w2, y - h2);
    theShape().lineTo(x - w2, y - h2);
    theShape.closePath();
}
Also used : Path2D(org.graphstream.ui.javafx.renderer.shape.javafx.baseShapes.Form.Path2D)

Example 19 with Path2D

use of org.graphstream.ui.javafx.renderer.shape.javafx.baseShapes.Form.Path2D 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 20 with Path2D

use of org.graphstream.ui.javafx.renderer.shape.javafx.baseShapes.Form.Path2D in project gs-ui-javafx by graphstream.

the class BlobShape 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;
    double srcsz = Math.min(theSourceSize.x, theSourceSize.y);
    // double trgsz = min( theTargetSizeX, theTargetSizeY )
    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((srcsz + swx) * 0.3f);
    if (isDirected) {
        mid1.scalarMult((theSize + swx) * 4f);
        mid2.scalarMult((theSize + swx) * 2f);
    } else {
        mid1.scalarMult((theSize + swx) * 4f);
        mid2.scalarMult((theSize + swx) * 4f);
    }
    theShape = new Path2D(10, 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((srcsz + swx) * 0.3f);
        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

Path2D (org.graphstream.ui.javafx.renderer.shape.javafx.baseShapes.Form.Path2D)35 Vector2 (org.graphstream.ui.geom.Vector2)15 Point3 (org.graphstream.ui.geom.Point3)4 Point2 (org.graphstream.ui.geom.Point2)2 Style (org.graphstream.ui.graphicGraph.stylesheet.Style)2 ConnectorSkeleton (org.graphstream.ui.javafx.renderer.ConnectorSkeleton)1 Triplet (org.graphstream.ui.javafx.renderer.Skeleton.Triplet)1