@Test public void testNearestPointInside() { ITube tube = Tube.create(startCenter, endCenter, radius); ITube tubeZeroLength = Tube.create(startCenter, startCenter, radius); IVector2 nearestPointInside = Vector2.fromXY(0, 9); IVector2 pOutside = Vector2.fromXY(0, 11); Assert.assertEquals(tube.nearestPointInside(pOutside), nearestPointInside); Assert.assertEquals(tube.nearestPointInside(nearestPointInside), nearestPointInside); Assert.assertEquals(tubeZeroLength.nearestPointInside(pOutside), nearestPointInside); }
@Override public IVector2 nearestPointInside(final IVector2 point) { ILineSegment tubeLineSeg = Lines.segmentFromPoints(startCenter, endCenter); if (tubeLineSeg.distanceTo(point) < radius) { return point; } IVector2 leadPoint = tubeLineSeg.closestPointOnLine(point); return LineMath.stepAlongLine(leadPoint, point, radius - 1); }
Tube implements ITube { @Override public IVector2 nearestPointInside(final IVector2 point) { ILineSegment tubeLineSeg = Lines.segmentFromPoints(startCenter, endCenter); if (tubeLineSeg.distanceTo(point) < radius) { return point; } IVector2 leadPoint = tubeLineSeg.closestPointOnLine(point); return LineMath.stepAlongLine(leadPoint, point, radius - 1); } }
Tube implements ITube { @Override public IVector2 nearestPointInside(final IVector2 point) { ILineSegment tubeLineSeg = Lines.segmentFromPoints(startCenter, endCenter); if (tubeLineSeg.distanceTo(point) < radius) { return point; } IVector2 leadPoint = tubeLineSeg.closestPointOnLine(point); return LineMath.stepAlongLine(leadPoint, point, radius - 1); } @SuppressWarnings("unused") private  Tube(); private  Tube(final IVector2 startCenter, final IVector2 endCenter, final double radius); }
Tube implements ITube { @Override public IVector2 nearestPointInside(final IVector2 point) { ILineSegment tubeLineSeg = Lines.segmentFromPoints(startCenter, endCenter); if (tubeLineSeg.distanceTo(point) < radius) { return point; } IVector2 leadPoint = tubeLineSeg.closestPointOnLine(point); return LineMath.stepAlongLine(leadPoint, point, radius - 1); } @SuppressWarnings("unused") private  Tube(); private  Tube(final IVector2 startCenter, final IVector2 endCenter, final double radius); static Tube create(final IVector2 startCenter, final IVector2 endCenter, final double radius); static Tube fromLineSegment(final ILineSegment lineSegment, final double radius); @Override double radius(); @Override IVector2 startCenter(); @Override IVector2 endCenter(); @Override IVector2 center(); @Override boolean isPointInShape(final IVector2 point); @Override boolean isPointInShape(final IVector2 point, final double margin); @Override IVector2 nearestPointOutside(final IVector2 point); @Override IVector2 nearestPointInside(final IVector2 point); @Override List<IVector2> lineIntersections(final ILine line); @Override ITube withMargin(final double margin); }
Tube implements ITube { @Override public IVector2 nearestPointInside(final IVector2 point) { ILineSegment tubeLineSeg = Lines.segmentFromPoints(startCenter, endCenter); if (tubeLineSeg.distanceTo(point) < radius) { return point; } IVector2 leadPoint = tubeLineSeg.closestPointOnLine(point); return LineMath.stepAlongLine(leadPoint, point, radius - 1); } @SuppressWarnings("unused") private  Tube(); private  Tube(final IVector2 startCenter, final IVector2 endCenter, final double radius); static Tube create(final IVector2 startCenter, final IVector2 endCenter, final double radius); static Tube fromLineSegment(final ILineSegment lineSegment, final double radius); @Override double radius(); @Override IVector2 startCenter(); @Override IVector2 endCenter(); @Override IVector2 center(); @Override boolean isPointInShape(final IVector2 point); @Override boolean isPointInShape(final IVector2 point, final double margin); @Override IVector2 nearestPointOutside(final IVector2 point); @Override IVector2 nearestPointInside(final IVector2 point); @Override List<IVector2> lineIntersections(final ILine line); @Override ITube withMargin(final double margin);  }