Search in sources :

Example 6 with IPolygon

use of net.sf.latexdraw.models.interfaces.shape.IPolygon in project latexdraw by arnobl.

the class TestIPolygon method testConstructor.

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

Example 7 with IPolygon

use of net.sf.latexdraw.models.interfaces.shape.IPolygon in project latexdraw by arnobl.

the class PSTLatexdrawListener method exitPspolygon.

@Override
public void exitPspolygon(final net.sf.latexdraw.parsers.pst.PSTParser.PspolygonContext ctx) {
    Stream<IPoint> stream = ctx.ps.stream().map(node -> ShapeFactory.INST.createPoint(ctx.pstctx.coordToAdjustedPoint(node)));
    stream = Stream.concat(Stream.of(ShapeFactory.INST.createPoint(ctx.pstctx.coordToAdjustedPoint(ctx.p1))), stream);
    if (ctx.ps.size() == 1) {
        stream = Stream.concat(Stream.of(ShapeFactory.INST.createPoint(ctx.pstctx.originToPoint())), stream);
    }
    final IPolygon pol = ShapeFactory.INST.createPolygon(stream.collect(Collectors.toList()));
    setShapeParameters(pol, ctx.pstctx);
    if (ctx.pstctx.starredCmd(ctx.cmd)) {
        setShapeForStar(pol);
    }
    shapes.peek().addShape(pol);
}
Also used : IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint) IPolygon(net.sf.latexdraw.models.interfaces.shape.IPolygon)

Example 8 with IPolygon

use of net.sf.latexdraw.models.interfaces.shape.IPolygon in project latexdraw by arnobl.

the class PlotViewHelper method updatePolygon.

public IPolygon updatePolygon(final IPlot shape, final double posX, final double posY, final double minX, final double maxX, final double step) {
    final IPolygon pg = ShapeFactory.INST.createPolygon(fillPoints(shape, posX, posY, minX, maxX, step));
    pg.copy(shape);
    return pg;
}
Also used : IPolygon(net.sf.latexdraw.models.interfaces.shape.IPolygon)

Example 9 with IPolygon

use of net.sf.latexdraw.models.interfaces.shape.IPolygon in project latexdraw by arnobl.

the class LShapeFactory method createPolygonFrom.

@Override
public IPolygon createPolygonFrom(final IPolygon sh, final IPoint pointToAdd) {
    if (sh == null || !MathUtils.INST.isValidPt(pointToAdd))
        return null;
    final List<IPoint> pts = new ArrayList<>(sh.getPoints());
    pts.add(pointToAdd);
    final IPolygon copy = createPolygon(pts);
    copy.copy(sh);
    return copy;
}
Also used : ArrayList(java.util.ArrayList) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint) IPolygon(net.sf.latexdraw.models.interfaces.shape.IPolygon)

Example 10 with IPolygon

use of net.sf.latexdraw.models.interfaces.shape.IPolygon in project latexdraw by arnobl.

the class TestCanvasCreation method testDrawPolygon.

@Test
public void testDrawPolygon() {
    pencil.setCurrentChoice(EditionChoice.POLYGON);
    final Point2D pos = point(canvas).query();
    moveTo(pos).clickOn(MouseButton.PRIMARY).moveBy(-20d, -100d).clickOn(MouseButton.PRIMARY).moveBy(-100d, 50d).clickOn(MouseButton.SECONDARY).sleep(SLEEP);
    assertEquals(1, drawing.size());
    assertTrue(drawing.getShapeAt(0) instanceof IPolygon);
    final IPolygon sh = (IPolygon) drawing.getShapeAt(0);
    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) IPolygon(net.sf.latexdraw.models.interfaces.shape.IPolygon) Test(org.junit.Test)

Aggregations

IPolygon (net.sf.latexdraw.models.interfaces.shape.IPolygon)15 Test (org.junit.Test)9 IPoint (net.sf.latexdraw.models.interfaces.shape.IPoint)4 IBezierCurve (net.sf.latexdraw.models.interfaces.shape.IBezierCurve)2 IFreehand (net.sf.latexdraw.models.interfaces.shape.IFreehand)2 IPolyline (net.sf.latexdraw.models.interfaces.shape.IPolyline)2 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 Function (java.util.function.Function)1 Platform (javafx.application.Platform)1 ObjectProperty (javafx.beans.property.ObjectProperty)1 SimpleObjectProperty (javafx.beans.property.SimpleObjectProperty)1 Point2D (javafx.geometry.Point2D)1 Point3D (javafx.geometry.Point3D)1 Cursor (javafx.scene.Cursor)1 MouseButton (javafx.scene.input.MouseButton)1 FileChooser (javafx.stage.FileChooser)1 AddShape (net.sf.latexdraw.commands.shape.AddShape)1 InitTextSetter (net.sf.latexdraw.commands.shape.InitTextSetter)1