Search in sources :

Example 11 with BezierCurve

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());
}
Also used : BezierCurve(net.sf.latexdraw.model.api.shape.BezierCurve) Test(org.junit.jupiter.api.Test) HelperTest(net.sf.latexdraw.HelperTest)

Example 12 with BezierCurve

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);
}
Also used : Shape(net.sf.latexdraw.model.api.shape.Shape) Polygon(net.sf.latexdraw.model.api.shape.Polygon) BezierCurve(net.sf.latexdraw.model.api.shape.BezierCurve) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 13 with BezierCurve

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());
}
Also used : Point2D(javafx.geometry.Point2D) BezierCurve(net.sf.latexdraw.model.api.shape.BezierCurve) Test(org.junit.Test)

Example 14 with BezierCurve

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;
}
Also used : Point(net.sf.latexdraw.model.api.shape.Point) BezierCurve(net.sf.latexdraw.model.api.shape.BezierCurve) Point(net.sf.latexdraw.model.api.shape.Point)

Example 15 with BezierCurve

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;
}
Also used : ArrayList(java.util.ArrayList) Point(net.sf.latexdraw.model.api.shape.Point) BezierCurve(net.sf.latexdraw.model.api.shape.BezierCurve) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

BezierCurve (net.sf.latexdraw.model.api.shape.BezierCurve)26 Test (org.junit.jupiter.api.Test)16 HelperTest (net.sf.latexdraw.HelperTest)6 Point (net.sf.latexdraw.model.api.shape.Point)4 Test (org.junit.Test)4 Polygon (net.sf.latexdraw.model.api.shape.Polygon)3 ArrayList (java.util.ArrayList)2 Freehand (net.sf.latexdraw.model.api.shape.Freehand)2 Polyline (net.sf.latexdraw.model.api.shape.Polyline)2 Shape (net.sf.latexdraw.model.api.shape.Shape)2 NotNull (org.jetbrains.annotations.NotNull)2 Click (io.github.interacto.jfx.interaction.library.Click)1 DnD (io.github.interacto.jfx.interaction.library.DnD)1 MultiClick (io.github.interacto.jfx.interaction.library.MultiClick)1 PointsData (io.github.interacto.jfx.interaction.library.PointsData)1 Press (io.github.interacto.jfx.interaction.library.Press)1 Point2D (java.awt.geom.Point2D)1 Arrays (java.util.Arrays)1 Objects (java.util.Objects)1 Function (java.util.function.Function)1