public static Line getLineInterval(Line line, float start, float end) { assert start >= 0 && start <= 1; assert end >= 0 && end <= 1; return new Line( line.getX1() + line.getDX() * start, line.getY1() + line.getDY() * start, line.getX1() + line.getDX() * end, line.getY1() + line.getDY() * end); }
public void drawLine(int x0, int y0, int x1, int y1, int blockId) { l.set(x0, y0, x1, y1); drawableMap.updateBlocks(l, blockId); }
public boolean intersects(Entity e) { Line interLine = new Line(pos.x, pos.y, pos.x + velocity.x, pos.y + velocity.y); return interLine.intersects(e.sp); }
public static Rectangle getNewBoundingRectangle(Shape shape) { if (shape instanceof Circle) { Circle circle = (Circle) shape; float x = circle.getCenterX(); float y = circle.getCenterY(); float r = circle.getRadius(); return new Rectangle(x - r, y - r, 2 * r, 2 * r); } if (shape instanceof Line) { Line line = (Line) shape; float x1; float x2; if (line.getX2() > line.getX1()) { x1 = line.getX1(); x2 = line.getX2(); } else { x1 = line.getX2(); x2 = line.getX1(); } float y1; float y2; if (line.getY2() > line.getY1()) { y1 = line.getY1(); y2 = line.getY2(); } else { y1 = line.getY2(); y2 = line.getY1(); } return new Rectangle( x1 - EPSILON, y1 - EPSILON, x2 - x1 + 1 + EPSILON, y2 - y1 + 1 + EPSILON); } if (shape instanceof Rectangle) { Rectangle r = (Rectangle) shape; return new Rectangle(r.getX(), r.getY(), r.getWidth(), r.getHeight()); } assert false; return new Rectangle(shape.getMinX(), shape.getMinY(), shape.getWidth(), shape.getHeight()); }
public static boolean lineEquals(Line l1, Line l2) { return l1.getX1() == l2.getX1() && l1.getY1() == l2.getY1() && l1.getX2() == l2.getX2() && l1.getY2() == l2.getY2(); }