Search in sources :

Example 16 with SVGPathSegMoveto

use of net.sf.latexdraw.parsers.svg.path.SVGPathSegMoveto in project latexdraw by arnobl.

the class SVGFreeHand method getPathLines.

/**
 * Fills the given SVG path with elements corresponding to the Freehand lined path.
 * @since 3.0
 */
protected void getPathLines(final SVGPathSegList path) {
    final IPoint p = shape.getPtAt(0);
    int i;
    final int size = shape.getNbPoints();
    final int interval = shape.getInterval();
    path.add(new SVGPathSegMoveto(p.getX(), p.getY(), false));
    for (i = interval; i < size; i += interval) {
        path.add(new SVGPathSegLineto(shape.getPtAt(i).getX(), shape.getPtAt(i).getY(), false));
    }
    if (i - interval < size) {
        path.add(new SVGPathSegLineto(shape.getPtAt(-1).getX(), shape.getPtAt(-1).getY(), false));
    }
}
Also used : SVGPathSegMoveto(net.sf.latexdraw.parsers.svg.path.SVGPathSegMoveto) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint) SVGPathSegLineto(net.sf.latexdraw.parsers.svg.path.SVGPathSegLineto) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint)

Example 17 with SVGPathSegMoveto

use of net.sf.latexdraw.parsers.svg.path.SVGPathSegMoveto in project latexdraw by arnobl.

the class SVGFreeHand method getPathCurves.

/**
 * Fills the given SVG path with elements corresponding to the Freehand curved path.
 * @since 3.0
 */
protected void getPathCurves(final SVGPathSegList path) {
    double prevx = shape.getPtAt(-1).getX();
    double prevy = shape.getPtAt(-1).getY();
    double curx = shape.getPtAt(0).getX();
    double cury = shape.getPtAt(0).getY();
    double midx = (curx + prevx) / 2d;
    double midy = (cury + prevy) / 2d;
    int i;
    final int size = shape.getNbPoints();
    final int interval = shape.getInterval();
    path.add(new SVGPathSegMoveto(curx, cury, false));
    if (size > interval) {
        prevx = curx;
        prevy = cury;
        curx = shape.getPtAt(interval).getX();
        cury = shape.getPtAt(interval).getY();
        midx = (curx + prevx) / 2d;
        midy = (cury + prevy) / 2d;
        path.add(new SVGPathSegLineto(midx, midy, false));
    }
    for (i = interval * 2; i < size; i += interval) {
        final double x1 = (midx + curx) / 2d;
        final double y1 = (midy + cury) / 2d;
        prevx = curx;
        prevy = cury;
        curx = shape.getPtAt(i).getX();
        cury = shape.getPtAt(i).getY();
        midx = (curx + prevx) / 2d;
        midy = (cury + prevy) / 2d;
        final double x2 = (prevx + midx) / 2d;
        final double y2 = (prevy + midy) / 2d;
        path.add(new SVGPathSegCurvetoCubic(midx, midy, x1, y1, x2, y2, false));
    }
    if (i - interval + 1 < size) {
        final double x1 = (midx + curx) / 2d;
        final double y1 = (midy + cury) / 2d;
        prevx = curx;
        prevy = cury;
        curx = shape.getPtAt(-1).getX();
        cury = shape.getPtAt(-1).getY();
        midx = (curx + prevx) / 2d;
        midy = (cury + prevy) / 2d;
        final double x2 = (prevx + midx) / 2d;
        final double y2 = (prevy + midy) / 2d;
        path.add(new SVGPathSegCurvetoCubic(shape.getPtAt(-1).getX(), shape.getPtAt(-1).getY(), x1, y1, x2, y2, false));
    }
}
Also used : SVGPathSegMoveto(net.sf.latexdraw.parsers.svg.path.SVGPathSegMoveto) SVGPathSegCurvetoCubic(net.sf.latexdraw.parsers.svg.path.SVGPathSegCurvetoCubic) SVGPathSegLineto(net.sf.latexdraw.parsers.svg.path.SVGPathSegLineto) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint)

Example 18 with SVGPathSegMoveto

use of net.sf.latexdraw.parsers.svg.path.SVGPathSegMoveto in project latexdraw by arnobl.

the class SVGPathElement method isPolygon.

/**
 * @return True if the path is composed of lines and has a 'close path' segment at the end.
 * @since 0.1
 */
public boolean isPolygon() {
    final SVGPathSegList segList = getSegList();
    if (segList.isEmpty() || !(segList.get(0) instanceof SVGPathSegMoveto))
        return false;
    boolean ok = true;
    int i;
    final int size;
    for (i = 1, size = segList.size() - 1; i < size && ok; i++) if (!(segList.get(i) instanceof SVGPathSegLineto))
        ok = false;
    if (!(segList.get(segList.size() - 1) instanceof SVGPathSegClosePath))
        ok = false;
    return ok;
}
Also used : SVGPathSegMoveto(net.sf.latexdraw.parsers.svg.path.SVGPathSegMoveto) SVGPathSegLineto(net.sf.latexdraw.parsers.svg.path.SVGPathSegLineto) SVGPathSegList(net.sf.latexdraw.parsers.svg.path.SVGPathSegList) SVGPathSegClosePath(net.sf.latexdraw.parsers.svg.path.SVGPathSegClosePath)

Example 19 with SVGPathSegMoveto

use of net.sf.latexdraw.parsers.svg.path.SVGPathSegMoveto in project latexdraw by arnobl.

the class SVGPathElement method isBezierCurve.

public boolean isBezierCurve() {
    final SVGPathSegList segList = getSegList();
    if (segList.isEmpty() || !(segList.get(0) instanceof SVGPathSegMoveto))
        return false;
    final int size = segList.size() - 1;
    boolean ok = true;
    int i;
    for (i = 1; i < size && ok; i++) if (!(segList.get(i) instanceof SVGPathSegCurvetoCubic) && !(segList.get(i) instanceof SVGPathSegCurvetoCubicSmooth))
        ok = false;
    return ok && (segList.get(size) instanceof SVGPathSegClosePath || segList.get(size) instanceof SVGPathSegCurvetoCubic || segList.get(size) instanceof SVGPathSegCurvetoCubicSmooth);
}
Also used : SVGPathSegCurvetoCubicSmooth(net.sf.latexdraw.parsers.svg.path.SVGPathSegCurvetoCubicSmooth) SVGPathSegMoveto(net.sf.latexdraw.parsers.svg.path.SVGPathSegMoveto) SVGPathSegCurvetoCubic(net.sf.latexdraw.parsers.svg.path.SVGPathSegCurvetoCubic) SVGPathSegList(net.sf.latexdraw.parsers.svg.path.SVGPathSegList) SVGPathSegClosePath(net.sf.latexdraw.parsers.svg.path.SVGPathSegClosePath)

Example 20 with SVGPathSegMoveto

use of net.sf.latexdraw.parsers.svg.path.SVGPathSegMoveto in project latexdraw by arnobl.

the class TestSVGPathSegLinetoHorizontal method testToString.

@Test
public void testToString() throws ParseException {
    SVGPathSegMoveto m = new SVGPathSegMoveto(0d, 0d, false);
    SVGPathParser parser = new SVGPathParser(m.toString() + " " + seg.toString(), pathSeg -> {
        if (pathSeg instanceof SVGPathSegMoveto && cpt == 0) {
            cpt++;
            return;
        }
        assertTrue(pathSeg instanceof SVGPathSegLinetoHorizontal);
        SVGPathSegLinetoHorizontal seg2 = (SVGPathSegLinetoHorizontal) pathSeg;
        assertEquals(seg.getX(), seg2.getX(), 0.0001);
        assertEquals(seg.isRelative(), seg2.isRelative());
    });
    parser.parse();
}
Also used : SVGPathParser(net.sf.latexdraw.parsers.svg.parsers.SVGPathParser) SVGPathSegMoveto(net.sf.latexdraw.parsers.svg.path.SVGPathSegMoveto) SVGPathSegLinetoHorizontal(net.sf.latexdraw.parsers.svg.path.SVGPathSegLinetoHorizontal) Test(org.junit.Test)

Aggregations

SVGPathSegMoveto (net.sf.latexdraw.parsers.svg.path.SVGPathSegMoveto)22 SVGPathParser (net.sf.latexdraw.parsers.svg.parsers.SVGPathParser)9 Test (org.junit.Test)9 SVGPathSegLineto (net.sf.latexdraw.parsers.svg.path.SVGPathSegLineto)7 SVGPathSegList (net.sf.latexdraw.parsers.svg.path.SVGPathSegList)7 IPoint (net.sf.latexdraw.models.interfaces.shape.IPoint)6 SVGPathSegClosePath (net.sf.latexdraw.parsers.svg.path.SVGPathSegClosePath)5 SVGPathSegCurvetoCubic (net.sf.latexdraw.parsers.svg.path.SVGPathSegCurvetoCubic)4 SVGPathSegArc (net.sf.latexdraw.parsers.svg.path.SVGPathSegArc)3 SVGPathElement (net.sf.latexdraw.parsers.svg.SVGPathElement)2 SVGPathSegCurvetoCubicSmooth (net.sf.latexdraw.parsers.svg.path.SVGPathSegCurvetoCubicSmooth)2 Point2D (java.awt.geom.Point2D)1 ArrayList (java.util.ArrayList)1 ArcStyle (net.sf.latexdraw.models.interfaces.shape.ArcStyle)1 IBezierCurve (net.sf.latexdraw.models.interfaces.shape.IBezierCurve)1 SVGDefsElement (net.sf.latexdraw.parsers.svg.SVGDefsElement)1 SVGElement (net.sf.latexdraw.parsers.svg.SVGElement)1 SVGGElement (net.sf.latexdraw.parsers.svg.SVGGElement)1 CtrlPointsSeg (net.sf.latexdraw.parsers.svg.path.CtrlPointsSeg)1 SVGPathSegCurvetoQuadratic (net.sf.latexdraw.parsers.svg.path.SVGPathSegCurvetoQuadratic)1