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