Search in sources :

Example 86 with Point

use of net.sf.latexdraw.model.api.shape.Point in project latexdraw by arnobl.

the class TestCanvasTranslation method testShapeTranslationWithZoom50.

@Test
public void testShapeTranslationWithZoom50() {
    final var sh = ShapeSupplier.createRectangle();
    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));
        canvas.setZoom(Double.NaN, Double.NaN, 0.5);
    }), requestFocusCanvas).execute();
    final Point tl = sh.getTopLeftPoint();
    Cmds.of(() -> drag(canvas.getSelectionBorder()).dropBy(100, 160)).execute();
    assertEquals(tl.getX() + 200d, sh.getTopLeftPoint().getX(), 5d);
    assertEquals(tl.getY() + 320d, sh.getTopLeftPoint().getY(), 5d);
}
Also used : Color(javafx.scene.paint.Color) Point(net.sf.latexdraw.model.api.shape.Point) Test(org.junit.Test)

Example 87 with Point

use of net.sf.latexdraw.model.api.shape.Point in project latexdraw by arnobl.

the class TestCanvasTranslation method testTranslateSeveralShapesUsingOne.

@Test
public void testTranslateSeveralShapesUsingOne() {
    Cmds.of(addRec, addRec2, selectAllShapes, CmdFXVoid.of(() -> canvas.getDrawing().getShapes().forEach(sh -> sh.setFilled(true)))).execute();
    final Point tl1 = canvas.getDrawing().getShapeAt(0).orElseThrow().getTopLeftPoint();
    final Point tl2 = canvas.getDrawing().getShapeAt(1).orElseThrow().getTopLeftPoint();
    Cmds.of(() -> drag(canvas.getViews().getChildren().get(1)), () -> dropBy(100d, 200d)).execute();
    assertEquals(2, canvas.getDrawing().getSelection().size());
    assertEquals(tl1.getX() + 100d, canvas.getDrawing().getShapeAt(0).orElseThrow().getTopLeftPoint().getX(), 1d);
    assertEquals(tl1.getY() + 200d, canvas.getDrawing().getShapeAt(0).orElseThrow().getTopLeftPoint().getY(), 1d);
    assertEquals(tl2.getX() + 100d, canvas.getDrawing().getShapeAt(1).orElseThrow().getTopLeftPoint().getX(), 1d);
    assertEquals(tl2.getY() + 200d, canvas.getDrawing().getShapeAt(1).orElseThrow().getTopLeftPoint().getY(), 1d);
}
Also used : KeyCode(javafx.scene.input.KeyCode) Color(javafx.scene.paint.Color) ShapeSupplier(net.sf.latexdraw.data.ShapeSupplier) Injector(net.sf.latexdraw.util.Injector) ShapeData(net.sf.latexdraw.data.ShapeData) RunWith(org.junit.runner.RunWith) Test(org.junit.Test) Picture(net.sf.latexdraw.model.api.shape.Picture) Mockito.when(org.mockito.Mockito.when) Point(net.sf.latexdraw.model.api.shape.Point) InvocationTargetException(java.lang.reflect.InvocationTargetException) WaitForAsyncUtils(org.testfx.util.WaitForAsyncUtils) Mockito(org.mockito.Mockito) List(java.util.List) Shape(net.sf.latexdraw.model.api.shape.Shape) Stage(javafx.stage.Stage) Theories(org.junit.experimental.theories.Theories) Point2D(javafx.geometry.Point2D) Canvas(net.sf.latexdraw.view.jfx.Canvas) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) Theory(org.junit.experimental.theories.Theory) Point(net.sf.latexdraw.model.api.shape.Point) Test(org.junit.Test)

Example 88 with Point

use of net.sf.latexdraw.model.api.shape.Point in project latexdraw by arnobl.

the class TestCanvasTranslation method testShapeTranslationWithZoom120.

@Test
public void testShapeTranslationWithZoom120() {
    final var sh = ShapeSupplier.createRectangle();
    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));
        canvas.setZoom(Double.NaN, Double.NaN, 1.2);
    }), requestFocusCanvas).execute();
    final Point tl = sh.getTopLeftPoint();
    Cmds.of(() -> drag(canvas.getSelectionBorder()).dropBy(100, 160)).execute();
    assertEquals(tl.getX() + (100d / 1.2), sh.getTopLeftPoint().getX(), 5d);
    assertEquals(tl.getY() + (160d / 1.2), sh.getTopLeftPoint().getY(), 5d);
}
Also used : Color(javafx.scene.paint.Color) Point(net.sf.latexdraw.model.api.shape.Point) Test(org.junit.Test)

Example 89 with Point

use of net.sf.latexdraw.model.api.shape.Point in project latexdraw by arnobl.

the class ShapeFactoryImpl method createBezierCurveFrom.

@Override
@NotNull
public BezierCurve createBezierCurveFrom(final BezierCurve bc, final Point pointToAdd) {
    if (bc == null || !MathUtils.INST.isValidPt(pointToAdd)) {
        throw new IllegalArgumentException();
    }
    final List<Point> pts = new ArrayList<>(bc.getPoints());
    final List<Point> ptsCtrl = new ArrayList<>(bc.getFirstCtrlPts());
    pts.add(pointToAdd);
    ptsCtrl.add(createPoint(pointToAdd.getX(), pointToAdd.getY() + BezierCurve.DEFAULT_POSITION_CTRL));
    final BezierCurve copy = new BezierCurveImpl(pts, ptsCtrl);
    copy.copy(bc);
    return copy;
}
Also used : ArrayList(java.util.ArrayList) Point(net.sf.latexdraw.model.api.shape.Point) BezierCurve(net.sf.latexdraw.model.api.shape.BezierCurve) NotNull(org.jetbrains.annotations.NotNull)

Example 90 with Point

use of net.sf.latexdraw.model.api.shape.Point in project latexdraw by arnobl.

the class SquaredShapeBase method setWidth.

@Override
public void setWidth(final double width) {
    if (width > 0 && MathUtils.INST.isValidCoord(width)) {
        final Point pt = points.get(points.size() - 1);
        final double xPos = pt.getX() + width;
        final double yPos = pt.getY() - width;
        points.get(1).setX(xPos);
        points.get(2).setX(xPos);
        points.get(0).setY(yPos);
        points.get(1).setY(yPos);
    }
}
Also used : Point(net.sf.latexdraw.model.api.shape.Point)

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