Search in sources :

Example 11 with Line

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

the class TestBorder method testArcEndHandler.

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

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

the class CtrlPointShapeBase method getBalancedPoints.

/**
 * Method used by the balance method. Just returns the balanced control points of the given points.
 */
private Point[] getBalancedPoints(final Point pt, final Point prevPt, final Point nextPt) {
    final Line 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 : Line(net.sf.latexdraw.model.api.shape.Line)

Example 13 with Line

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

the class CtrlPointShapeBase 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 Point[] 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 Line line1 = ShapeFactory.INST.createLine(getPtAt(posPrev), ctrlPts[0]);
    final Line 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 : Line(net.sf.latexdraw.model.api.shape.Line) Point(net.sf.latexdraw.model.api.shape.Point)

Example 14 with Line

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

the class TestLine method testGetPerpendicularLineVert.

@Test
public void testGetPerpendicularLineVert() {
    line.setLine(0, 10, 0, -10);
    line.updateAandB();
    final Line line2 = line.getPerpendicularLine(ShapeFactory.INST.createPoint());
    assertNotNull(line2);
    assertEqualsDouble(0d, line2.getY1());
    assertEqualsDouble(0d, line2.getY2());
}
Also used : Line(net.sf.latexdraw.model.api.shape.Line) Test(org.junit.Test) HelperTest(net.sf.latexdraw.HelperTest)

Example 15 with Line

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

the class TestLine method testGetPerpendicularLineHoriz.

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

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