Search in sources :

Example 6 with SVGPathSegMoveto

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

the class TestSVGPathSegLinetoVertical method testToString.

@Test
public void testToString() {
    final AtomicBoolean done = new AtomicBoolean(false);
    final SVGPathSegMoveto m = new SVGPathSegMoveto(0d, 0d, false);
    SVGParserUtils.INSTANCE.parseSVGPath(m.toString() + " " + seg.toString(), pathSeg -> {
        if (pathSeg instanceof SVGPathSegMoveto) {
            return;
        }
        done.set(true);
        final SVGPathSegLinetoVertical seg2 = (SVGPathSegLinetoVertical) pathSeg;
        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) SVGPathSegLinetoVertical(net.sf.latexdraw.parser.svg.path.SVGPathSegLinetoVertical) Test(org.junit.jupiter.api.Test)

Example 7 with SVGPathSegMoveto

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

the class SVGArrow method createMoveTo.

@Override
public void createMoveTo(final double x, final double y) {
    createPath();
    currentPath.add(new SVGPathSegMoveto(x, y, false));
}
Also used : SVGPathSegMoveto(net.sf.latexdraw.parser.svg.path.SVGPathSegMoveto)

Example 8 with SVGPathSegMoveto

use of net.sf.latexdraw.parser.svg.path.SVGPathSegMoveto 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 9 with SVGPathSegMoveto

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

Example 10 with SVGPathSegMoveto

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

the class SVGPathElement method isLines.

/**
 * @return True if the path is composed of lines and has a 'close path' segment at the end.
 */
public boolean isLines() {
    final SVGPathSegList segList = getSegList();
    if (segList.size() < 3 || !(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;
        }
    }
    return ok;
}
Also used : SVGPathSegMoveto(net.sf.latexdraw.parser.svg.path.SVGPathSegMoveto) SVGPathSegLineto(net.sf.latexdraw.parser.svg.path.SVGPathSegLineto) SVGPathSegList(net.sf.latexdraw.parser.svg.path.SVGPathSegList)

Aggregations

SVGPathSegMoveto (net.sf.latexdraw.parser.svg.path.SVGPathSegMoveto)18 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)9 Test (org.junit.jupiter.api.Test)9 SVGPathSegList (net.sf.latexdraw.parser.svg.path.SVGPathSegList)7 SVGPathSegClosePath (net.sf.latexdraw.parser.svg.path.SVGPathSegClosePath)5 SVGPathSegLineto (net.sf.latexdraw.parser.svg.path.SVGPathSegLineto)4 Point (net.sf.latexdraw.model.api.shape.Point)3 SVGPathSegArc (net.sf.latexdraw.parser.svg.path.SVGPathSegArc)3 SVGPathSegCurvetoCubic (net.sf.latexdraw.parser.svg.path.SVGPathSegCurvetoCubic)3 SVGPathElement (net.sf.latexdraw.parser.svg.SVGPathElement)2 SVGPathSegCurvetoCubicSmooth (net.sf.latexdraw.parser.svg.path.SVGPathSegCurvetoCubicSmooth)2 Point2D (java.awt.geom.Point2D)1 ArrayList (java.util.ArrayList)1 NoBadaboomCheck (net.sf.latexdraw.NoBadaboomCheck)1 ArcStyle (net.sf.latexdraw.model.api.shape.ArcStyle)1 BezierCurve (net.sf.latexdraw.model.api.shape.BezierCurve)1 SVGDefsElement (net.sf.latexdraw.parser.svg.SVGDefsElement)1 SVGElement (net.sf.latexdraw.parser.svg.SVGElement)1 SVGGElement (net.sf.latexdraw.parser.svg.SVGGElement)1 CtrlPointsSeg (net.sf.latexdraw.parser.svg.path.CtrlPointsSeg)1