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);
}
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());
}
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;
}
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();
}
}
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);
}
}
}
Aggregations