use of net.sf.latexdraw.model.api.shape.Point in project latexdraw by arnobl.
the class ViewArrowableTraitPath method clipPath.
@Override
protected void clipPath(final Path path) {
final Path clip = pathProducer.clonePath(path);
clip.setFill(path.getFill());
clip.setStrokeWidth(path.getStrokeWidth());
if (!clip.getElements().isEmpty()) {
// Defensive programming
final Optional<Point> pt1 = getArrowReducedPoint(arrows.get(0).arrow);
final Optional<Point> pt2 = getArrowReducedPoint(arrows.get(arrows.size() - 1).arrow);
if (pt1.isPresent() && clip.getElements().get(0) instanceof MoveTo) {
// Defensive programming
// Changing the first point to the one at the beginning of the arrow.
final MoveTo moveTo = (MoveTo) clip.getElements().get(0);
moveTo.setX(pt1.get().getX());
moveTo.setY(pt1.get().getY());
}
pt2.ifPresent(pt -> {
if (clip.getElements().get(clip.getElements().size() - 1) instanceof LineTo) {
final LineTo lineTo = (LineTo) clip.getElements().get(clip.getElements().size() - 1);
lineTo.setX(pt.getX());
lineTo.setY(pt.getY());
} else if (clip.getElements().get(clip.getElements().size() - 1) instanceof CubicCurveTo) {
final CubicCurveTo ccTo = (CubicCurveTo) clip.getElements().get(clip.getElements().size() - 1);
ccTo.setX(pt.getX());
ccTo.setY(pt.getY());
}
});
}
clip.setStrokeWidth(path.getStrokeWidth());
clip.setStrokeLineCap(path.getStrokeLineCap());
path.setClip(clip);
}
use of net.sf.latexdraw.model.api.shape.Point in project latexdraw by arnobl.
the class ViewArrowableTrait method getArrowReducedPoint.
protected static Optional<Point> getArrowReducedPoint(final Arrow arrow) {
final Line l = arrow.getArrowLine();
if (l == null) {
return Optional.empty();
}
final Point[] points = l.findPoints(l.getX1(), l.getY1(), arrow.getArrowShapeLength());
if (points.length == 0) {
return Optional.empty();
}
return Arrays.stream(points).reduce((p1, p2) -> p1.distance(l.getPoint2()) < p2.distance(l.getPoint2()) ? p1 : p2);
}
use of net.sf.latexdraw.model.api.shape.Point in project latexdraw by arnobl.
the class TestBorder method testScaleNRectangle.
@Test
public void testScaleNRectangle() {
Cmds.of(addRec, selectAllShapes).execute();
final double width = addedRec.getWidth();
final double height = addedRec.getHeight();
final Point tr = addedRec.getTopRightPoint();
final CmdFXVoid trCmd = () -> tr.translate(0d, -20d);
Cmds.of(trCmd, () -> drag(border.scaleHandlers.get(1)).dropBy(30d, -20d)).execute();
assertEquals(width, addedRec.getWidth(), 0.001);
assertEquals(height + 20d, addedRec.getHeight(), 3d);
assertEquals(tr.getX(), addedRec.getTopRightPoint().getX(), 3d);
assertEquals(tr.getY(), addedRec.getTopRightPoint().getY(), 3d);
}
use of net.sf.latexdraw.model.api.shape.Point in project latexdraw by arnobl.
the class TestBorder method testArcStartHandlerRotated.
@Test
public void testArcStartHandlerRotated() {
Cmds.of(addArc, selectAllShapes, () -> addedArc.setRotationAngle(0.5)).execute();
final Point gc = addedArc.getGravityCentre();
final Point point = addedArc.getStartPoint().rotatePoint(addedArc.getGravityCentre(), addedArc.getRotationAngle());
final Point newpoint = point.rotatePoint(gc, -Math.PI / 4d).rotatePoint(addedArc.getGravityCentre(), addedArc.getRotationAngle());
Cmds.of(() -> drag(border.arcHandlerStart).dropBy(newpoint.getX() - point.getX(), newpoint.getY() - point.getY())).execute();
final Line l1 = ShapeFactory.INST.createLine(gc, addedArc.getStartPoint().rotatePoint(addedArc.getGravityCentre(), addedArc.getRotationAngle()));
final Line l2 = ShapeFactory.INST.createLine(gc, newpoint);
assertEquals(l1.getA(), l2.getA(), 0.02);
}
use of net.sf.latexdraw.model.api.shape.Point in project latexdraw by arnobl.
the class TestCanvasTranslation method testShapeTranslationOK.
@Theory
public void testShapeTranslationOK(@ShapeData final Shape sh) {
if (sh instanceof Picture) {
((Picture) sh).setPathSource(getClass().getResource("/Arc.png").getFile());
}
Cmds.of(CmdFXVoid.of(() -> {
canvas.getSelectionBorder().setFill(new Color(1d, 1d, 1d, 0.1d));
sh.setFilled(true);
sh.translate(-canvas.getOrigin().getX(), -canvas.getOrigin().getY());
canvas.getDrawing().addShape(sh);
canvas.getDrawing().setSelection(List.of(sh));
}), requestFocusCanvas).execute();
final Point tl = sh.getTopLeftPoint();
Cmds.of(() -> drag(canvas.getSelectionBorder()).dropBy(101, 163)).execute();
assertEquals(tl.getX() + 101d, sh.getTopLeftPoint().getX(), 5d);
assertEquals(tl.getY() + 163d, sh.getTopLeftPoint().getY(), 5d);
}
Aggregations