Search in sources :

Example 1 with SVGPathSegCurvetoCubic

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

the class TestSVGPathSegCurvetoCubic method testToString.

@Test
void testToString() {
    final AtomicBoolean done = new AtomicBoolean(false);
    final SVGPathSegMoveto m = new SVGPathSegMoveto(0, 0, false);
    SVGParserUtils.INSTANCE.parseSVGPath(m.toString() + " " + seg.toString(), pathSeg -> {
        if (pathSeg instanceof SVGPathSegMoveto) {
            return;
        }
        done.set(true);
        final SVGPathSegCurvetoCubic seg2 = (SVGPathSegCurvetoCubic) pathSeg;
        assertEquals(seg.getX(), seg2.getX(), 0.0001);
        assertEquals(seg.getY(), seg2.getY(), 0.0001);
        assertEquals(seg.isRelative(), seg2.isRelative());
    });
    assertTrue(done.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SVGPathSegMoveto(net.sf.latexdraw.parser.svg.path.SVGPathSegMoveto) SVGPathSegCurvetoCubic(net.sf.latexdraw.parser.svg.path.SVGPathSegCurvetoCubic) Test(org.junit.jupiter.api.Test)

Example 2 with SVGPathSegCurvetoCubic

use of net.sf.latexdraw.parser.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.
 */
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 Point ctrl1b = shape.getFirstCtrlPtAt(0).centralSymmetry(shape.getPtAt(0));
        final Point 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.parser.svg.path.SVGPathSegMoveto) SVGPathSegCurvetoCubic(net.sf.latexdraw.parser.svg.path.SVGPathSegCurvetoCubic) Point(net.sf.latexdraw.model.api.shape.Point) SVGPathSegList(net.sf.latexdraw.parser.svg.path.SVGPathSegList) SVGPathSegClosePath(net.sf.latexdraw.parser.svg.path.SVGPathSegClosePath) Point(net.sf.latexdraw.model.api.shape.Point)

Example 3 with SVGPathSegCurvetoCubic

use of net.sf.latexdraw.parser.svg.path.SVGPathSegCurvetoCubic 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.parser.svg.path.SVGPathSegCurvetoCubicSmooth) SVGPathSegMoveto(net.sf.latexdraw.parser.svg.path.SVGPathSegMoveto) SVGPathSegCurvetoCubic(net.sf.latexdraw.parser.svg.path.SVGPathSegCurvetoCubic) SVGPathSegList(net.sf.latexdraw.parser.svg.path.SVGPathSegList) SVGPathSegClosePath(net.sf.latexdraw.parser.svg.path.SVGPathSegClosePath)

Aggregations

SVGPathSegCurvetoCubic (net.sf.latexdraw.parser.svg.path.SVGPathSegCurvetoCubic)3 SVGPathSegMoveto (net.sf.latexdraw.parser.svg.path.SVGPathSegMoveto)3 SVGPathSegClosePath (net.sf.latexdraw.parser.svg.path.SVGPathSegClosePath)2 SVGPathSegList (net.sf.latexdraw.parser.svg.path.SVGPathSegList)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Point (net.sf.latexdraw.model.api.shape.Point)1 SVGPathSegCurvetoCubicSmooth (net.sf.latexdraw.parser.svg.path.SVGPathSegCurvetoCubicSmooth)1 Test (org.junit.jupiter.api.Test)1