use of net.sf.latexdraw.model.api.shape.Polygon 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.Polygon in project latexdraw by arnobl.
the class PolygonImpl method duplicate.
@Override
@NotNull
public Polygon duplicate() {
final Polygon dup = ShapeFactory.INST.createPolygon(points);
dup.copy(this);
return dup;
}
use of net.sf.latexdraw.model.api.shape.Polygon in project latexdraw by arnobl.
the class TestParsingPspolygon method testCoordinatesMm.
@Test
public void testCoordinatesMm() {
parser("\\pspolygon(350mm,200mm)(10mm, 30.3mm)(-10mm, -30.3mm)");
final Polygon line = getShapeAt(0);
assertEquals(3, line.getNbPoints());
assertEquals(35d * Shape.PPC, line.getPtAt(0).getX(), 0.0001);
assertEquals(-20d * Shape.PPC, line.getPtAt(0).getY(), 0.0001);
assertEquals(1d * Shape.PPC, line.getPtAt(1).getX(), 0.0001);
assertEquals(-3.03 * Shape.PPC, line.getPtAt(1).getY(), 0.0001);
assertEquals(-1d * Shape.PPC, line.getPtAt(2).getX(), 0.0001);
assertEquals(3.03 * Shape.PPC, line.getPtAt(2).getY(), 0.0001);
}
use of net.sf.latexdraw.model.api.shape.Polygon in project latexdraw by arnobl.
the class TestParsingPspolygon method testCoordinatesInch.
@Test
public void testCoordinatesInch() {
parser("\\pspolygon(35in,20in)(1.2in,0.2in)(-1.2in,-0.2in)");
final Polygon line = getShapeAt(0);
assertEquals(3, line.getNbPoints());
assertEquals(35d * Shape.PPC / 2.54, line.getPtAt(0).getX(), 0.0001);
assertEquals(-20d * Shape.PPC / 2.54, line.getPtAt(0).getY(), 0.0001);
assertEquals(1.2 * Shape.PPC / 2.54, line.getPtAt(1).getX(), 0.0001);
assertEquals(-0.2 * Shape.PPC / 2.54, line.getPtAt(1).getY(), 0.0001);
assertEquals(-1.2 * Shape.PPC / 2.54, line.getPtAt(2).getX(), 0.0001);
assertEquals(0.2 * Shape.PPC / 2.54, line.getPtAt(2).getY(), 0.0001);
}
use of net.sf.latexdraw.model.api.shape.Polygon in project latexdraw by arnobl.
the class TestParsingPspolygon method testCoordinatesCm.
@Test
public void testCoordinatesCm() {
parser("\\pspolygon(35cm,20cm)(1.2cm,2cm)(-1.2cm,-2cm)");
final Polygon line = getShapeAt(0);
assertEquals(3, line.getNbPoints());
assertEquals(35d * Shape.PPC, line.getPtAt(0).getX(), 0.0001);
assertEquals(-20d * Shape.PPC, line.getPtAt(0).getY(), 0.0001);
assertEquals(1.2 * Shape.PPC, line.getPtAt(1).getX(), 0.0001);
assertEquals(-2d * Shape.PPC, line.getPtAt(1).getY(), 0.0001);
assertEquals(-1.2 * Shape.PPC, line.getPtAt(2).getX(), 0.0001);
assertEquals(2d * Shape.PPC, line.getPtAt(2).getY(), 0.0001);
}
Aggregations