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));
}
}
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));
}
}
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;
}
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);
}
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();
}
Aggregations