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());
}
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);
}
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();
}
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);
}
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;
}
Aggregations