Search in sources :

Example 6 with Freehand

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

the class TestPSTShape method testFreeHandPointsCurves.

@Test
public void testFreeHandPointsCurves() {
    final Freehand fh = ShapeFactory.INST.createFreeHand(Arrays.asList(ShapeFactory.INST.createPoint(50d, 70d), ShapeFactory.INST.createPoint(100d, 90d), ShapeFactory.INST.createPoint(110d, 100d), ShapeFactory.INST.createPoint(150d, 180d)));
    fh.setInterval(1);
    fh.setType(FreeHandStyle.CURVES);
    final Shape s2 = produceOutputShapeFrom(fh);
    assertThat(s2.getPoints()).isEqualTo(Arrays.asList(ShapeFactory.INST.createPoint(50d, 70d), ShapeFactory.INST.createPoint(75d, 80d), ShapeFactory.INST.createPoint(105d, 95d), ShapeFactory.INST.createPoint(130d, 140d)));
}
Also used : Shape(net.sf.latexdraw.model.api.shape.Shape) Freehand(net.sf.latexdraw.model.api.shape.Freehand) PolymorphShapeTest(net.sf.latexdraw.view.PolymorphShapeTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 7 with Freehand

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

the class ShapeFactoryImpl method createFreeHandFrom.

@Override
@NotNull
public Freehand createFreeHandFrom(final Freehand 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 Freehand copy = createFreeHand(pts);
    copy.copy(sh);
    return copy;
}
Also used : ArrayList(java.util.ArrayList) Freehand(net.sf.latexdraw.model.api.shape.Freehand) Point(net.sf.latexdraw.model.api.shape.Point) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with Freehand

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

the class TestCanvasCreation method testDrawFreeHand.

@Test
public void testDrawFreeHand() {
    final Point2D pos = point(canvas).query();
    Cmds.of(CmdFXVoid.of(() -> editing.setCurrentChoice(EditionChoice.FREE_HAND)), CmdFXVoid.of(() -> editing.getGroupParams().setInterval(1)), () -> drag(pos, MouseButton.PRIMARY).dropBy(100d, 200d)).execute();
    assertEquals(1, drawing.size());
    assertTrue(drawing.getShapeAt(0).orElseThrow() instanceof Freehand);
    assertEquals(100d, drawing.getShapeAt(0).orElseThrow().getWidth(), 1d);
    assertEquals(200d, drawing.getShapeAt(0).orElseThrow().getHeight(), 1d);
    assertEquals(-Canvas.getMargins() + canvas.screenToLocal(pos).getX(), drawing.getShapeAt(0).orElseThrow().getTopLeftPoint().getX(), 1d);
    assertEquals(-Canvas.getMargins() + canvas.screenToLocal(pos).getY(), drawing.getShapeAt(0).orElseThrow().getTopLeftPoint().getY(), 1d);
}
Also used : Point2D(javafx.geometry.Point2D) Freehand(net.sf.latexdraw.model.api.shape.Freehand) Test(org.junit.Test)

Example 9 with Freehand

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

the class PolymorphFreeHandTest method testFreeHandType.

@ParameterizedTest
@MethodSource("net.sf.latexdraw.data.ShapeSupplier#createDiversifiedFreeHand")
default void testFreeHandType(final Freehand sh) {
    final Freehand s2 = produceOutputShapeFrom(sh);
    assertEquals(sh.getType(), s2.getType());
}
Also used : Freehand(net.sf.latexdraw.model.api.shape.Freehand) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 10 with Freehand

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

the class TestPSTShape method testFreeHandPointsLines.

@Test
public void testFreeHandPointsLines() {
    final Freehand fh = ShapeFactory.INST.createFreeHand(Arrays.asList(ShapeFactory.INST.createPoint(50d, 70d), ShapeFactory.INST.createPoint(100d, 90d), ShapeFactory.INST.createPoint(132d, 112d), ShapeFactory.INST.createPoint(150d, 180d)));
    fh.setInterval(1);
    fh.setType(FreeHandStyle.LINES);
    final Shape s2 = produceOutputShapeFrom(fh);
    assertThat(s2.getPoints()).isEqualTo(produceOutputShapeFrom(s2).getPoints());
}
Also used : Shape(net.sf.latexdraw.model.api.shape.Shape) Freehand(net.sf.latexdraw.model.api.shape.Freehand) PolymorphShapeTest(net.sf.latexdraw.view.PolymorphShapeTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

Freehand (net.sf.latexdraw.model.api.shape.Freehand)16 Test (org.junit.jupiter.api.Test)7 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 Shape (net.sf.latexdraw.model.api.shape.Shape)3 BezierCurve (net.sf.latexdraw.model.api.shape.BezierCurve)2 Point (net.sf.latexdraw.model.api.shape.Point)2 Polygon (net.sf.latexdraw.model.api.shape.Polygon)2 Polyline (net.sf.latexdraw.model.api.shape.Polyline)2 NotNull (org.jetbrains.annotations.NotNull)2 Test (org.junit.Test)2 MethodSource (org.junit.jupiter.params.provider.MethodSource)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