Search in sources :

Example 71 with Point

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

the class TestCanvasTranslation method testTranslateAbortOK.

@Test
public void testTranslateAbortOK() {
    Cmds.of(addRec).execute();
    final Point tl = canvas.getDrawing().getShapeAt(0).orElseThrow().getTopLeftPoint();
    Cmds.of(() -> drag(canvas.getViews().getChildren().get(0)), () -> moveBy(100d, 200d).type(KeyCode.ESCAPE)).execute();
    assertEquals(tl, canvas.getDrawing().getShapeAt(0).orElseThrow().getTopLeftPoint());
}
Also used : Point(net.sf.latexdraw.model.api.shape.Point) Test(org.junit.Test)

Example 72 with Point

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

the class TestCanvasTranslation method testTranslateCorrectSelectedShape.

@Test
public void testTranslateCorrectSelectedShape() {
    Cmds.of(addRec, addRec2, CmdFXVoid.of(() -> canvas.getDrawing().getShapes().forEach(sh -> sh.setFilled(true)))).execute();
    final Point tl1 = canvas.getDrawing().getShapeAt(0).orElseThrow().getTopLeftPoint();
    final Point tl2 = canvas.getDrawing().getShapeAt(1).orElseThrow().getTopLeftPoint();
    Cmds.of(() -> clickOn(canvas.getViews().getChildren().get(0)), () -> drag(canvas.getViews().getChildren().get(1)), () -> dropBy(100d, 200d)).execute();
    assertEquals(tl1, canvas.getDrawing().getShapeAt(0).orElseThrow().getTopLeftPoint());
    assertEquals(tl2.getX() + 100d, canvas.getDrawing().getShapeAt(1).orElseThrow().getTopLeftPoint().getX(), 1d);
    assertEquals(tl2.getY() + 200d, canvas.getDrawing().getShapeAt(1).orElseThrow().getTopLeftPoint().getY(), 1d);
}
Also used : KeyCode(javafx.scene.input.KeyCode) Color(javafx.scene.paint.Color) ShapeSupplier(net.sf.latexdraw.data.ShapeSupplier) Injector(net.sf.latexdraw.util.Injector) ShapeData(net.sf.latexdraw.data.ShapeData) RunWith(org.junit.runner.RunWith) Test(org.junit.Test) Picture(net.sf.latexdraw.model.api.shape.Picture) Mockito.when(org.mockito.Mockito.when) Point(net.sf.latexdraw.model.api.shape.Point) InvocationTargetException(java.lang.reflect.InvocationTargetException) WaitForAsyncUtils(org.testfx.util.WaitForAsyncUtils) Mockito(org.mockito.Mockito) List(java.util.List) Shape(net.sf.latexdraw.model.api.shape.Shape) Stage(javafx.stage.Stage) Theories(org.junit.experimental.theories.Theories) Point2D(javafx.geometry.Point2D) Canvas(net.sf.latexdraw.view.jfx.Canvas) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) Theory(org.junit.experimental.theories.Theory) Point(net.sf.latexdraw.model.api.shape.Point) Test(org.junit.Test)

Example 73 with Point

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

the class InsertPSTCode method doCmdBody.

@Override
protected void doCmdBody() {
    final PSTLatexdrawListener listener = new PSTLatexdrawListener();
    final PSTLexer lexer = new PSTLexer(CharStreams.fromString(code));
    final PSTParser parser = new PSTParser(new CommonTokenStream(lexer));
    parser.addParseListener(listener);
    parser.pstCode(new PSTContext());
    final Group group = ShapeFactory.INST.createGroup();
    group.getShapes().addAll(listener.flatShapes());
    if (!group.isEmpty()) {
        final Shape sh = group.size() > 1 ? group : group.getShapeAt(0).orElseThrow();
        final Point tl = sh.getTopLeftPoint();
        final double tx = tl.getX() < 0d ? -tl.getX() + 50d : 0d;
        final double ty = tl.getY() < 0d ? -tl.getY() + 50d : 0d;
        shapes = Optional.of(sh);
        sh.translate(tx, ty);
        redo();
        statusBar.setText(lang.getString("codeConverted"));
    }
    parser.getInterpreter().clearDFA();
    lexer.getInterpreter().clearDFA();
}
Also used : CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) Group(net.sf.latexdraw.model.api.shape.Group) PSTLexer(net.sf.latexdraw.parser.pst.PSTLexer) Shape(net.sf.latexdraw.model.api.shape.Shape) PSTLatexdrawListener(net.sf.latexdraw.parser.pst.PSTLatexdrawListener) PSTContext(net.sf.latexdraw.parser.pst.PSTContext) Point(net.sf.latexdraw.model.api.shape.Point) PSTParser(net.sf.latexdraw.parser.pst.PSTParser)

Example 74 with Point

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

the class MoveCtrlPoint method move.

private void move(@NotNull final Point firstPt, @NotNull final Point sndPt) {
    final int indexPt = getIndexCtrlPt();
    shape.setXFirstCtrlPt(firstPt.getX(), indexPt);
    shape.setYFirstCtrlPt(firstPt.getY(), indexPt);
    shape.setXSecondCtrlPt(sndPt.getX(), indexPt);
    shape.setYSecondCtrlPt(sndPt.getY(), indexPt);
    shape.setModified(true);
}
Also used : Point(net.sf.latexdraw.model.api.shape.Point)

Example 75 with Point

use of net.sf.latexdraw.model.api.shape.Point 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)

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