Search in sources :

Example 81 with Point

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);
}
Also used : Path(javafx.scene.shape.Path) MoveTo(javafx.scene.shape.MoveTo) LineTo(javafx.scene.shape.LineTo) Point(net.sf.latexdraw.model.api.shape.Point) CubicCurveTo(javafx.scene.shape.CubicCurveTo)

Example 82 with Point

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);
}
Also used : Line(net.sf.latexdraw.model.api.shape.Line) Point(net.sf.latexdraw.model.api.shape.Point)

Example 83 with Point

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);
}
Also used : Point(net.sf.latexdraw.model.api.shape.Point) Test(org.junit.Test)

Example 84 with Point

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);
}
Also used : Line(net.sf.latexdraw.model.api.shape.Line) Point(net.sf.latexdraw.model.api.shape.Point) Test(org.junit.Test)

Example 85 with Point

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);
}
Also used : Picture(net.sf.latexdraw.model.api.shape.Picture) Color(javafx.scene.paint.Color) Point(net.sf.latexdraw.model.api.shape.Point) Theory(org.junit.experimental.theories.Theory)

Aggregations

Point (net.sf.latexdraw.model.api.shape.Point)139 Test (org.junit.Test)52 HelperTest (net.sf.latexdraw.HelperTest)27 Theory (org.junit.experimental.theories.Theory)23 NotNull (org.jetbrains.annotations.NotNull)19 Line (net.sf.latexdraw.model.api.shape.Line)10 Shape (net.sf.latexdraw.model.api.shape.Shape)9 SVGElement (net.sf.latexdraw.parser.svg.SVGElement)9 SVGGElement (net.sf.latexdraw.parser.svg.SVGGElement)9 Test (org.junit.jupiter.api.Test)8 ArrayList (java.util.ArrayList)7 Polyline (net.sf.latexdraw.model.api.shape.Polyline)5 Color (javafx.scene.paint.Color)4 MathUtils (net.sf.latexdraw.model.MathUtils)4 ShapeFactory (net.sf.latexdraw.model.ShapeFactory)4 BezierCurve (net.sf.latexdraw.model.api.shape.BezierCurve)4 Canvas (net.sf.latexdraw.view.jfx.Canvas)4 Point2D (java.awt.geom.Point2D)3 List (java.util.List)3 ShapeData (net.sf.latexdraw.data.ShapeData)3