Search in sources :

Example 6 with ILine

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

the class TestICircleArc method testGetArrowLineArrow1StartLesserEnd.

@Theory
public void testGetArrowLineArrow1StartLesserEnd(@ArcData final ICircleArc shape) {
    shape.setPosition(0d, 0d);
    shape.setWidth(10d);
    shape.setAngleStart(Math.PI * 1.22);
    shape.setAngleEnd(Math.PI * 1.56);
    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 7 with ILine

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

the class GenericViewArrow method updatePath.

default void updatePath(final boolean isShadow) {
    final IArrow arrow = getArrow();
    final ILine arrowLine = arrow.getArrowLine();
    if (arrow.getArrowStyle() == ArrowStyle.NONE || arrowLine == null || !arrow.hasStyle()) {
        return;
    }
    final IPoint pt1 = arrowLine.getPoint1();
    final IPoint pt2 = arrowLine.getPoint2();
    setTranslation(pt1.getX(), pt1.getY());
    switch(arrow.getArrowStyle()) {
        case BAR_END:
            updatePathBarEnd(isShadow);
            break;
        case BAR_IN:
            updatePathBarIn(pt1, pt2, isShadow);
            break;
        case CIRCLE_END:
        case DISK_END:
            updatePathDiskCircleEnd(isShadow);
            break;
        case CIRCLE_IN:
        case DISK_IN:
            updatePathDiskCircleIn(pt1, pt2, isShadow);
            break;
        case RIGHT_ARROW:
        case LEFT_ARROW:
            updatePathRightLeftArrow(isShadow);
            break;
        case RIGHT_DBLE_ARROW:
        case LEFT_DBLE_ARROW:
            updatePathDoubleLeftRightArrow(isShadow);
            break;
        case RIGHT_ROUND_BRACKET:
        case LEFT_ROUND_BRACKET:
            updatePathRoundLeftRightBracket(isShadow);
            break;
        case LEFT_SQUARE_BRACKET:
        case RIGHT_SQUARE_BRACKET:
            updatePathRightLeftSquaredBracket(isShadow);
            break;
        case SQUARE_END:
            updatePathSquareEnd(pt1, pt2, isShadow);
            break;
        case ROUND_END:
            updatePathRoundEnd(isShadow);
            break;
        case ROUND_IN:
            updatePathRoundIn(pt1, pt2, isShadow);
            break;
        case NONE:
            break;
    }
}
Also used : ILine(net.sf.latexdraw.models.interfaces.shape.ILine) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint) IArrow(net.sf.latexdraw.models.interfaces.shape.IArrow)

Example 8 with ILine

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

the class ViewSingleShape method computeGradient.

private LinearGradient computeGradient() {
    final IPoint tl = model.getTopLeftPoint();
    final IPoint br = model.getBottomRightPoint();
    IPoint pt1 = ShapeFactory.INST.createPoint((tl.getX() + br.getX()) / 2d, tl.getY());
    IPoint pt2 = ShapeFactory.INST.createPoint((tl.getX() + br.getX()) / 2d, br.getY());
    double angle = model.getGradAngle() % (2d * Math.PI);
    double gradMidPt = model.getGradMidPt();
    if (tl.equals(br)) {
        return null;
    }
    if (angle < 0d) {
        angle = 2d * Math.PI + angle;
    }
    if (angle >= Math.PI) {
        gradMidPt = 1d - gradMidPt;
        angle -= Math.PI;
    }
    if (MathUtils.INST.equalsDouble(angle, 0d)) {
        if (gradMidPt < 0.5)
            pt1.setY(pt2.getY() - Point2D.distance(pt2.getX(), pt2.getY(), (tl.getX() + br.getX()) / 2d, br.getY()));
        pt2.setY(tl.getY() + (br.getY() - tl.getY()) * gradMidPt);
    } else {
        if (MathUtils.INST.equalsDouble(angle % (Math.PI / 2d), 0d)) {
            pt1 = ShapeFactory.INST.createPoint(tl.getX(), (tl.getY() + br.getY()) / 2d);
            pt2 = ShapeFactory.INST.createPoint(br.getX(), (tl.getY() + br.getY()) / 2d);
            if (gradMidPt < 0.5)
                pt1.setX(pt2.getX() - Point2D.distance(pt2.getX(), pt2.getY(), br.getX(), (tl.getY() + br.getY()) / 2d));
            pt2.setX(tl.getX() + (br.getX() - tl.getX()) * gradMidPt);
        } else {
            final IPoint cg = model.getGravityCentre();
            final ILine l2;
            final ILine l;
            pt1 = pt1.rotatePoint(cg, -angle);
            pt2 = pt2.rotatePoint(cg, -angle);
            l = ShapeFactory.INST.createLine(pt1, pt2);
            if (angle >= 0d && angle < Math.PI / 2d) {
                l2 = l.getPerpendicularLine(tl);
            } else {
                l2 = l.getPerpendicularLine(ShapeFactory.INST.createPoint(tl.getX(), br.getY()));
            }
            pt1 = l.getIntersection(l2);
            final double distance = Point2D.distance(cg.getX(), cg.getY(), pt1.getX(), pt1.getY());
            l.setX1(pt1.getX());
            l.setY1(pt1.getY());
            final IPoint[] pts = l.findPoints(pt1, 2d * distance * gradMidPt);
            pt2 = pts[0];
            if (gradMidPt < 0.5) {
                pt1 = pt1.rotatePoint(model.getGravityCentre(), Math.PI);
            }
        }
    }
    return new LinearGradient(pt1.getX(), pt1.getY(), pt2.getX(), pt2.getY(), false, CycleMethod.NO_CYCLE, new Stop(0d, model.getGradColStart().toJFX()), new Stop(1d, model.getGradColEnd().toJFX()));
}
Also used : LinearGradient(javafx.scene.paint.LinearGradient) ILine(net.sf.latexdraw.models.interfaces.shape.ILine) Stop(javafx.scene.paint.Stop) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint)

Example 9 with ILine

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

the class ViewArrowableTrait method getArrowReducedPoint.

protected static Optional<IPoint> getArrowReducedPoint(final IArrow arrow) {
    final ILine l = arrow.getArrowLine();
    if (l == null) {
        return Optional.empty();
    }
    final IPoint[] 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 : ILine(net.sf.latexdraw.models.interfaces.shape.ILine) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint)

Example 10 with ILine

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

the class TestBorder method testArcEndHandler.

@Test
public void testArcEndHandler() {
    new CompositeGUIVoidCommand(addArc, waitFXEvents, selectAllShapes, waitFXEvents).execute();
    final IPoint gc = addedArc.getGravityCentre();
    final IPoint point = ShapeFactory.INST.createPoint(addedArc.getEndPoint());
    final IPoint newpoint = point.rotatePoint(gc, Math.PI / 3d);
    drag(border.arcHandlerEnd).dropBy(newpoint.getX() - point.getX(), newpoint.getY() - point.getY());
    waitFXEvents.execute();
    final ILine l1 = ShapeFactory.INST.createLine(gc, ShapeFactory.INST.createPoint(addedArc.getEndPoint()));
    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)

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