Search in sources :

Example 66 with Point

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

the class LineImpl method getIntersectionSegment.

@Override
public Point getIntersectionSegment(final Line l) {
    final Point p = getIntersection(l);
    if (p == null) {
        return null;
    }
    final double px = p.getX();
    final double py = p.getY();
    final Point tl = getTopLeftPoint();
    final Point br = getBottomRightPoint();
    final Point tl2 = l.getTopLeftPoint();
    final Point br2 = l.getBottomRightPoint();
    if (px >= tl.getX() && px <= br.getX() && py >= tl.getY() && py <= br.getY() && px >= tl2.getX() && px <= br2.getX() && py >= tl2.getY() && py <= br2.getY()) {
        return p;
    }
    return null;
}
Also used : Point(net.sf.latexdraw.model.api.shape.Point)

Example 67 with Point

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

the class ShapeFactoryImpl method createPolygonFrom.

@Override
@NotNull
public Polygon createPolygonFrom(final Polygon sh, final Point pointToAdd) {
    if (sh == null || !MathUtils.INST.isValidPt(pointToAdd)) {
        throw new IllegalArgumentException();
    }
    final List<Point> pts = new ArrayList<>(sh.getPoints());
    pts.add(pointToAdd);
    final Polygon copy = createPolygon(pts);
    copy.copy(sh);
    return copy;
}
Also used : ArrayList(java.util.ArrayList) Point(net.sf.latexdraw.model.api.shape.Point) Polygon(net.sf.latexdraw.model.api.shape.Polygon) NotNull(org.jetbrains.annotations.NotNull)

Example 68 with Point

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

the class ShapeFactoryImpl method createFreeHandFrom.

@Override
@NotNull
public Freehand createFreeHandFrom(final Freehand sh, final Point pointToAdd) {
    if (sh == null || !MathUtils.INST.isValidPt(pointToAdd)) {
        throw new IllegalArgumentException();
    }
    final List<Point> pts = new ArrayList<>(sh.getPoints());
    pts.add(pointToAdd);
    final Freehand copy = createFreeHand(pts);
    copy.copy(sh);
    return copy;
}
Also used : ArrayList(java.util.ArrayList) Freehand(net.sf.latexdraw.model.api.shape.Freehand) Point(net.sf.latexdraw.model.api.shape.Point) NotNull(org.jetbrains.annotations.NotNull)

Example 69 with Point

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

the class ShapeFactoryImpl method createPolylineFrom.

@Override
@NotNull
public Polyline createPolylineFrom(final Polyline sh, final Point pointToAdd) {
    if (sh == null || !MathUtils.INST.isValidPt(pointToAdd)) {
        throw new IllegalArgumentException();
    }
    final List<Point> pts = new ArrayList<>(sh.getPoints());
    pts.add(pointToAdd);
    final Polyline copy = createPolyline(pts);
    copy.copy(sh);
    return copy;
}
Also used : ArrayList(java.util.ArrayList) Polyline(net.sf.latexdraw.model.api.shape.Polyline) Point(net.sf.latexdraw.model.api.shape.Point) NotNull(org.jetbrains.annotations.NotNull)

Example 70 with Point

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

the class TestCanvasTranslation method testTranslateOnSelectionRectangle.

@Test
public void testTranslateOnSelectionRectangle() {
    Cmds.of(addRec).execute();
    final Point tl = canvas.getDrawing().getShapeAt(0).orElseThrow().getTopLeftPoint();
    Cmds.of(() -> clickOn(canvas.getViews().getChildren().get(0))).execute();
    final Point2D bounds = canvas.localToScreen(canvas.getSelectionBorder().getLayoutX() + Canvas.getMargins(), canvas.getSelectionBorder().getLayoutY() + Canvas.getMargins());
    Cmds.of(() -> drag(bounds.getX() + 150, bounds.getY()), () -> dropBy(100d, 200d)).execute();
    assertEquals(tl.getX() + 100d, canvas.getDrawing().getShapeAt(0).orElseThrow().getTopLeftPoint().getX(), 1d);
    assertEquals(tl.getY() + 200d, canvas.getDrawing().getShapeAt(0).orElseThrow().getTopLeftPoint().getY(), 1d);
}
Also used : Point2D(javafx.geometry.Point2D) Point(net.sf.latexdraw.model.api.shape.Point) Test(org.junit.Test)

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