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