@Override public LineSegment<E> next() { prev = next; next = iter.next(); return new LineSegment(prev, next); }
public LineSegment<E> getClosingSegment() { return new LineSegment<>(positions.get(positions.size() - 1), positions.get(0)); }
public Iterator<LineSegment<E>> getLineSegmentIterator() { return new Iterator<LineSegment<E>>() { Iterator<E> iter = positions.iterator(); E prev, next = iter.next(); @Override public boolean hasNext() { return iter.hasNext(); } @Override public LineSegment<E> next() { prev = next; next = iter.next(); return new LineSegment(prev, next); } @Override public void remove() { throw new UnsupportedOperationException("Not supported yet."); } }; }
public LineSegment<E> offset(ImmutableVector<E> offset) { return new LineSegment<>(start.clone().add(offset), end.clone().add(offset)); }
/** * @param line < p/> * <p/> * @return <b>null</b> if the line does not intersect with the circle */ public LineSegment<Vector2> getIntersection(Line<Vector2> line) { assert !contains(line.getStartingPoint()); Vector2 toCircle = center.clone().sub(line.getStartingPoint()); float distSquare = (float) toCircle.lengthQuad(); if (distSquare == 0) { toCircle = center.clone().sub(line.getStartingPoint().clone().add(line.getDirection())); distSquare = (float) toCircle.lengthQuad(); } float t = toCircle.dot(line.getDirection()); float tmp = radius * radius - distSquare + t * t; if (tmp < 0) { return null;//no intersection } float f = (float) sqrt(tmp); return new LineSegment<>(line.getDirection().clone().mul(t - f).add(line.getStartingPoint()), line.getDirection().clone().mul(t + f).add(line.getStartingPoint())); }