Search in sources :

Example 1 with Point

use of net.sf.latexdraw.model.api.shape.Point in project latexdraw by arnobl.

the class Pencil method setInitialPtsShape.

/**
 * Companion function to the bindMultiClic2AddShape binding.
 * It initialises the first two points of the given shape.
 */
private Shape setInitialPtsShape(final Shape sh, final Point3D firstPt) {
    if (sh instanceof ModifiablePointsShape) {
        final ModifiablePointsShape modShape = (ModifiablePointsShape) sh;
        final Point pt = getAdaptedPoint(firstPt);
        modShape.setPoint(pt.getX(), pt.getY(), 0);
        modShape.setPoint(pt.getX() + 1d, pt.getY() + 1d, 1);
    }
    return sh;
}
Also used : ModifiablePointsShape(net.sf.latexdraw.model.api.shape.ModifiablePointsShape) Point(net.sf.latexdraw.model.api.shape.Point)

Example 2 with Point

use of net.sf.latexdraw.model.api.shape.Point 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<PointsData, AddShape> creation = i -> new AddShape(setInitialPtsShape(editing.createShapeInstance(), i.getPointsData().get(0).getSrcLocalPoint()), canvas.getDrawing());
    // Binding for polygons
    nodeBinder().usingInteraction(() -> new MultiClick(3)).toProduce(creation).on(canvas).then((i, c) -> {
        final Point currPoint = getAdaptedPoint(i.getCurrentPosition());
        if (c.getShape().getNbPoints() == i.getPointsData().size() && i.getLastButton().orElse(MouseButton.NONE) == MouseButton.PRIMARY) {
            c.setShape(ShapeFactory.INST.createPolygonFrom((Polygon) c.getShape(), ShapeFactory.INST.createPoint(currPoint.getX(), currPoint.getY())));
        } else {
            ((ModifiablePointsShape) c.getShape()).setPoint(currPoint.getX(), currPoint.getY(), -1);
        }
        canvas.setTempView(viewFactory.createView(c.getShape()).orElse(null));
    }).strictStart().endOrCancel(i -> canvas.setTempView(null)).when(() -> editing.getCurrentChoice() == EditionChoice.POLYGON).bind();
    // Binding for polyline
    nodeBinder().usingInteraction(MultiClick::new).toProduce(creation).on(canvas).then((i, c) -> {
        final Point currPoint = getAdaptedPoint(i.getCurrentPosition());
        if (c.getShape().getNbPoints() == i.getPointsData().size() && i.getLastButton().orElse(MouseButton.NONE) == MouseButton.PRIMARY) {
            c.setShape(ShapeFactory.INST.createPolylineFrom((Polyline) c.getShape(), ShapeFactory.INST.createPoint(currPoint.getX(), currPoint.getY())));
        } else {
            ((ModifiablePointsShape) c.getShape()).setPoint(currPoint.getX(), currPoint.getY(), -1);
        }
        canvas.setTempView(viewFactory.createView(c.getShape()).orElse(null));
    }).strictStart().endOrCancel(i -> canvas.setTempView(null)).when(() -> editing.getCurrentChoice() == EditionChoice.LINES).bind();
    // Binding for bézier curves
    nodeBinder().usingInteraction(MultiClick::new).toProduce(creation).on(canvas).then((i, c) -> {
        final Point currPoint = getAdaptedPoint(i.getCurrentPosition());
        if (c.getShape().getNbPoints() == i.getPointsData().size() && i.getLastButton().orElse(MouseButton.NONE) == MouseButton.PRIMARY) {
            c.setShape(ShapeFactory.INST.createBezierCurveFrom((BezierCurve) c.getShape(), ShapeFactory.INST.createPoint(currPoint.getX(), currPoint.getY())));
        } else {
            ((ModifiablePointsShape) c.getShape()).setPoint(currPoint.getX(), currPoint.getY(), -1);
        }
        ((ControlPointShape) c.getShape()).balance();
        canvas.setTempView(viewFactory.createView(c.getShape()).orElse(null));
    }).strictStart().endOrCancel(i -> canvas.setTempView(null)).when(() -> editing.getCurrentChoice() == EditionChoice.BEZIER_CURVE).bind();
}
Also used : EditingService(net.sf.latexdraw.service.EditingService) Arrays(java.util.Arrays) MouseButton(javafx.scene.input.MouseButton) ControlPointShape(net.sf.latexdraw.model.api.shape.ControlPointShape) BezierCurve(net.sf.latexdraw.model.api.shape.BezierCurve) Freehand(net.sf.latexdraw.model.api.shape.Freehand) Point3D(javafx.geometry.Point3D) BorderPos(net.sf.latexdraw.model.api.shape.BorderPos) InsertPicture(net.sf.latexdraw.command.shape.InsertPicture) Function(java.util.function.Function) Polyline(net.sf.latexdraw.model.api.shape.Polyline) ShapeFactory(net.sf.latexdraw.model.ShapeFactory) Shape(net.sf.latexdraw.model.api.shape.Shape) Inject(net.sf.latexdraw.util.Inject) PointsData(io.github.interacto.jfx.interaction.library.PointsData) MathUtils(net.sf.latexdraw.model.MathUtils) AddShape(net.sf.latexdraw.command.shape.AddShape) Canvas(net.sf.latexdraw.view.jfx.Canvas) ViewFactory(net.sf.latexdraw.view.jfx.ViewFactory) Click(io.github.interacto.jfx.interaction.library.Click) InitTextSetter(net.sf.latexdraw.command.shape.InitTextSetter) MultiClick(io.github.interacto.jfx.interaction.library.MultiClick) ModifiablePointsShape(net.sf.latexdraw.model.api.shape.ModifiablePointsShape) Polygon(net.sf.latexdraw.model.api.shape.Polygon) Press(io.github.interacto.jfx.interaction.library.Press) PositionShape(net.sf.latexdraw.model.api.shape.PositionShape) Point(net.sf.latexdraw.model.api.shape.Point) MagneticGrid(net.sf.latexdraw.view.jfx.MagneticGrid) Objects(java.util.Objects) FileChooser(javafx.stage.FileChooser) SquaredShape(net.sf.latexdraw.model.api.shape.SquaredShape) RectangularShape(net.sf.latexdraw.model.api.shape.RectangularShape) NotNull(org.jetbrains.annotations.NotNull) DnD(io.github.interacto.jfx.interaction.library.DnD) MultiClick(io.github.interacto.jfx.interaction.library.MultiClick) PointsData(io.github.interacto.jfx.interaction.library.PointsData) AddShape(net.sf.latexdraw.command.shape.AddShape) Polyline(net.sf.latexdraw.model.api.shape.Polyline) ModifiablePointsShape(net.sf.latexdraw.model.api.shape.ModifiablePointsShape) Point(net.sf.latexdraw.model.api.shape.Point) Polygon(net.sf.latexdraw.model.api.shape.Polygon) BezierCurve(net.sf.latexdraw.model.api.shape.BezierCurve) ControlPointShape(net.sf.latexdraw.model.api.shape.ControlPointShape)

Example 3 with Point

use of net.sf.latexdraw.model.api.shape.Point in project latexdraw by arnobl.

the class CtrlPointShapeBase method setPoint.

@Override
public boolean setPoint(final double x, final double y, final int position) {
    final Point pt = getPtAt(position);
    if (pt == null || !MathUtils.INST.isValidPt(x, y)) {
        return false;
    }
    final double tx = x - pt.getX();
    final double ty = y - pt.getY();
    getFirstCtrlPtAt(position).translate(tx, ty);
    getSecondCtrlPtAt(position).translate(tx, ty);
    super.setPoint(x, y, position);
    return true;
}
Also used : Point(net.sf.latexdraw.model.api.shape.Point)

Example 4 with Point

use of net.sf.latexdraw.model.api.shape.Point in project latexdraw by arnobl.

the class CtrlPointShapeBase method balance.

@Override
public void balance() {
    final int size = getNbPoints();
    // Works only with more than 2 points.
    if (size < 3) {
        return;
    }
    Point ptPrev;
    Point ptNext;
    // Balancing all the points except the first and the last one.
    for (int i = 1; i < size - 1; i++) {
        ptPrev = points.get(i - 1);
        ptNext = points.get(i + 1);
        setControlPoints(i, getBalancedPoints(points.get(i), ptPrev, ptNext));
    }
    // Balancing the first and the last points.
    ptPrev = points.get(size - 1);
    ptNext = points.get(1);
    setControlPoints(0, getBalancedPoints(points.get(0), ptPrev, ptNext));
    ptPrev = points.get(size - 2);
    ptNext = points.get(0);
    setControlPoints(size - 1, getBalancedPoints(points.get(size - 1), ptPrev, ptNext));
}
Also used : Point(net.sf.latexdraw.model.api.shape.Point) Point(net.sf.latexdraw.model.api.shape.Point)

Example 5 with Point

use of net.sf.latexdraw.model.api.shape.Point in project latexdraw by arnobl.

the class RectangularShapeBase method mirrorHorizontal.

@Override
public void mirrorHorizontal(final double x) {
    super.mirrorHorizontal(x);
    if (getWidth() < 0d) {
        final Point tmp = ShapeFactory.INST.createPoint(points.get(0));
        points.get(0).setPoint(points.get(1));
        points.get(1).setPoint(tmp);
        tmp.setPoint(points.get(2));
        points.get(2).setPoint(points.get(3));
        points.get(3).setPoint(tmp);
    }
}
Also used : Point(net.sf.latexdraw.model.api.shape.Point)

Aggregations

Point (net.sf.latexdraw.model.api.shape.Point)139 Test (org.junit.Test)52 HelperTest (net.sf.latexdraw.HelperTest)27 Theory (org.junit.experimental.theories.Theory)23 NotNull (org.jetbrains.annotations.NotNull)19 Line (net.sf.latexdraw.model.api.shape.Line)10 Shape (net.sf.latexdraw.model.api.shape.Shape)9 SVGElement (net.sf.latexdraw.parser.svg.SVGElement)9 SVGGElement (net.sf.latexdraw.parser.svg.SVGGElement)9 Test (org.junit.jupiter.api.Test)8 ArrayList (java.util.ArrayList)7 Polyline (net.sf.latexdraw.model.api.shape.Polyline)5 Color (javafx.scene.paint.Color)4 MathUtils (net.sf.latexdraw.model.MathUtils)4 ShapeFactory (net.sf.latexdraw.model.ShapeFactory)4 BezierCurve (net.sf.latexdraw.model.api.shape.BezierCurve)4 Canvas (net.sf.latexdraw.view.jfx.Canvas)4 Point2D (java.awt.geom.Point2D)3 List (java.util.List)3 ShapeData (net.sf.latexdraw.data.ShapeData)3