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