Search in sources :

Example 21 with IBezierCurve

use of net.sf.latexdraw.models.interfaces.shape.IBezierCurve in project latexdraw by arnobl.

the class LBezierCurve method duplicate.

@Override
public IBezierCurve duplicate() {
    final IBezierCurve dup = ShapeFactory.INST.createBezierCurve(points, firstCtrlPts);
    dup.copy(this);
    return dup;
}
Also used : IBezierCurve(net.sf.latexdraw.models.interfaces.shape.IBezierCurve)

Example 22 with IBezierCurve

use of net.sf.latexdraw.models.interfaces.shape.IBezierCurve in project latexdraw by arnobl.

the class Pencil method bindMultiClic2AddShape.

/**
 * Binds a multi-click interaction to creates multi-point shapes.
 */
private void bindMultiClic2AddShape() {
    final Function<MultiClick, AddShape> creation = i -> new AddShape(setInitialPtsShape(createShapeInstance(), i.getPoints().get(0)), canvas.getDrawing());
    // Binding for polygons
    nodeBinder(AddShape.class, new MultiClick(3)).on(canvas).map(creation).then((c, i) -> {
        final IPoint currPoint = getAdaptedPoint(i.getCurrentPosition());
        if (c.getShape().get().getNbPoints() == i.getPoints().size() && i.getCurrentButton() == MouseButton.PRIMARY) {
            c.setShape(ShapeFactory.INST.createPolygonFrom((IPolygon) c.getShape().get(), ShapeFactory.INST.createPoint(currPoint.getX(), currPoint.getY())));
        } else {
            ((IModifiablePointsShape) c.getShape().get()).setPoint(currPoint.getX(), currPoint.getY(), -1);
        }
        canvas.setTempView(ViewFactory.INSTANCE.createView(c.getShape().orElse(null)).orElse(null));
    }).endOrCancel((c, i) -> canvas.setTempView(null)).bind().activationProperty().bind(currentChoice.isEqualTo(EditionChoice.POLYGON).and(activatedProp));
    // Binding for polyline
    nodeBinder(AddShape.class, new MultiClick()).on(canvas).map(creation).then((c, i) -> {
        final IPoint currPoint = getAdaptedPoint(i.getCurrentPosition());
        if (c.getShape().get().getNbPoints() == i.getPoints().size() && i.getCurrentButton() == MouseButton.PRIMARY) {
            c.setShape(ShapeFactory.INST.createPolylineFrom((IPolyline) c.getShape().get(), ShapeFactory.INST.createPoint(currPoint.getX(), currPoint.getY())));
        } else {
            ((IModifiablePointsShape) c.getShape().get()).setPoint(currPoint.getX(), currPoint.getY(), -1);
        }
        canvas.setTempView(ViewFactory.INSTANCE.createView(c.getShape().orElse(null)).orElse(null));
    }).endOrCancel((c, i) -> canvas.setTempView(null)).bind().activationProperty().bind(currentChoice.isEqualTo(EditionChoice.LINES).and(activatedProp));
    // Binding for bézier curves
    nodeBinder(AddShape.class, new MultiClick()).on(canvas).map(creation).then((c, i) -> {
        final IPoint currPoint = getAdaptedPoint(i.getCurrentPosition());
        if (c.getShape().get().getNbPoints() == i.getPoints().size() && i.getCurrentButton() == MouseButton.PRIMARY) {
            c.setShape(ShapeFactory.INST.createBezierCurveFrom((IBezierCurve) c.getShape().get(), ShapeFactory.INST.createPoint(currPoint.getX(), currPoint.getY())));
        } else {
            ((IModifiablePointsShape) c.getShape().get()).setPoint(currPoint.getX(), currPoint.getY(), -1);
        }
        ((IControlPointShape) c.getShape().get()).balance();
        canvas.setTempView(ViewFactory.INSTANCE.createView(c.getShape().orElse(null)).orElse(null));
    }).endOrCancel((c, i) -> canvas.setTempView(null)).bind().activationProperty().bind(currentChoice.isEqualTo(EditionChoice.BEZIER_CURVE).and(activatedProp));
}
Also used : MultiClick(org.malai.javafx.interaction.library.MultiClick) ISquaredShape(net.sf.latexdraw.models.interfaces.shape.ISquaredShape) Arrays(java.util.Arrays) MouseButton(javafx.scene.input.MouseButton) IPositionShape(net.sf.latexdraw.models.interfaces.shape.IPositionShape) Point3D(javafx.geometry.Point3D) ShapeFactory(net.sf.latexdraw.models.ShapeFactory) IRectangularShape(net.sf.latexdraw.models.interfaces.shape.IRectangularShape) MathUtils(net.sf.latexdraw.models.MathUtils) AddShape(net.sf.latexdraw.commands.shape.AddShape) Function(java.util.function.Function) BorderPos(net.sf.latexdraw.models.interfaces.shape.BorderPos) Inject(net.sf.latexdraw.util.Inject) IShape(net.sf.latexdraw.models.interfaces.shape.IShape) InsertPicture(net.sf.latexdraw.commands.shape.InsertPicture) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint) DnD(org.malai.javafx.interaction.library.DnD) IFreehand(net.sf.latexdraw.models.interfaces.shape.IFreehand) ObjectProperty(javafx.beans.property.ObjectProperty) ViewFactory(net.sf.latexdraw.view.jfx.ViewFactory) IControlPointShape(net.sf.latexdraw.models.interfaces.shape.IControlPointShape) IPolygon(net.sf.latexdraw.models.interfaces.shape.IPolygon) IPolyline(net.sf.latexdraw.models.interfaces.shape.IPolyline) LangTool(net.sf.latexdraw.util.LangTool) IGroup(net.sf.latexdraw.models.interfaces.shape.IGroup) IBezierCurve(net.sf.latexdraw.models.interfaces.shape.IBezierCurve) InitTextSetter(net.sf.latexdraw.commands.shape.InitTextSetter) MultiClick(org.malai.javafx.interaction.library.MultiClick) Platform(javafx.application.Platform) Cursor(javafx.scene.Cursor) FileChooser(javafx.stage.FileChooser) IModifiablePointsShape(net.sf.latexdraw.models.interfaces.shape.IModifiablePointsShape) Press(org.malai.javafx.interaction.library.Press) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) Collections(java.util.Collections) AddShape(net.sf.latexdraw.commands.shape.AddShape) IModifiablePointsShape(net.sf.latexdraw.models.interfaces.shape.IModifiablePointsShape) IBezierCurve(net.sf.latexdraw.models.interfaces.shape.IBezierCurve) IPolyline(net.sf.latexdraw.models.interfaces.shape.IPolyline) IControlPointShape(net.sf.latexdraw.models.interfaces.shape.IControlPointShape) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint) IPolygon(net.sf.latexdraw.models.interfaces.shape.IPolygon)

Example 23 with IBezierCurve

use of net.sf.latexdraw.models.interfaces.shape.IBezierCurve in project latexdraw by arnobl.

the class TestParsingPSbezier method testParse3Coordinates.

@Test
public void testParse3Coordinates() {
    parser("\\psbezier(1,2)(3,4)(5,6)");
    final IBezierCurve bc = getShapeAt(0);
    assertEquals(2, bc.getNbPoints());
    assertEquals(0d, bc.getPtAt(0).getX(), 0.0001);
    assertEquals(0d, bc.getPtAt(0).getY(), 0.0001);
    assertEquals(5d * IShape.PPC, bc.getPtAt(1).getX(), 0.0001);
    assertEquals(-6d * IShape.PPC, bc.getPtAt(1).getY(), 0.0001);
    assertEquals(-1d * IShape.PPC, bc.getSecondCtrlPtAt(0).getX(), 0.0001);
    assertEquals(2d * IShape.PPC, bc.getSecondCtrlPtAt(0).getY(), 0.0001);
    assertEquals(3d * IShape.PPC, bc.getFirstCtrlPtAt(1).getX(), 0.0001);
    assertEquals(-4d * IShape.PPC, bc.getFirstCtrlPtAt(1).getY(), 0.0001);
}
Also used : IBezierCurve(net.sf.latexdraw.models.interfaces.shape.IBezierCurve) Test(org.junit.Test)

Example 24 with IBezierCurve

use of net.sf.latexdraw.models.interfaces.shape.IBezierCurve in project latexdraw by arnobl.

the class TestParsingPSbezier method testShowPoints.

@Test
public void testShowPoints() {
    parser("\\psbezier[showpoints=true](5,10)(1,2)(3,4)(5,6)");
    final IBezierCurve bc = getShapeAt(0);
    assertTrue(bc.isShowPts());
}
Also used : IBezierCurve(net.sf.latexdraw.models.interfaces.shape.IBezierCurve) Test(org.junit.Test)

Example 25 with IBezierCurve

use of net.sf.latexdraw.models.interfaces.shape.IBezierCurve in project latexdraw by arnobl.

the class TestParsingPSbezier method testParse6Coordinates.

@Test
public void testParse6Coordinates() {
    parser("\\psbezier(1,2)(3,4)(5,6)(7,8)(9,10)(11,12)");
    final IBezierCurve bc = getShapeAt(0);
    assertEquals(3, bc.getNbPoints());
    assertEquals(0d, bc.getPtAt(0).getX(), 0.0001);
    assertEquals(0d, bc.getPtAt(0).getY(), 0.0001);
    assertEquals(5d * IShape.PPC, bc.getPtAt(1).getX(), 0.0001);
    assertEquals(-6d * IShape.PPC, bc.getPtAt(1).getY(), 0.0001);
    assertEquals(11d * IShape.PPC, bc.getPtAt(2).getX(), 0.0001);
    assertEquals(-12d * IShape.PPC, bc.getPtAt(2).getY(), 0.0001);
    assertEquals(-1d * IShape.PPC, bc.getSecondCtrlPtAt(0).getX(), 0.0001);
    assertEquals(2d * IShape.PPC, bc.getSecondCtrlPtAt(0).getY(), 0.0001);
    assertEquals(7d * IShape.PPC, bc.getSecondCtrlPtAt(1).getX(), 0.0001);
    assertEquals(-8d * IShape.PPC, bc.getSecondCtrlPtAt(1).getY(), 0.0001);
    assertEquals(3d * IShape.PPC, bc.getFirstCtrlPtAt(1).getX(), 0.0001);
    assertEquals(-4d * IShape.PPC, bc.getFirstCtrlPtAt(1).getY(), 0.0001);
    assertEquals(9d * IShape.PPC, bc.getFirstCtrlPtAt(2).getX(), 0.0001);
    assertEquals(-10d * IShape.PPC, bc.getFirstCtrlPtAt(2).getY(), 0.0001);
}
Also used : IBezierCurve(net.sf.latexdraw.models.interfaces.shape.IBezierCurve) Test(org.junit.Test)

Aggregations

IBezierCurve (net.sf.latexdraw.models.interfaces.shape.IBezierCurve)28 Test (org.junit.Test)20 HelperTest (net.sf.latexdraw.HelperTest)6 IPoint (net.sf.latexdraw.models.interfaces.shape.IPoint)5 IFreehand (net.sf.latexdraw.models.interfaces.shape.IFreehand)3 IPolygon (net.sf.latexdraw.models.interfaces.shape.IPolygon)3 IPolyline (net.sf.latexdraw.models.interfaces.shape.IPolyline)3 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2 Point2D (javafx.geometry.Point2D)2 MathUtils (net.sf.latexdraw.models.MathUtils)2 ShapeFactory (net.sf.latexdraw.models.ShapeFactory)2 BorderPos (net.sf.latexdraw.models.interfaces.shape.BorderPos)2 IAxes (net.sf.latexdraw.models.interfaces.shape.IAxes)2 ICircle (net.sf.latexdraw.models.interfaces.shape.ICircle)2 ICircleArc (net.sf.latexdraw.models.interfaces.shape.ICircleArc)2 IDot (net.sf.latexdraw.models.interfaces.shape.IDot)2 IEllipse (net.sf.latexdraw.models.interfaces.shape.IEllipse)2 IGrid (net.sf.latexdraw.models.interfaces.shape.IGrid)2