Search in sources :

Example 1 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 2 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 3 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)

Example 4 with ILine

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

the class TestILine method testGetPerpendicularLineDiag.

@Test
public void testGetPerpendicularLineDiag() {
    line.setLine(1, 1, 2, 2);
    line.updateAandB();
    ILine line2 = line.getPerpendicularLine(ShapeFactory.INST.createPoint());
    assertNotNull(line2);
    assertEqualsDouble(0d, line2.getB());
    assertEqualsDouble(-1d, line2.getA());
}
Also used : ILine(net.sf.latexdraw.models.interfaces.shape.ILine) Test(org.junit.Test) HelperTest(net.sf.latexdraw.HelperTest)

Example 5 with ILine

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

the class TestILine method testGetPerpendicularLineHoriz.

@Test
public void testGetPerpendicularLineHoriz() {
    line.setLine(-10, 0, 10, 0);
    line.updateAandB();
    ILine line2 = line.getPerpendicularLine(ShapeFactory.INST.createPoint());
    assertNotNull(line2);
    assertEqualsDouble(0d, line2.getX1());
    assertEqualsDouble(0d, line2.getX2());
}
Also used : ILine(net.sf.latexdraw.models.interfaces.shape.ILine) Test(org.junit.Test) HelperTest(net.sf.latexdraw.HelperTest)

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