Search in sources :

Example 11 with ILine

use of net.sf.latexdraw.models.interfaces.shape.ILine 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 if the document is null.
 */
public SVGElement toSVG(final SVGDocument document, final boolean isShadow) {
    if (document == null || !arrow.hasStyle()) {
        return null;
    }
    final ILine 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 : ILine(net.sf.latexdraw.models.interfaces.shape.ILine) SVGMarkerElement(net.sf.latexdraw.parsers.svg.SVGMarkerElement)

Example 12 with ILine

use of net.sf.latexdraw.models.interfaces.shape.ILine in project latexdraw by arnobl.

the class TestBorder method testArcStartHandler.

@Test
public void testArcStartHandler() {
    new CompositeGUIVoidCommand(addArc, waitFXEvents, selectAllShapes, waitFXEvents).execute();
    final IPoint gc = addedArc.getGravityCentre();
    final IPoint point = ShapeFactory.INST.createPoint(addedArc.getStartPoint());
    final IPoint newpoint = point.rotatePoint(gc, -Math.PI / 4d);
    drag(border.arcHandlerStart).dropBy(newpoint.getX() - point.getX(), newpoint.getY() - point.getY());
    waitFXEvents.execute();
    final ILine l1 = ShapeFactory.INST.createLine(gc, ShapeFactory.INST.createPoint(addedArc.getStartPoint()));
    final ILine l2 = ShapeFactory.INST.createLine(gc, newpoint);
    assertEquals(l1.getA(), l2.getA(), 0.02);
}
Also used : ILine(net.sf.latexdraw.models.interfaces.shape.ILine) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint) Test(org.junit.Test)

Example 13 with ILine

use of net.sf.latexdraw.models.interfaces.shape.ILine in project latexdraw by arnobl.

the class TestICircleArc method testGetArrowLineArrow1StartGreaterEnd.

@Theory
public void testGetArrowLineArrow1StartGreaterEnd(@ArcData final ICircleArc shape) {
    shape.setPosition(0d, 0d);
    shape.setWidth(10d);
    shape.setAngleStart(Math.PI * 1.22);
    shape.setAngleEnd(Math.PI * 0.98);
    shape.setArrowStyle(ArrowStyle.RIGHT_ARROW, 1);
    final ILine line = shape.getArrowLine(1);
    assertTrue(line.getX1() < line.getX2());
    assertTrue(line.getY1() < line.getY2());
}
Also used : ILine(net.sf.latexdraw.models.interfaces.shape.ILine) Theory(org.junit.experimental.theories.Theory)

Example 14 with ILine

use of net.sf.latexdraw.models.interfaces.shape.ILine in project latexdraw by arnobl.

the class LAbstractCtrlPointShape method getBalancedPoints.

/**
 * Method used by the balance method. Just returns the balanced control points of the given points.
 */
private IPoint[] getBalancedPoints(final IPoint pt, final IPoint prevPt, final IPoint nextPt) {
    final ILine line = ShapeFactory.INST.createLine(prevPt, nextPt);
    if (line.isHorizontalLine()) {
        line.setLine(pt.getX(), pt.getY(), pt.getX() + 10d, pt.getY());
    } else {
        final double b = pt.getY() - line.getA() * pt.getX();
        line.setLine(pt.getX(), pt.getY(), pt.getX() + 10d, line.getA() * (pt.getX() + 10d) + b);
    }
    return line.findPoints(pt, defaultBalanceGap);
}
Also used : ILine(net.sf.latexdraw.models.interfaces.shape.ILine)

Example 15 with ILine

use of net.sf.latexdraw.models.interfaces.shape.ILine in project latexdraw by arnobl.

the class LAbstractCtrlPointShape method setControlPoints.

/**
 * Method used by the balance method. Just sets the given control points at the given position.
 */
private void setControlPoints(final int position, final IPoint[] ctrlPts) {
    if (ctrlPts == null || ctrlPts.length != 2) {
        return;
    }
    // If there exists an intersection point between the two lines created using control points and points,
    // where is a loop that must be removed by inverting the control points.
    // For the first point, the lines are created differently.
    final int posPrev;
    final int posNext;
    if (position == 0) {
        posNext = points.size() - 1;
        posPrev = 1;
    } else {
        posNext = position == points.size() - 1 ? 0 : position + 1;
        posPrev = position - 1;
    }
    final ILine line1 = ShapeFactory.INST.createLine(getPtAt(posPrev), ctrlPts[0]);
    final ILine line2 = ShapeFactory.INST.createLine(getPtAt(posNext), ctrlPts[1]);
    if (line1.getIntersectionSegment(line2) == null) {
        firstCtrlPts.get(position).setPoint(ctrlPts[0]);
        secondCtrlPts.get(position).setPoint(ctrlPts[1]);
    } else {
        firstCtrlPts.get(position).setPoint(ctrlPts[1]);
        secondCtrlPts.get(position).setPoint(ctrlPts[0]);
    }
}
Also used : ILine(net.sf.latexdraw.models.interfaces.shape.ILine) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint)

Aggregations

ILine (net.sf.latexdraw.models.interfaces.shape.ILine)21 IPoint (net.sf.latexdraw.models.interfaces.shape.IPoint)10 Test (org.junit.Test)10 HelperTest (net.sf.latexdraw.HelperTest)7 Theory (org.junit.experimental.theories.Theory)4 LinearGradient (javafx.scene.paint.LinearGradient)1 Stop (javafx.scene.paint.Stop)1 Rotate (javafx.scene.transform.Rotate)1 IArrow (net.sf.latexdraw.models.interfaces.shape.IArrow)1 SVGMarkerElement (net.sf.latexdraw.parsers.svg.SVGMarkerElement)1