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));
}
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);
}
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;
}
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;
}
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());
}
Aggregations