Search in sources :

Example 36 with IPoint

use of net.sf.latexdraw.models.interfaces.shape.IPoint 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 37 with IPoint

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

the class PSTLatexdrawListener method exitPsframe.

@Override
public void exitPsframe(final net.sf.latexdraw.parsers.pst.PSTParser.PsframeContext ctx) {
    final IRectangle rec = ShapeFactory.INST.createRectangle();
    final Tuple<IPoint, IPoint> pts = getRectangularPoints(ctx.p1, ctx.p2, ctx.pstctx);
    rec.setLineArc(ctx.pstctx.frameArc);
    // The x-coordinates of pt1 must be lower than pt2 one.
    if (pts.a.getX() > pts.b.getX()) {
        final double tmp = pts.a.getX();
        pts.a.setX(pts.b.getX());
        pts.b.setX(tmp);
    }
    // The y-coordinates of pt1 must be lower than pt2 one.
    if (pts.a.getY() < pts.b.getY()) {
        final double tmp = pts.a.getY();
        pts.a.setY(pts.b.getY());
        pts.b.setY(tmp);
    }
    setRectangularShape(rec, pts.a.getX(), pts.a.getY(), Math.abs(pts.b.getX() - pts.a.getX()), Math.abs(pts.b.getY() - pts.a.getY()), ctx.pstctx, ctx.cmd);
    shapes.peek().addShape(rec);
}
Also used : IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint) IRectangle(net.sf.latexdraw.models.interfaces.shape.IRectangle)

Example 38 with IPoint

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

the class GenericViewArrow method updatePath.

default void updatePath(final boolean isShadow) {
    final IArrow arrow = getArrow();
    final ILine arrowLine = arrow.getArrowLine();
    if (arrow.getArrowStyle() == ArrowStyle.NONE || arrowLine == null || !arrow.hasStyle()) {
        return;
    }
    final IPoint pt1 = arrowLine.getPoint1();
    final IPoint pt2 = arrowLine.getPoint2();
    setTranslation(pt1.getX(), pt1.getY());
    switch(arrow.getArrowStyle()) {
        case BAR_END:
            updatePathBarEnd(isShadow);
            break;
        case BAR_IN:
            updatePathBarIn(pt1, pt2, isShadow);
            break;
        case CIRCLE_END:
        case DISK_END:
            updatePathDiskCircleEnd(isShadow);
            break;
        case CIRCLE_IN:
        case DISK_IN:
            updatePathDiskCircleIn(pt1, pt2, isShadow);
            break;
        case RIGHT_ARROW:
        case LEFT_ARROW:
            updatePathRightLeftArrow(isShadow);
            break;
        case RIGHT_DBLE_ARROW:
        case LEFT_DBLE_ARROW:
            updatePathDoubleLeftRightArrow(isShadow);
            break;
        case RIGHT_ROUND_BRACKET:
        case LEFT_ROUND_BRACKET:
            updatePathRoundLeftRightBracket(isShadow);
            break;
        case LEFT_SQUARE_BRACKET:
        case RIGHT_SQUARE_BRACKET:
            updatePathRightLeftSquaredBracket(isShadow);
            break;
        case SQUARE_END:
            updatePathSquareEnd(pt1, pt2, isShadow);
            break;
        case ROUND_END:
            updatePathRoundEnd(isShadow);
            break;
        case ROUND_IN:
            updatePathRoundIn(pt1, pt2, isShadow);
            break;
        case NONE:
            break;
    }
}
Also used : ILine(net.sf.latexdraw.models.interfaces.shape.ILine) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint) IArrow(net.sf.latexdraw.models.interfaces.shape.IArrow)

Example 39 with IPoint

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

the class PlotViewHelper method updateCurve.

public IBezierCurve updateCurve(final IPlot shape, final double posX, final double posY, final double minX, final double maxX, final double step) {
    // The algorithm follows this definition:
    // https://stackoverflow.com/questions/15864441/how-to-make-a-line-curve-through-points
    final double scale = 0.33d;
    final IBezierCurve bc = ShapeFactory.INST.createBezierCurve(fillPoints(shape, posX, posY, minX, maxX, step));
    bc.setOpened(shape.getPlotStyle() != PlotStyle.CCURVE);
    bc.copy(shape);
    int i = 0;
    final int last = bc.getPoints().size() - 1;
    for (final IPoint pt : bc.getPoints()) {
        if (i == 0) {
            final IPoint p2 = bc.getPtAt(i + 1);
            final IPoint tangent = p2.substract(pt);
            final IPoint q1 = pt.add(tangent.zoom(scale));
            bc.setXFirstCtrlPt(q1.getX(), i);
            bc.setYFirstCtrlPt(q1.getY(), i);
        } else if (i == last) {
            final IPoint p0 = bc.getPtAt(i - 1);
            final IPoint tangent = pt.substract(p0);
            final IPoint q0 = pt.substract(tangent.zoom(scale));
            bc.setXFirstCtrlPt(q0.getX(), i);
            bc.setYFirstCtrlPt(q0.getY(), i);
        } else {
            final IPoint p0 = bc.getPtAt(i - 1);
            final IPoint p2 = bc.getPtAt(i + 1);
            final IPoint tangent = p2.substract(p0).normalise();
            final IPoint q0 = pt.substract(tangent.zoom(scale * pt.substract(p0).magnitude()));
            bc.setXFirstCtrlPt(q0.getX(), i);
            bc.setYFirstCtrlPt(q0.getY(), i);
        }
        i++;
    }
    bc.updateSecondControlPoints();
    return bc;
}
Also used : IBezierCurve(net.sf.latexdraw.models.interfaces.shape.IBezierCurve) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint)

Example 40 with IPoint

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

the class PlotViewHelper method fillPoints.

public List<IPoint> fillPoints(final IPlot shape, final double posX, final double posY, final double minX, final double maxX, final double step) {
    final double xs = shape.getXScale();
    final double ys = shape.getYScale();
    double x = minX;
    final List<IPoint> pts = new ArrayList<>();
    if (shape.isPolar()) {
        for (int i = 0; i < shape.getNbPlottedPoints(); i++, x += step) {
            pts.add(getPolarPoint(shape, x, xs, ys, posX, posY));
        }
        pts.add(getPolarPoint(shape, maxX, xs, ys, posX, posY));
    } else {
        for (int i = 0; i < shape.getNbPlottedPoints(); i++, x += step) {
            pts.add(ShapeFactory.INST.createPoint(x * IShape.PPC * xs + posX, -shape.getY(x) * IShape.PPC * ys + posY));
        }
    }
    return pts;
}
Also used : ArrayList(java.util.ArrayList) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint) 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