/** * New line segment with start and end reversed. * * @return new LineSegment with start and end reversed */ public LineSegment reverse() { return new LineSegment(this.end, this.start); }
/** * Ctor with given start point, a point that defines the direction of the line and a length * * @param start start point * @param direction point that defines the direction (a line from start to direction point) * @param distance how long to move along the line between start and direction */ public LineSegment(Point start, Point direction, double distance) { this.start = start; this.end = new LineSegment(start, direction).pointAlongLineSegment(distance); }
/** * LineSegment that starts at offset from start and runs for length towards end point * * @param offset offset applied at begin of line * @param length length of the new segment * @return new LineSegment computed */ public LineSegment subSegment(double offset, double length) { Point subSegmentStart = pointAlongLineSegment(offset); Point subSegmentEnd = pointAlongLineSegment(offset + length); return new LineSegment(subSegmentStart, subSegmentEnd); }
@Test public void equalsTest() { Point point1 = new Point(1, 2); Point point2 = new Point(1, 2); Point point3 = new Point(1, 1); LineSegment point1ToPoint2 = new LineSegment(point1, point2); LineSegment point1ToPoint3 = new LineSegment(point1, point3); LineSegment point1ToPoint1 = new LineSegment(point1, point1); Assert.assertNotEquals(point1ToPoint1, point1ToPoint3); Assert.assertEquals(point1ToPoint1, point1ToPoint1); Assert.assertEquals(point1ToPoint1, point1ToPoint2); }
if (0 == (codeStart | codeEnd)) { return new LineSegment(a, b); } else if (0 != (codeStart & codeEnd)) {
/** * New line segment with start and end reversed. * * @return new LineSegment with start and end reversed */ public LineSegment reverse() { return new LineSegment(this.end, this.start); }
Point point7 = new Point(2, 5); LineSegment point1ToPoint3 = new LineSegment(point1, point3); LineSegment point1ToPoint1 = new LineSegment(point1, point1); LineSegment vertical = new LineSegment(point4, point5); Assert.assertEquals(s3, null); LineSegment verticalClipped = new LineSegment(point6, point7); LineSegment s4 = vertical.clipToRectangle(r1); Assert.assertEquals(s4, verticalClipped); Point point10 = new Point(-1, -1); Point point11 = new Point(1, 1); LineSegment s6 = new LineSegment(point8, point9); LineSegment s7 = s6.clipToRectangle(r3); LineSegment s8 = new LineSegment(point11, point10); Assert.assertEquals(s8, s7); LineSegment s6r = new LineSegment(point9, point8); LineSegment s7r = s6r.clipToRectangle(r3); LineSegment s8r = new LineSegment(point10, point11); Assert.assertEquals(s8r, s7r);
LineSegment currentSegment = new LineSegment(c[i - 1], c[i]); double currentLength = currentSegment.length();
@Test public void ctorTest() { // tests the second ctor that computes a line segment from point, target and distance Point[] points = {new Point(1, 0), new Point(0, 1), new Point(0, 0), new Point(1, 1), new Point(2, 2), new Point(0, 4), new Point(-182.9934, 0), new Point(34.6, -356.1)}; Point point1 = new Point(0, 0); Point point2 = new Point(1, 0); Point point3 = new Point(2, 2); LineSegment ls1 = new LineSegment(point1, point2, 0.5); Assert.assertEquals(new Point(0.5, 0), ls1.end); Assert.assertEquals(Math.sqrt(8), point1.distance(point3), 0.001d); for (Point point : points) { LineSegment ls2 = new LineSegment(point1, point, point1.distance(point)); Assert.assertEquals(point, ls2.end); } LineSegment ls3 = new LineSegment(point1, point3, 0.5 * point1.distance(point3)); Assert.assertEquals(new Point(1, 1), ls3.end); }
/** * Ctor with given start point, a point that defines the direction of the line and a length * * @param start start point * @param direction point that defines the direction (a line from start to direction point) * @param distance how long to move along the line between start and direction */ public LineSegment(Point start, Point direction, double distance) { this.start = start; this.end = new LineSegment(start, direction).pointAlongLineSegment(distance); }
/** * LineSegment that starts at offset from start and runs for length towards end point * * @param offset offset applied at begin of line * @param length length of the new segment * @return new LineSegment computed */ public LineSegment subSegment(double offset, double length) { Point subSegmentStart = pointAlongLineSegment(offset); Point subSegmentEnd = pointAlongLineSegment(offset + length); return new LineSegment(subSegmentStart, subSegmentEnd); }
if (0 == (codeStart | codeEnd)) { return new LineSegment(a, b); } else if (0 != (codeStart & codeEnd)) {
LineSegment currentSegment = new LineSegment(c[i - 1], c[i]); double currentLength = currentSegment.length();