use of net.sf.latexdraw.models.interfaces.shape.IPoint in project latexdraw by arnobl.
the class TestISquaredShape method testMirrorVertical.
@Theory
public void testMirrorVertical(@SquaredData final ISquaredShape shape) {
final IPoint p1 = ShapeFactory.INST.createPoint(3, 1);
final IPoint p2 = ShapeFactory.INST.createPoint(1, 3);
shape.setPosition(p2);
shape.setWidth(p1.getX() - p2.getX());
shape.mirrorVertical(shape.getGravityCentre().getY());
assertEqualsDouble(1., shape.getPtAt(0).getX());
assertEqualsDouble(3., shape.getPtAt(1).getX());
assertEqualsDouble(3., shape.getPtAt(2).getX());
assertEqualsDouble(1., shape.getPtAt(-1).getX());
assertEqualsDouble(3., shape.getPtAt(0).getY());
assertEqualsDouble(3., shape.getPtAt(1).getY());
assertEqualsDouble(1., shape.getPtAt(2).getY());
assertEqualsDouble(1., shape.getPtAt(-1).getY());
}
use of net.sf.latexdraw.models.interfaces.shape.IPoint in project latexdraw by arnobl.
the class TestIText method testMirrorVertical.
@Test
public void testMirrorVertical() {
final IPoint pos = ShapeFactory.INST.createPoint(shape.getPosition());
shape.mirrorVertical(shape.getGravityCentre().getY());
assertEquals(pos, shape.getPosition());
}
use of net.sf.latexdraw.models.interfaces.shape.IPoint in project latexdraw by arnobl.
the class TestIText method testMirrorHorizontal.
@Test
public void testMirrorHorizontal() {
final IPoint pos = ShapeFactory.INST.createPoint(shape.getPosition());
shape.mirrorHorizontal(shape.getGravityCentre().getX());
assertEquals(pos, shape.getPosition());
}
use of net.sf.latexdraw.models.interfaces.shape.IPoint in project latexdraw by arnobl.
the class PSTLatexdrawListener method exitPsgrid.
@Override
public void exitPsgrid(final net.sf.latexdraw.parsers.pst.PSTParser.PsgridContext ctx) {
final IGrid grid = ShapeFactory.INST.createGrid(ShapeFactory.INST.createPoint());
final IPoint gridStart;
final IPoint gridEnd;
final IPoint pos;
boolean isGridXLabelInverted = false;
boolean isGridYLabelInverted = false;
if (ctx.p3 == null) {
if (ctx.p2 == null) {
if (ctx.p1 == null) {
gridStart = ShapeFactory.INST.createPoint(Math.round(ctx.pstctx.pictureSWPt.getX()), Math.round(ctx.pstctx.pictureSWPt.getY()));
gridEnd = ShapeFactory.INST.createPoint(Math.round(ctx.pstctx.pictureNEPt.getX()), Math.round(ctx.pstctx.pictureNEPt.getY()));
pos = ShapeFactory.INST.createPoint();
grid.setPosition(0d, 0d);
grid.setLabelsSize(0);
} else {
pos = ShapeFactory.INST.createPoint();
gridStart = ShapeFactory.INST.createPoint();
gridEnd = ShapeFactory.INST.createPoint(ctx.pstctx.coordToRawPoint(ctx.p1));
}
} else {
pos = ShapeFactory.INST.createPoint(ctx.pstctx.coordToRawPoint(ctx.p1));
gridStart = ShapeFactory.INST.createPoint(ctx.pstctx.coordToRawPoint(ctx.p1));
gridEnd = ShapeFactory.INST.createPoint(ctx.pstctx.coordToRawPoint(ctx.p2));
}
} else {
pos = ShapeFactory.INST.createPoint(ctx.pstctx.coordToRawPoint(ctx.p1));
gridStart = ShapeFactory.INST.createPoint(ctx.pstctx.coordToRawPoint(ctx.p2));
gridEnd = ShapeFactory.INST.createPoint(ctx.pstctx.coordToRawPoint(ctx.p3));
}
if (gridStart.getX() >= gridEnd.getX()) {
final double tmp = gridEnd.getX();
gridEnd.setX(gridStart.getX());
gridStart.setX(tmp);
isGridXLabelInverted = true;
}
if (gridStart.getY() >= gridEnd.getY()) {
final double tmp = gridEnd.getY();
gridEnd.setY(gridStart.getY());
gridStart.setY(tmp);
isGridYLabelInverted = true;
}
setStdGridParams(pos.getX(), pos.getY(), grid, ctx.pstctx);
setShapeParameters(grid, ctx.pstctx);
grid.setPosition(0d, 0d);
grid.setUnit(ctx.pstctx.unit);
grid.setGridDots((int) ctx.pstctx.gridDots);
grid.setGridLabelsColour(ctx.pstctx.gridlabelcolor);
grid.setLabelsSize((int) (ctx.pstctx.gridLabel * IShape.PPC));
grid.setGridWidth(Math.abs(ctx.pstctx.gridWidth * IShape.PPC));
grid.setSubGridColour(ctx.pstctx.subGridCol);
grid.setSubGridDiv((int) ctx.pstctx.subGridDiv);
grid.setSubGridDots((int) ctx.pstctx.subGridDots);
grid.setSubGridWidth(Math.abs(ctx.pstctx.subGridWidth * IShape.PPC));
grid.setLineColour(ctx.pstctx.gridColor);
grid.setXLabelSouth(!isGridYLabelInverted);
grid.setYLabelWest(!isGridXLabelInverted);
grid.setGridEndX(gridEnd.getX());
grid.setGridEndY(gridEnd.getY());
grid.setGridStartX(gridStart.getX());
grid.setGridStartY(gridStart.getY());
shapes.peek().addShape(grid);
}
use of net.sf.latexdraw.models.interfaces.shape.IPoint in project latexdraw by arnobl.
the class PSTLatexdrawListener method exitPsbezier.
@Override
public void exitPsbezier(final net.sf.latexdraw.parsers.pst.PSTParser.PsbezierContext ctx) {
// Transforming all the parsed points
Stream<IPoint> stream = IntStream.range(0, ctx.p1.size()).mapToObj(i -> Stream.of(ctx.p1.get(i), ctx.p2.get(i), ctx.p3.get(i))).flatMap(s -> s).map(pt -> ShapeFactory.INST.createPoint(ctx.pstctx.coordToAdjustedPoint(pt)));
// Managing the optional last point
if (ctx.p4 == null) {
stream = Stream.concat(Stream.of(ShapeFactory.INST.createPoint(ctx.pstctx.originToPoint())), stream);
} else {
stream = Stream.concat(stream, Stream.of(ShapeFactory.INST.createPoint(ctx.pstctx.coordToAdjustedPoint(ctx.p4))));
}
final List<IPoint> allPts = stream.collect(Collectors.toList());
// Point 1: shape point, point 2 : second control point (ignored), point 3 : first control point
final List<IPoint> pts = IntStream.range(0, allPts.size()).filter(i -> i % 3 == 0).mapToObj(i -> allPts.get(i)).collect(Collectors.toList());
final List<IPoint> ctrls = IntStream.range(2, allPts.size()).filter(i -> i % 3 == 2).mapToObj(i -> allPts.get(i)).collect(Collectors.toList());
if (allPts.size() > 1) {
ctrls.add(0, allPts.get(1));
}
boolean closed = false;
// Closing the shape
if (pts.size() > 2 && pts.get(0).equals(pts.get(pts.size() - 1))) {
pts.remove(pts.size() - 1);
ctrls.remove(ctrls.size() - 1);
closed = true;
}
final IBezierCurve bc = ShapeFactory.INST.createBezierCurve(pts);
bc.setOpened(!closed);
setShapeParameters(bc, ctx.pstctx);
setArrows(bc, ctx.pstctx);
// Setting the control points
IntStream.range(0, bc.getFirstCtrlPts().size()).forEach(i -> bc.getFirstCtrlPtAt(i).setPoint(ctrls.get(i)));
// Updating the second control points to the first ones
bc.updateSecondControlPoints();
if (ctx.pstctx.starredCmd(ctx.cmd)) {
setShapeForStar(bc);
}
shapes.peek().addShape(bc);
}
Aggregations