Search in sources :

Example 6 with ClosePath

use of javafx.scene.shape.ClosePath in project tilesfx by HanSolo.

the class Helper method smoothPath.

// Smooth given path defined by it's list of path elements
public static final Path smoothPath(final ObservableList<PathElement> ELEMENTS, final boolean FILLED) {
    if (ELEMENTS.isEmpty()) {
        return new Path();
    }
    final Point[] dataPoints = new Point[ELEMENTS.size()];
    for (int i = 0; i < ELEMENTS.size(); i++) {
        final PathElement element = ELEMENTS.get(i);
        if (element instanceof MoveTo) {
            MoveTo move = (MoveTo) element;
            dataPoints[i] = new Point(move.getX(), move.getY());
        } else if (element instanceof LineTo) {
            LineTo line = (LineTo) element;
            dataPoints[i] = new Point(line.getX(), line.getY());
        }
    }
    double zeroY = ((MoveTo) ELEMENTS.get(0)).getY();
    List<PathElement> smoothedElements = new ArrayList<>();
    Pair<Point[], Point[]> result = calcCurveControlPoints(dataPoints);
    Point[] firstControlPoints = result.getKey();
    Point[] secondControlPoints = result.getValue();
    // Start path dependent on filled or not
    if (FILLED) {
        smoothedElements.add(new MoveTo(dataPoints[0].getX(), zeroY));
        smoothedElements.add(new LineTo(dataPoints[0].getX(), dataPoints[0].getY()));
    } else {
        smoothedElements.add(new MoveTo(dataPoints[0].getX(), dataPoints[0].getY()));
    }
    // Add curves
    for (int i = 2; i < dataPoints.length; i++) {
        final int ci = i - 1;
        smoothedElements.add(new CubicCurveTo(firstControlPoints[ci].getX(), firstControlPoints[ci].getY(), secondControlPoints[ci].getX(), secondControlPoints[ci].getY(), dataPoints[i].getX(), dataPoints[i].getY()));
    }
    // Close the path if filled
    if (FILLED) {
        smoothedElements.add(new LineTo(dataPoints[dataPoints.length - 1].getX(), zeroY));
        smoothedElements.add(new ClosePath());
    }
    return new Path(smoothedElements);
}
Also used : Path(javafx.scene.shape.Path) ClosePath(javafx.scene.shape.ClosePath) LineTo(javafx.scene.shape.LineTo) ArrayList(java.util.ArrayList) CubicCurveTo(javafx.scene.shape.CubicCurveTo) ClosePath(javafx.scene.shape.ClosePath) PathElement(javafx.scene.shape.PathElement) MoveTo(javafx.scene.shape.MoveTo)

Example 7 with ClosePath

use of javafx.scene.shape.ClosePath in project latexdraw by arnobl.

the class TestViewShape method duplicatePath.

protected static List<PathElement> duplicatePath(final List<PathElement> path) {
    return path.stream().map(elt -> {
        PathElement dupelt;
        if (elt instanceof MoveTo) {
            final MoveTo moveTo = (MoveTo) elt;
            dupelt = ViewFactory.INSTANCE.createMoveTo(moveTo.getX(), moveTo.getY());
        } else if (elt instanceof LineTo) {
            final LineTo lineTo = (LineTo) elt;
            dupelt = ViewFactory.INSTANCE.createLineTo(lineTo.getX(), lineTo.getY());
        } else if (elt instanceof ClosePath) {
            dupelt = ViewFactory.INSTANCE.createClosePath();
        } else if (elt instanceof CubicCurveTo) {
            final CubicCurveTo cct = (CubicCurveTo) elt;
            dupelt = ViewFactory.INSTANCE.createCubicCurveTo(cct.getControlX1(), cct.getControlY1(), cct.getControlX2(), cct.getControlY2(), cct.getX(), cct.getY());
        } else {
            throw new IllegalArgumentException();
        }
        dupelt.setAbsolute(elt.isAbsolute());
        return dupelt;
    }).collect(Collectors.toList());
}
Also used : ClosePath(javafx.scene.shape.ClosePath) CubicCurveTo(javafx.scene.shape.CubicCurveTo) LineTo(javafx.scene.shape.LineTo) PathElement(javafx.scene.shape.PathElement) Assert.assertTrue(org.junit.Assert.assertTrue) Collectors(java.util.stream.Collectors) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) ISingleShape(net.sf.latexdraw.models.interfaces.shape.ISingleShape) CommandsRegistry(org.malai.command.CommandsRegistry) List(java.util.List) HelperTest(net.sf.latexdraw.HelperTest) After(org.junit.After) MoveTo(javafx.scene.shape.MoveTo) BadaboomCollector(net.sf.latexdraw.badaboom.BadaboomCollector) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) UndoCollector(org.malai.undo.UndoCollector) ClosePath(javafx.scene.shape.ClosePath) PathElement(javafx.scene.shape.PathElement) MoveTo(javafx.scene.shape.MoveTo) LineTo(javafx.scene.shape.LineTo) CubicCurveTo(javafx.scene.shape.CubicCurveTo)

Example 8 with ClosePath

use of javafx.scene.shape.ClosePath in project FXyzLib by Birdasaur.

the class Text3DHelper method generatePath.

private Path generatePath() {
    Path path = new Path(new MoveTo(list.get(0).x, list.get(0).y));
    list.stream().skip(1).forEach(p -> path.getElements().add(new LineTo(p.x, p.y)));
    path.getElements().add(new ClosePath());
    path.setStroke(Color.GREEN);
    // Path must be filled to allow Shape.intersect
    path.setFill(Color.RED);
    return path;
}
Also used : Path(javafx.scene.shape.Path) ClosePath(javafx.scene.shape.ClosePath) ClosePath(javafx.scene.shape.ClosePath) MoveTo(javafx.scene.shape.MoveTo) LineTo(javafx.scene.shape.LineTo)

Example 9 with ClosePath

use of javafx.scene.shape.ClosePath in project Board-Instrumentation-Framework by intel.

the class SimpleGaugeSkin method resize.

private void resize() {
    size = getSkinnable().getWidth() < getSkinnable().getHeight() ? getSkinnable().getWidth() : getSkinnable().getHeight();
    if (size > 0) {
        pane.setMaxSize(size, size);
        pane.relocate((getSkinnable().getWidth() - size) * 0.5, (getSkinnable().getHeight() - size) * 0.5);
        sectionsCanvas.setWidth(size);
        sectionsCanvas.setHeight(size);
        drawSections();
        sectionsCanvas.setCache(true);
        sectionsCanvas.setCacheHint(CacheHint.QUALITY);
        measuredRangeCanvas.setWidth(size);
        measuredRangeCanvas.setHeight(size);
        drawMeasuredRange();
        double currentValue = (needleRotate.getAngle() + getSkinnable().getStartAngle() - 180) / angleStep + getSkinnable().getMinValue();
        value.setText(String.format(Locale.US, "%." + getSkinnable().getDecimals() + "f", currentValue) + getSkinnable().getUnit());
        value.setVisible(getSkinnable().isValueVisible());
        title.setText(getSkinnable().getTitle());
        title.setVisible(getSkinnable().isTitleVisible());
        needle.getElements().clear();
        needle.getElements().add(new MoveTo(0.275 * size, 0.5 * size));
        needle.getElements().add(new CubicCurveTo(0.275 * size, 0.62426575 * size, 0.37573425 * size, 0.725 * size, 0.5 * size, 0.725 * size));
        needle.getElements().add(new CubicCurveTo(0.62426575 * size, 0.725 * size, 0.725 * size, 0.62426575 * size, 0.725 * size, 0.5 * size));
        needle.getElements().add(new CubicCurveTo(0.725 * size, 0.3891265 * size, 0.6448105 * size, 0.296985 * size, 0.5392625 * size, 0.2784125 * size));
        needle.getElements().add(new LineTo(0.5 * size, 0.0225 * size));
        needle.getElements().add(new LineTo(0.4607375 * size, 0.2784125 * size));
        needle.getElements().add(new CubicCurveTo(0.3551895 * size, 0.296985 * size, 0.275 * size, 0.3891265 * size, 0.275 * size, 0.5 * size));
        needle.getElements().add(new ClosePath());
        needle.setStrokeWidth(size * 0.025);
        needle.relocate(needle.getLayoutBounds().getMinX(), needle.getLayoutBounds().getMinY());
        needleRotate.setPivotX(size * 0.5);
        needleRotate.setPivotY(size * 0.5);
        resizeText();
    }
}
Also used : ClosePath(javafx.scene.shape.ClosePath) MoveTo(javafx.scene.shape.MoveTo) LineTo(javafx.scene.shape.LineTo) CubicCurveTo(javafx.scene.shape.CubicCurveTo)

Example 10 with ClosePath

use of javafx.scene.shape.ClosePath in project FXyzLib by Birdasaur.

the class Text3DHelper method getPoints.

private void getPoints(PathElement elem) {
    if (elem instanceof MoveTo) {
        list = new ArrayList<>();
        p0 = new Point3D((float) ((MoveTo) elem).getX(), (float) ((MoveTo) elem).getY(), 0f);
        list.add(p0);
    } else if (elem instanceof LineTo) {
        list.add(new Point3D((float) ((LineTo) elem).getX(), (float) ((LineTo) elem).getY(), 0f));
    } else if (elem instanceof CubicCurveTo) {
        Point3D ini = (list.size() > 0 ? list.get(list.size() - 1) : p0);
        IntStream.rangeClosed(1, POINTS_CURVE).forEach(i -> list.add(evalCubicBezier((CubicCurveTo) elem, ini, ((double) i) / POINTS_CURVE)));
    } else if (elem instanceof QuadCurveTo) {
        Point3D ini = (list.size() > 0 ? list.get(list.size() - 1) : p0);
        IntStream.rangeClosed(1, POINTS_CURVE).forEach(i -> list.add(evalQuadBezier((QuadCurveTo) elem, ini, ((double) i) / POINTS_CURVE)));
    } else if (elem instanceof ClosePath) {
        list.add(p0);
        // stored in a LineSegment: a continuous line that can change direction
        if (Math.abs(getArea()) > 0.001) {
            LineSegment line = new LineSegment(text);
            line.setHole(isHole());
            line.setPoints(list);
            line.setPath(generatePath());
            line.setOrigen(p0);
            polis.add(line);
        }
    }
}
Also used : IntStream(java.util.stream.IntStream) Path(javafx.scene.shape.Path) QuadCurveTo(javafx.scene.shape.QuadCurveTo) Color(javafx.scene.paint.Color) ClosePath(javafx.scene.shape.ClosePath) CubicCurveTo(javafx.scene.shape.CubicCurveTo) LineTo(javafx.scene.shape.LineTo) Font(javafx.scene.text.Font) PathElement(javafx.scene.shape.PathElement) Rectangle(javafx.scene.shape.Rectangle) DoubleProperty(javafx.beans.property.DoubleProperty) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Text(javafx.scene.text.Text) List(java.util.List) SimpleDoubleProperty(javafx.beans.property.SimpleDoubleProperty) MoveTo(javafx.scene.shape.MoveTo) Point2D(javafx.geometry.Point2D) Shape(javafx.scene.shape.Shape) Point3D(org.fxyz.geometry.Point3D) ClosePath(javafx.scene.shape.ClosePath) MoveTo(javafx.scene.shape.MoveTo) LineTo(javafx.scene.shape.LineTo) QuadCurveTo(javafx.scene.shape.QuadCurveTo) Point3D(org.fxyz.geometry.Point3D) CubicCurveTo(javafx.scene.shape.CubicCurveTo)

Aggregations

ClosePath (javafx.scene.shape.ClosePath)15 MoveTo (javafx.scene.shape.MoveTo)15 LineTo (javafx.scene.shape.LineTo)11 CubicCurveTo (javafx.scene.shape.CubicCurveTo)9 Path (javafx.scene.shape.Path)6 PathElement (javafx.scene.shape.PathElement)4 Point (eu.hansolo.tilesfx.tools.Point)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 ArcTo (javafx.scene.shape.ArcTo)2 QuadCurveTo (javafx.scene.shape.QuadCurveTo)2 Text (javafx.scene.text.Text)2 IntStream (java.util.stream.IntStream)1 DoubleProperty (javafx.beans.property.DoubleProperty)1 SimpleDoubleProperty (javafx.beans.property.SimpleDoubleProperty)1 Point2D (javafx.geometry.Point2D)1 InnerShadow (javafx.scene.effect.InnerShadow)1 Pane (javafx.scene.layout.Pane)1 Color (javafx.scene.paint.Color)1