Search in sources :

Example 6 with Line

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

the class TestLine method testGetIntersectionHoriz.

@Test
public void testGetIntersectionHoriz() {
    final Line line2 = ShapeFactory.INST.createLine(0, 0, 1, 0);
    line.setLine(0, -10, 0, 10);
    line.updateAandB();
    final Point pt = line2.getIntersection(line);
    assertNotNull(pt);
    assertEqualsDouble(0d, pt.getX());
    assertEqualsDouble(0d, pt.getY());
}
Also used : Line(net.sf.latexdraw.model.api.shape.Line) Point(net.sf.latexdraw.model.api.shape.Point) Test(org.junit.Test) HelperTest(net.sf.latexdraw.HelperTest)

Example 7 with Line

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

the class ViewArrow method updatePath.

@Override
public void updatePath(final boolean isShadow) {
    path.setStrokeLineCap(StrokeLineCap.BUTT);
    path.getElements().clear();
    path.fillProperty().unbind();
    path.strokeWidthProperty().unbind();
    path.getTransforms().clear();
    ellipse.getTransforms().clear();
    arc.getTransforms().clear();
    GenericViewArrow.super.updatePath(isShadow);
    final Line line = arrow.getArrowLine();
    final double lineAngle = (-line.getLineAngle() + Math.PI * 2d) % (Math.PI * 2d);
    if (arrow.getArrowStyle() != ArrowStyle.NONE && !MathUtils.INST.equalsDouble(lineAngle, 0d)) {
        final Rotate rotate = new Rotate(Math.toDegrees(lineAngle), 0d, 0d);
        path.getTransforms().add(rotate);
        ellipse.getTransforms().add(rotate);
        arc.getTransforms().add(rotate);
    }
}
Also used : Line(net.sf.latexdraw.model.api.shape.Line) Rotate(javafx.scene.transform.Rotate)

Example 8 with Line

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

the class ViewArrowableTrait method getArrowReducedPoint.

protected static Optional<Point> getArrowReducedPoint(final Arrow arrow) {
    final Line l = arrow.getArrowLine();
    if (l == null) {
        return Optional.empty();
    }
    final Point[] points = l.findPoints(l.getX1(), l.getY1(), arrow.getArrowShapeLength());
    if (points.length == 0) {
        return Optional.empty();
    }
    return Arrays.stream(points).reduce((p1, p2) -> p1.distance(l.getPoint2()) < p2.distance(l.getPoint2()) ? p1 : p2);
}
Also used : Line(net.sf.latexdraw.model.api.shape.Line) Point(net.sf.latexdraw.model.api.shape.Point)

Example 9 with Line

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

the class TestBorder method testArcStartHandlerRotated.

@Test
public void testArcStartHandlerRotated() {
    Cmds.of(addArc, selectAllShapes, () -> addedArc.setRotationAngle(0.5)).execute();
    final Point gc = addedArc.getGravityCentre();
    final Point point = addedArc.getStartPoint().rotatePoint(addedArc.getGravityCentre(), addedArc.getRotationAngle());
    final Point newpoint = point.rotatePoint(gc, -Math.PI / 4d).rotatePoint(addedArc.getGravityCentre(), addedArc.getRotationAngle());
    Cmds.of(() -> drag(border.arcHandlerStart).dropBy(newpoint.getX() - point.getX(), newpoint.getY() - point.getY())).execute();
    final Line l1 = ShapeFactory.INST.createLine(gc, addedArc.getStartPoint().rotatePoint(addedArc.getGravityCentre(), addedArc.getRotationAngle()));
    final Line l2 = ShapeFactory.INST.createLine(gc, newpoint);
    assertEquals(l1.getA(), l2.getA(), 0.02);
}
Also used : Line(net.sf.latexdraw.model.api.shape.Line) Point(net.sf.latexdraw.model.api.shape.Point) Test(org.junit.Test)

Example 10 with Line

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

the class SVGArrow method toSVG.

/**
 * Return the SVG tree of the arrowhead or null if this arrowhead has no style.
 * @param document The document used to create elements.
 * @param isShadow True: this operation is call to create the SVG shadow of the shape.
 * @return The SVG tree of the arrowhead or null
 */
SVGElement toSVG(@NotNull final SVGDocument document, final boolean isShadow) {
    if (!arrow.hasStyle()) {
        return null;
    }
    final Line line = arrow.getArrowLine();
    final double lineAngle = (-line.getLineAngle() + Math.PI * 2d) % (Math.PI * 2d);
    currentDoc = document;
    currentMarker = new SVGMarkerElement(document);
    currentMarker.setAttribute(SVGAttributes.SVG_OVERFLOW, SVGAttributes.SVG_VALUE_VISIBLE);
    currentMarker.setAttribute(SVGAttributes.SVG_MARKER_UNITS, SVGAttributes.SVG_UNITS_VALUE_USR);
    if (arrow.getArrowStyle() != ArrowStyle.NONE && !MathUtils.INST.equalsDouble(lineAngle, 0d)) {
        currentMarker.setAttribute(SVGAttributes.SVG_ORIENT, MathUtils.INST.format.format(Math.toDegrees(lineAngle)));
    } else {
        currentMarker.setAttribute(SVGAttributes.SVG_ORIENT, SVGAttributes.SVG_VALUE_AUTO);
    }
    updatePath(isShadow);
    if (currentPath != null) {
        createPathElement();
        currentPathElt.setAttribute(SVGAttributes.SVG_D, currentPath.toString());
        currentPathElt.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_ARROW_SIZE_NUM, MathUtils.INST.format.format(arrow.getArrowSizeNum()));
        currentPathElt.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_ARROW_TBAR_SIZE_NUM, MathUtils.INST.format.format(arrow.getTBarSizeNum()));
    }
    return currentMarker;
}
Also used : Line(net.sf.latexdraw.model.api.shape.Line) SVGMarkerElement(net.sf.latexdraw.parser.svg.SVGMarkerElement)

Aggregations

Line (net.sf.latexdraw.model.api.shape.Line)21 Test (org.junit.Test)12 Point (net.sf.latexdraw.model.api.shape.Point)10 HelperTest (net.sf.latexdraw.HelperTest)7 Theory (org.junit.experimental.theories.Theory)4 Rotate (javafx.scene.transform.Rotate)1 SVGMarkerElement (net.sf.latexdraw.parser.svg.SVGMarkerElement)1