use of net.sf.latexdraw.model.api.shape.BezierCurve in project latexdraw by arnobl.
the class TestShapeFactory method testCreateBezierCurveFromSameNewCtrlPoint.
@Test
void testCreateBezierCurveFromSameNewCtrlPoint() {
BezierCurve bc = ShapeFactory.INST.createBezierCurve(Collections.singletonList(ShapeFactory.INST.createPoint()));
bc = ShapeFactory.INST.createBezierCurveFrom(bc, ShapeFactory.INST.createPoint(1d, 2d));
assertEqualsDouble(1d, bc.getFirstCtrlPtAt(1).getX());
assertEqualsDouble(2d + BezierCurve.DEFAULT_POSITION_CTRL, bc.getFirstCtrlPtAt(1).getY());
}
use of net.sf.latexdraw.model.api.shape.BezierCurve in project latexdraw by arnobl.
the class TestPSTShape method testLoadRotationAngleParams.
@Override
@ParameterizedTest
@MethodSource("net.sf.latexdraw.data.ShapeSupplier#getDiversifiedShapes")
public void testLoadRotationAngleParams(final Shape sh) {
assumeFalse(sh instanceof Polygon || sh instanceof BezierCurve);
final Shape s2 = produceOutputShapeFrom(sh);
CompareShapeMatcher.INST.assertEqualShapeRotationAngle(sh, s2);
}
use of net.sf.latexdraw.model.api.shape.BezierCurve in project latexdraw by arnobl.
the class TestCanvasCreation method testDrawBezierCurve.
@Test
public void testDrawBezierCurve() {
final Point2D pos = point(canvas).query();
Cmds.of(CmdFXVoid.of(() -> editing.setCurrentChoice(EditionChoice.BEZIER_CURVE)), () -> moveTo(pos).clickOn(MouseButton.PRIMARY).moveBy(-20d, -100d).clickOn(MouseButton.PRIMARY).moveBy(-100d, 50d).clickOn(MouseButton.SECONDARY)).execute();
assertEquals(1, drawing.size());
assertTrue(drawing.getShapeAt(0).orElseThrow() instanceof BezierCurve);
final BezierCurve sh = (BezierCurve) drawing.getShapeAt(0).orElseThrow();
assertEquals(-Canvas.getMargins() + canvas.screenToLocal(pos).getX(), sh.getPtAt(0).getX(), 1d);
assertEquals(-Canvas.getMargins() + canvas.screenToLocal(pos).getY(), sh.getPtAt(0).getY(), 1d);
assertTrue(sh.isOpened());
assertEquals(3, sh.getNbPoints());
}
use of net.sf.latexdraw.model.api.shape.BezierCurve in project latexdraw by arnobl.
the class PlotViewComputation method updateCurve.
default BezierCurve updateCurve(final Plot shape, final double posX, final double posY, final double minX, final double maxX, final double step) {
// The algorithm follows this definition:
// https://stackoverflow.com/questions/15864441/how-to-make-a-line-curve-through-points
final double scale = 0.33d;
final BezierCurve bc = ShapeFactory.INST.createBezierCurve(fillPoints(shape, posX, posY, minX, maxX, step));
bc.setOpened(shape.getPlotStyle() != PlotStyle.CCURVE);
bc.copy(shape);
int i = 0;
final int last = bc.getPoints().size() - 1;
for (final Point pt : bc.getPoints()) {
if (i == 0) {
final Point p2 = bc.getPtAt(i + 1);
final Point tangent = p2.substract(pt);
final Point q1 = pt.add(tangent.zoom(scale));
bc.setXFirstCtrlPt(q1.getX(), i);
bc.setYFirstCtrlPt(q1.getY(), i);
} else if (i == last) {
final Point p0 = bc.getPtAt(i - 1);
final Point tangent = pt.substract(p0);
final Point q0 = pt.substract(tangent.zoom(scale));
bc.setXFirstCtrlPt(q0.getX(), i);
bc.setYFirstCtrlPt(q0.getY(), i);
} else {
final Point p0 = bc.getPtAt(i - 1);
final Point p2 = bc.getPtAt(i + 1);
final Point tangent = p2.substract(p0).normalise();
final Point q0 = pt.substract(tangent.zoom(scale * pt.substract(p0).magnitude()));
bc.setXFirstCtrlPt(q0.getX(), i);
bc.setYFirstCtrlPt(q0.getY(), i);
}
i++;
}
bc.updateSecondControlPoints();
return bc;
}
use of net.sf.latexdraw.model.api.shape.BezierCurve in project latexdraw by arnobl.
the class ShapeFactoryImpl method createBezierCurveFrom.
@Override
@NotNull
public BezierCurve createBezierCurveFrom(final BezierCurve bc, final Point pointToAdd) {
if (bc == null || !MathUtils.INST.isValidPt(pointToAdd)) {
throw new IllegalArgumentException();
}
final List<Point> pts = new ArrayList<>(bc.getPoints());
final List<Point> ptsCtrl = new ArrayList<>(bc.getFirstCtrlPts());
pts.add(pointToAdd);
ptsCtrl.add(createPoint(pointToAdd.getX(), pointToAdd.getY() + BezierCurve.DEFAULT_POSITION_CTRL));
final BezierCurve copy = new BezierCurveImpl(pts, ptsCtrl);
copy.copy(bc);
return copy;
}
Aggregations