Search in sources :

Example 16 with Point

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

the class TestBorder method testMoveCtrl1PtHandlerMovePt.

@Test
public void testMoveCtrl1PtHandlerMovePt() {
    Cmds.of(addBezier, selectAllShapes).execute();
    final Point point = ShapeFactory.INST.createPoint(addedBezier.getFirstCtrlPtAt(1));
    point.translate(100d, 20d);
    Cmds.of(() -> drag(border.ctrlPt1Handlers.get(1)).dropBy(100d, 20d)).execute();
    assertEquals(point.getX(), addedBezier.getFirstCtrlPtAt(1).getX(), 1d);
    assertEquals(point.getY(), addedBezier.getFirstCtrlPtAt(1).getY(), 1d);
}
Also used : Point(net.sf.latexdraw.model.api.shape.Point) Test(org.junit.Test)

Example 17 with Point

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

the class TestBorder method testArcEndHandlerRotated.

@Test
public void testArcEndHandlerRotated() {
    Cmds.of(addArc, selectAllShapes, () -> addedArc.setRotationAngle(0.5)).execute();
    final Point gc = addedArc.getGravityCentre();
    final Point point = addedArc.getEndPoint().rotatePoint(addedArc.getGravityCentre(), addedArc.getRotationAngle());
    final Point newpoint = point.rotatePoint(gc, Math.PI / 3d).rotatePoint(addedArc.getGravityCentre(), addedArc.getRotationAngle());
    Cmds.of(() -> drag(border.arcHandlerEnd).dropBy(newpoint.getX() - point.getX(), newpoint.getY() - point.getY())).execute();
    final Line l1 = ShapeFactory.INST.createLine(gc, addedArc.getEndPoint().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 18 with Point

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

the class TestBorder method testScaleERectangle.

@Test
public void testScaleERectangle() {
    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(50d, 0d);
    Cmds.of(trCmd, () -> drag(border.scaleHandlers.get(4)).dropBy(50d, 10d)).execute();
    assertEquals(height, addedRec.getHeight(), 0.001);
    assertEquals(width + 50d, addedRec.getWidth(), 3d);
    assertEquals(tr.getX(), addedRec.getTopRightPoint().getX(), 2d);
    assertEquals(tr.getY(), addedRec.getTopRightPoint().getY(), 2d);
}
Also used : Point(net.sf.latexdraw.model.api.shape.Point) Test(org.junit.Test)

Example 19 with Point

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

the class TestBorder method testRotateTwoRectangles.

@Test
public void testRotateTwoRectangles() {
    final CmdFXVoid tr = () -> canvas.getDrawing().getShapeAt(1).orElseThrow().translate(150, 60);
    Cmds.of(addRec, addRec, tr, selectAllShapes).execute();
    final Point pt1 = ShapeFactory.INST.createPoint(point(border.rotHandler).query());
    final Point gc = ShapeFactory.INST.createPoint(point(getPane().getChildren().get(0)).query());
    Cmds.of(rotateDown).execute();
    final double a1 = ShapeFactory.INST.createLine(pt1, gc).getLineAngle();
    final double a2 = 2d * Math.PI - ShapeFactory.INST.createLine(ShapeFactory.INST.createPoint(pt1.getX() + txDown, pt1.getY() + tyDown), gc).getLineAngle();
    assertFalse("No rotation", ((ViewRectangle) canvas.getSelectedViews().get(0)).getBorder().getTransforms().isEmpty());
    assertFalse("No rotation", ((ViewRectangle) canvas.getSelectedViews().get(1)).getBorder().getTransforms().isEmpty());
    assertEquals(a1 + a2, ((Shape) getPane().getChildren().get(0).getUserData()).getRotationAngle(), 0.3);
    assertEquals(Math.toDegrees(a1 + a2), ((Rotate) ((ViewRectangle) canvas.getSelectedViews().get(0)).getBorder().getTransforms().get(0)).getAngle(), 15d);
    assertEquals(Math.toDegrees(a1 + a2), ((Rotate) ((ViewRectangle) canvas.getSelectedViews().get(1)).getBorder().getTransforms().get(0)).getAngle(), 15d);
}
Also used : Point(net.sf.latexdraw.model.api.shape.Point) ViewRectangle(net.sf.latexdraw.view.jfx.ViewRectangle) Test(org.junit.Test)

Example 20 with Point

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

the class TestBorder method testArcStartHandler.

@Test
public void testArcStartHandler() {
    Cmds.of(addArc, selectAllShapes).execute();
    final Point gc = addedArc.getGravityCentre();
    final Point point = ShapeFactory.INST.createPoint(addedArc.getStartPoint());
    final Point newpoint = point.rotatePoint(gc, -Math.PI / 4d);
    Cmds.of(() -> drag(border.arcHandlerStart).dropBy(newpoint.getX() - point.getX(), newpoint.getY() - point.getY())).execute();
    final Line l1 = ShapeFactory.INST.createLine(gc, ShapeFactory.INST.createPoint(addedArc.getStartPoint()));
    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)

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