Search in sources :

Example 6 with Polygon

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

the class TestPolygon method testConstructor.

@Test
public void testConstructor() {
    final Point pt1 = ShapeFactory.INST.createPoint(1, 1);
    final Point pt2 = ShapeFactory.INST.createPoint(2, 2);
    final Polygon pol = ShapeFactory.INST.createPolygon(Arrays.asList(pt1, pt2));
    assertEquals(pt1, pol.getPtAt(0));
    assertEquals(pt2, pol.getPtAt(-1));
}
Also used : Point(net.sf.latexdraw.model.api.shape.Point) Polygon(net.sf.latexdraw.model.api.shape.Polygon) Test(org.junit.Test)

Example 7 with Polygon

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

the class TestPSTShape method testLoadRotationAngleParams.

@Override
@ParameterizedTest
@MethodSource("net.sf.latexdraw.data.ShapeSupplier#getDiversifiedShapes")
public void testLoadRotationAngleParams(final Shape sh) {
    assumeFalse(sh instanceof Polygon || sh instanceof BezierCurve);
    final Shape s2 = produceOutputShapeFrom(sh);
    CompareShapeMatcher.INST.assertEqualShapeRotationAngle(sh, s2);
}
Also used : Shape(net.sf.latexdraw.model.api.shape.Shape) Polygon(net.sf.latexdraw.model.api.shape.Polygon) BezierCurve(net.sf.latexdraw.model.api.shape.BezierCurve) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 8 with Polygon

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

the class ShapeFactoryImpl method createPolygonFrom.

@Override
@NotNull
public Polygon createPolygonFrom(final Polygon sh, final Point pointToAdd) {
    if (sh == null || !MathUtils.INST.isValidPt(pointToAdd)) {
        throw new IllegalArgumentException();
    }
    final List<Point> pts = new ArrayList<>(sh.getPoints());
    pts.add(pointToAdd);
    final Polygon copy = createPolygon(pts);
    copy.copy(sh);
    return copy;
}
Also used : ArrayList(java.util.ArrayList) Point(net.sf.latexdraw.model.api.shape.Point) Polygon(net.sf.latexdraw.model.api.shape.Polygon) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with Polygon

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

the class TestCanvasCreation method testDrawPolygon.

@Test
public void testDrawPolygon() {
    final Point2D pos = point(canvas).query();
    Cmds.of(CmdFXVoid.of(() -> editing.setCurrentChoice(EditionChoice.POLYGON)), () -> moveTo(pos).clickOn(MouseButton.PRIMARY).moveBy(-20d, -100d).clickOn(MouseButton.PRIMARY).moveBy(-100d, 50d).clickOn(MouseButton.SECONDARY)).execute();
    assertEquals(1, drawing.size());
    assertTrue(drawing.getShapeAt(0).orElseThrow() instanceof Polygon);
    final Polygon sh = (Polygon) drawing.getShapeAt(0).orElseThrow();
    assertEquals(-Canvas.getMargins() + canvas.screenToLocal(pos).getX(), sh.getPtAt(0).getX(), 1d);
    assertEquals(-Canvas.getMargins() + canvas.screenToLocal(pos).getY(), sh.getPtAt(0).getY(), 1d);
    assertEquals(3, sh.getNbPoints());
}
Also used : Point2D(javafx.geometry.Point2D) Polygon(net.sf.latexdraw.model.api.shape.Polygon) Test(org.junit.Test)

Example 10 with Polygon

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

the class PlotViewComputation method updatePolygon.

default Polygon updatePolygon(final Plot shape, final double posX, final double posY, final double minX, final double maxX, final double step) {
    final Polygon pg = ShapeFactory.INST.createPolygon(fillPoints(shape, posX, posY, minX, maxX, step));
    pg.copy(shape);
    return pg;
}
Also used : Polygon(net.sf.latexdraw.model.api.shape.Polygon)

Aggregations

Polygon (net.sf.latexdraw.model.api.shape.Polygon)15 Test (org.junit.jupiter.api.Test)7 BezierCurve (net.sf.latexdraw.model.api.shape.BezierCurve)3 Point (net.sf.latexdraw.model.api.shape.Point)3 NotNull (org.jetbrains.annotations.NotNull)3 Freehand (net.sf.latexdraw.model.api.shape.Freehand)2 Polyline (net.sf.latexdraw.model.api.shape.Polyline)2 Shape (net.sf.latexdraw.model.api.shape.Shape)2 Test (org.junit.Test)2 Click (io.github.interacto.jfx.interaction.library.Click)1 DnD (io.github.interacto.jfx.interaction.library.DnD)1 MultiClick (io.github.interacto.jfx.interaction.library.MultiClick)1 PointsData (io.github.interacto.jfx.interaction.library.PointsData)1 Press (io.github.interacto.jfx.interaction.library.Press)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Objects (java.util.Objects)1 Function (java.util.function.Function)1 Point2D (javafx.geometry.Point2D)1 Point3D (javafx.geometry.Point3D)1