@Test public void testInterect() { Vector2 vertices[] = new Vector2[2]; vertices[0] = new Vector2(0,0); vertices[1] = new Vector2(0,1); Line line = new Line(vertices); double distance = 0.1; Vector2 test = new Vector2(0,0.0099); assertTrue(line.intersect(test, distance * distance)); }
@Override public boolean intersect(Vector2 position, double distanceSquared) { if(vertices == null || vertices.length < 2) { return false; } for(int i = 1;i < vertices.length;++i) { Vector2 start = vertices[i - 1]; Vector2 end = vertices[i]; double dSquared = distanceSquared(start, end, position); if(isPointInSegment(start, end, position) && dSquared < distanceSquared) { return true; } } return false; }
Line extends Drawable { @Override public boolean intersect(Vector2 position, double distanceSquared) { if(vertices == null || vertices.length < 2) { return false; } for(int i = 1;i < vertices.length;++i) { Vector2 start = vertices[i - 1]; Vector2 end = vertices[i]; double dSquared = distanceSquared(start, end, position); if(isPointInSegment(start, end, position) && dSquared < distanceSquared) { return true; } } return false; } }
Line extends Drawable { @Override public boolean intersect(Vector2 position, double distanceSquared) { if(vertices == null || vertices.length < 2) { return false; } for(int i = 1;i < vertices.length;++i) { Vector2 start = vertices[i - 1]; Vector2 end = vertices[i]; double dSquared = distanceSquared(start, end, position); if(isPointInSegment(start, end, position) && dSquared < distanceSquared) { return true; } } return false; } Line(Vector2 vertices[]);  Line(Vector2 vertices[], Box2D box); }
Line extends Drawable { @Override public boolean intersect(Vector2 position, double distanceSquared) { if(vertices == null || vertices.length < 2) { return false; } for(int i = 1;i < vertices.length;++i) { Vector2 start = vertices[i - 1]; Vector2 end = vertices[i]; double dSquared = distanceSquared(start, end, position); if(isPointInSegment(start, end, position) && dSquared < distanceSquared) { return true; } } return false; } Line(Vector2 vertices[]);  Line(Vector2 vertices[], Box2D box); @Override void draw(IGraphics graphics, IStyle style); @Override boolean intersect(Vector2 position, double distanceSquared); static boolean isPointInSegment(Vector2 start, Vector2 end, Vector2 position); static double distanceSquared(Vector2 start, Vector2 end, Vector2 position); @Override int getDrawableType(); }
Line extends Drawable { @Override public boolean intersect(Vector2 position, double distanceSquared) { if(vertices == null || vertices.length < 2) { return false; } for(int i = 1;i < vertices.length;++i) { Vector2 start = vertices[i - 1]; Vector2 end = vertices[i]; double dSquared = distanceSquared(start, end, position); if(isPointInSegment(start, end, position) && dSquared < distanceSquared) { return true; } } return false; } Line(Vector2 vertices[]);  Line(Vector2 vertices[], Box2D box); @Override void draw(IGraphics graphics, IStyle style); @Override boolean intersect(Vector2 position, double distanceSquared); static boolean isPointInSegment(Vector2 start, Vector2 end, Vector2 position); static double distanceSquared(Vector2 start, Vector2 end, Vector2 position); @Override int getDrawableType();  }