use of net.sf.latexdraw.model.api.shape.BezierCurve 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();
}
use of net.sf.latexdraw.model.api.shape.BezierCurve in project latexdraw by arnobl.
the class TestParsingPSbezier method testParamArrowsArrows.
@Test
public void testParamArrowsArrows() {
parser("\\psbezier[arrows=<->](1,2)(3,4)(5,6)(7,8)");
final BezierCurve bc = getShapeAt(0);
assertEquals(ArrowStyle.LEFT_ARROW, bc.getArrowStyle(0));
assertEquals(ArrowStyle.RIGHT_ARROW, bc.getArrowStyle(1));
}
use of net.sf.latexdraw.model.api.shape.BezierCurve in project latexdraw by arnobl.
the class TestParsingPSbezier method testSimpleBezierCurveOpen.
@Test
public void testSimpleBezierCurveOpen() {
parser("\\psbezier[linecolor=black, linewidth=0.04](0.014142151,-1.4747834)(0.7212489,-2.1818902)(4.9070354,-1.3818903)(5.614142," + "-0.6747834777832031)(6.321249,0.032323305)(4.2040915,1.8666378)(3.214142,1.7252165)");
final BezierCurve bc = getShapeAt(0);
assertTrue(bc.isOpened());
}
use of net.sf.latexdraw.model.api.shape.BezierCurve in project latexdraw by arnobl.
the class TestParsingPSbezier method testParse10Coordinates.
@Test
public void testParse10Coordinates() {
parser("\\psbezier(5,10)(1,2)(3,4)(5,6)(7,8)(9,10)(11,12)(13,14)(15,16)(17,18)");
final BezierCurve bc = getShapeAt(0);
assertEquals(4, bc.getNbPoints());
assertEquals(5d * Shape.PPC, bc.getPtAt(0).getX(), 0.0001);
assertEquals(-10d * Shape.PPC, bc.getPtAt(0).getY(), 0.0001);
assertEquals(5d * Shape.PPC, bc.getPtAt(1).getX(), 0.0001);
assertEquals(-6d * Shape.PPC, bc.getPtAt(1).getY(), 0.0001);
assertEquals(11d * Shape.PPC, bc.getPtAt(2).getX(), 0.0001);
assertEquals(-12d * Shape.PPC, bc.getPtAt(2).getY(), 0.0001);
assertEquals(17d * Shape.PPC, bc.getPtAt(3).getX(), 0.0001);
assertEquals(-18d * Shape.PPC, bc.getPtAt(3).getY(), 0.0001);
assertEquals(9d * Shape.PPC, bc.getSecondCtrlPtAt(0).getX(), 0.0001);
assertEquals(-18d * Shape.PPC, bc.getSecondCtrlPtAt(0).getY(), 0.0001);
assertEquals(7d * Shape.PPC, bc.getSecondCtrlPtAt(1).getX(), 0.0001);
assertEquals(-8d * Shape.PPC, bc.getSecondCtrlPtAt(1).getY(), 0.0001);
assertEquals(13d * Shape.PPC, bc.getSecondCtrlPtAt(2).getX(), 0.0001);
assertEquals(-14d * Shape.PPC, bc.getSecondCtrlPtAt(2).getY(), 0.0001);
assertEquals(3d * Shape.PPC, bc.getFirstCtrlPtAt(1).getX(), 0.0001);
assertEquals(-4d * Shape.PPC, bc.getFirstCtrlPtAt(1).getY(), 0.0001);
assertEquals(9d * Shape.PPC, bc.getFirstCtrlPtAt(2).getX(), 0.0001);
assertEquals(-10d * Shape.PPC, bc.getFirstCtrlPtAt(2).getY(), 0.0001);
assertEquals(15d * Shape.PPC, bc.getFirstCtrlPtAt(3).getX(), 0.0001);
assertEquals(-16d * Shape.PPC, bc.getFirstCtrlPtAt(3).getY(), 0.0001);
}
use of net.sf.latexdraw.model.api.shape.BezierCurve in project latexdraw by arnobl.
the class TestParsingPSbezier method testSimpleBezierCurve.
@Test
public void testSimpleBezierCurve() {
parser("\\psbezier[linewidth=0.02](1.3918242,0.7584497)(2.0668242,0.95844966)(4.3168244,0.95844966)(4.991824,0.7584497)");
final BezierCurve bc = getShapeAt(0);
assertEquals(bc.getPtAt(0).getY(), bc.getPtAt(1).getY(), 0.001);
assertEquals(bc.getFirstCtrlPtAt(0).getY(), bc.getFirstCtrlPtAt(1).getY(), 0.001);
assertFalse(bc.isFilled());
}
Aggregations