Search in sources :

Example 1 with SVGPathSegCurvetoCubic

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

the class TestSVGPathSegCurvetoCubic method setUp.

@Before
public void setUp() {
    seg = new SVGPathSegCurvetoCubic(-1, -2, 3e1, 4e-1, -5e1, 6.5, true);
    cpt = 0;
}
Also used : SVGPathSegCurvetoCubic(net.sf.latexdraw.parsers.svg.path.SVGPathSegCurvetoCubic) Before(org.junit.Before)

Example 2 with SVGPathSegCurvetoCubic

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

the class TestSVGPathSegCurvetoCubic method testToString.

@Test
public void testToString() throws ParseException {
    SVGPathSegMoveto m = new SVGPathSegMoveto(0, 0, false);
    SVGPathParser parser = new SVGPathParser(m.toString() + " " + seg.toString(), pathSeg -> {
        if (pathSeg instanceof SVGPathSegMoveto && cpt == 0) {
            cpt++;
            return;
        }
        assertTrue(pathSeg instanceof SVGPathSegCurvetoCubic);
        SVGPathSegCurvetoCubic seg2 = (SVGPathSegCurvetoCubic) pathSeg;
        assertEquals(seg.getX(), seg2.getX(), 0.0001);
        assertEquals(seg.getY(), seg2.getY(), 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) SVGPathSegCurvetoCubic(net.sf.latexdraw.parsers.svg.path.SVGPathSegCurvetoCubic) Test(org.junit.Test)

Example 3 with SVGPathSegCurvetoCubic

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

the class SVGBezierCurve method getPathSegList.

/**
 * @return The SVG segment path list of the current Bézier curve.
 * @since 2.0.0
 */
protected SVGPathSegList getPathSegList() {
    if (shape.getNbPoints() < 2) {
        return null;
    }
    final int size = shape.getNbPoints();
    int i;
    final SVGPathSegList path = new SVGPathSegList();
    path.add(new SVGPathSegMoveto(shape.getPtAt(0).getX(), shape.getPtAt(0).getY(), false));
    path.add(new SVGPathSegCurvetoCubic(shape.getPtAt(1).getX(), shape.getPtAt(1).getY(), shape.getFirstCtrlPtAt(0).getX(), shape.getFirstCtrlPtAt(0).getY(), shape.getFirstCtrlPtAt(1).getX(), shape.getFirstCtrlPtAt(1).getY(), false));
    for (i = 2; i < size; i++) {
        path.add(new SVGPathSegCurvetoCubic(shape.getPtAt(i).getX(), shape.getPtAt(i).getY(), shape.getSecondCtrlPtAt(i - 1).getX(), shape.getSecondCtrlPtAt(i - 1).getY(), shape.getFirstCtrlPtAt(i).getX(), shape.getFirstCtrlPtAt(i).getY(), false));
    }
    if (!shape.isOpened()) {
        final IPoint ctrl1b = shape.getFirstCtrlPtAt(0).centralSymmetry(shape.getPtAt(0));
        final IPoint ctrl2b = shape.getFirstCtrlPtAt(-1).centralSymmetry(shape.getPtAt(-1));
        path.add(new SVGPathSegCurvetoCubic(shape.getPtAt(0).getX(), shape.getPtAt(0).getY(), ctrl2b.getX(), ctrl2b.getY(), ctrl1b.getX(), ctrl1b.getY(), false));
        path.add(new SVGPathSegClosePath());
    }
    return path;
}
Also used : SVGPathSegMoveto(net.sf.latexdraw.parsers.svg.path.SVGPathSegMoveto) SVGPathSegCurvetoCubic(net.sf.latexdraw.parsers.svg.path.SVGPathSegCurvetoCubic) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint) SVGPathSegList(net.sf.latexdraw.parsers.svg.path.SVGPathSegList) SVGPathSegClosePath(net.sf.latexdraw.parsers.svg.path.SVGPathSegClosePath) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint)

Example 4 with SVGPathSegCurvetoCubic

use of net.sf.latexdraw.parsers.svg.path.SVGPathSegCurvetoCubic 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 5 with SVGPathSegCurvetoCubic

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

the class SVGPathParser method parseCurveto.

/**
 * Parses an SVGPath curveto.
 * @param isRelative True if segment is relative.
 * @throws ParseException If a problem occurs.
 */
protected void parseCurveto(final boolean isRelative) throws ParseException {
    nextChar();
    skipWSP();
    do {
        final Tuple<Double, Double> p1 = parsePoint();
        skipWSPComma();
        final Tuple<Double, Double> p2 = parsePoint();
        skipWSPComma();
        final Tuple<Double, Double> p0 = parsePoint();
        skipWSPComma();
        handler.onPathSeg(new SVGPathSegCurvetoCubic(p0.a, p0.b, p1.a, p1.b, p2.a, p2.b, isRelative));
    } while (!isEOC() && isNumber(false));
}
Also used : SVGPathSegCurvetoCubic(net.sf.latexdraw.parsers.svg.path.SVGPathSegCurvetoCubic)

Aggregations

SVGPathSegCurvetoCubic (net.sf.latexdraw.parsers.svg.path.SVGPathSegCurvetoCubic)6 SVGPathSegMoveto (net.sf.latexdraw.parsers.svg.path.SVGPathSegMoveto)4 IPoint (net.sf.latexdraw.models.interfaces.shape.IPoint)2 SVGPathSegClosePath (net.sf.latexdraw.parsers.svg.path.SVGPathSegClosePath)2 SVGPathSegList (net.sf.latexdraw.parsers.svg.path.SVGPathSegList)2 SVGPathParser (net.sf.latexdraw.parsers.svg.parsers.SVGPathParser)1 SVGPathSegCurvetoCubicSmooth (net.sf.latexdraw.parsers.svg.path.SVGPathSegCurvetoCubicSmooth)1 SVGPathSegLineto (net.sf.latexdraw.parsers.svg.path.SVGPathSegLineto)1 Before (org.junit.Before)1 Test (org.junit.Test)1