Search in sources :

Example 31 with IPoint

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());
}
Also used : IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint) Theory(org.junit.experimental.theories.Theory)

Example 32 with IPoint

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());
}
Also used : IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint) Test(org.junit.Test) HelperTest(net.sf.latexdraw.HelperTest)

Example 33 with IPoint

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());
}
Also used : IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint) Test(org.junit.Test) HelperTest(net.sf.latexdraw.HelperTest)

Example 34 with IPoint

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);
}
Also used : IGrid(net.sf.latexdraw.models.interfaces.shape.IGrid) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint)

Example 35 with IPoint

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);
}
Also used : IntStream(java.util.stream.IntStream) Arrays(java.util.Arrays) ShapeFactory(net.sf.latexdraw.models.ShapeFactory) IRectangularShape(net.sf.latexdraw.models.interfaces.shape.IRectangularShape) Token(org.antlr.v4.runtime.Token) IGrid(net.sf.latexdraw.models.interfaces.shape.IGrid) MathUtils(net.sf.latexdraw.models.MathUtils) Deque(java.util.Deque) BorderPos(net.sf.latexdraw.models.interfaces.shape.BorderPos) IArrowableSingleShape(net.sf.latexdraw.models.interfaces.shape.IArrowableSingleShape) ICircle(net.sf.latexdraw.models.interfaces.shape.ICircle) IShape(net.sf.latexdraw.models.interfaces.shape.IShape) LineStyle(net.sf.latexdraw.models.interfaces.shape.LineStyle) DviPsColors(net.sf.latexdraw.view.latex.DviPsColors) TicksStyle(net.sf.latexdraw.models.interfaces.shape.TicksStyle) Point2D(javafx.geometry.Point2D) ArcStyle(net.sf.latexdraw.models.interfaces.shape.ArcStyle) AxesStyle(net.sf.latexdraw.models.interfaces.shape.AxesStyle) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint) FreeHandStyle(net.sf.latexdraw.models.interfaces.shape.FreeHandStyle) IEllipse(net.sf.latexdraw.models.interfaces.shape.IEllipse) IFreehand(net.sf.latexdraw.models.interfaces.shape.IFreehand) IStandardGrid(net.sf.latexdraw.models.interfaces.shape.IStandardGrid) ITriangle(net.sf.latexdraw.models.interfaces.shape.ITriangle) TextPosition(net.sf.latexdraw.models.interfaces.shape.TextPosition) PlottingStyle(net.sf.latexdraw.models.interfaces.shape.PlottingStyle) IPolygon(net.sf.latexdraw.models.interfaces.shape.IPolygon) IPolyline(net.sf.latexdraw.models.interfaces.shape.IPolyline) IText(net.sf.latexdraw.models.interfaces.shape.IText) ICircleArc(net.sf.latexdraw.models.interfaces.shape.ICircleArc) IGroup(net.sf.latexdraw.models.interfaces.shape.IGroup) IBezierCurve(net.sf.latexdraw.models.interfaces.shape.IBezierCurve) Collectors(java.util.stream.Collectors) PlotStyle(net.sf.latexdraw.models.interfaces.shape.PlotStyle) DotStyle(net.sf.latexdraw.models.interfaces.shape.DotStyle) Tuple(net.sf.latexdraw.util.Tuple) ArrowStyle(net.sf.latexdraw.models.interfaces.shape.ArrowStyle) List(java.util.List) Stream(java.util.stream.Stream) Color(net.sf.latexdraw.models.interfaces.shape.Color) FillingStyle(net.sf.latexdraw.models.interfaces.shape.FillingStyle) IPlot(net.sf.latexdraw.models.interfaces.shape.IPlot) IRhombus(net.sf.latexdraw.models.interfaces.shape.IRhombus) IAxes(net.sf.latexdraw.models.interfaces.shape.IAxes) IRectangle(net.sf.latexdraw.models.interfaces.shape.IRectangle) IDot(net.sf.latexdraw.models.interfaces.shape.IDot) ArrayDeque(java.util.ArrayDeque) Collections(java.util.Collections) IBezierCurve(net.sf.latexdraw.models.interfaces.shape.IBezierCurve) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint)

Aggregations

IPoint (net.sf.latexdraw.models.interfaces.shape.IPoint)191 Test (org.junit.Test)45 HelperTest (net.sf.latexdraw.HelperTest)25 Theory (org.junit.experimental.theories.Theory)21 IShape (net.sf.latexdraw.models.interfaces.shape.IShape)15 SVGElement (net.sf.latexdraw.parsers.svg.SVGElement)11 SVGGElement (net.sf.latexdraw.parsers.svg.SVGGElement)11 ShapeFactory (net.sf.latexdraw.models.ShapeFactory)10 ILine (net.sf.latexdraw.models.interfaces.shape.ILine)10 IBezierCurve (net.sf.latexdraw.models.interfaces.shape.IBezierCurve)9 IGroup (net.sf.latexdraw.models.interfaces.shape.IGroup)9 ArrayList (java.util.ArrayList)8 MathUtils (net.sf.latexdraw.models.MathUtils)8 Collections (java.util.Collections)7 IPolygon (net.sf.latexdraw.models.interfaces.shape.IPolygon)7 Arrays (java.util.Arrays)6 Cursor (javafx.scene.Cursor)6 BorderPos (net.sf.latexdraw.models.interfaces.shape.BorderPos)6 IModifiablePointsShape (net.sf.latexdraw.models.interfaces.shape.IModifiablePointsShape)6 Inject (net.sf.latexdraw.util.Inject)6