/** The CirclePath class represents a circular path, revolving around a
    center point at a set increment (permanently set to Pi/100 in this
    version)
*/
public class CirclePath implements Path {
  protected int x, y;
  protected double angle, r;

  public static final double FULL_CIRCLE = Math.PI * 2;
  public static final double ANGLE_INC = Math.PI/100;
  
  /** Constructor based on a starting point of the circumference of a
      circle and the center of the circle.  
  */
  public CirclePath(Point start, Point center) {
    this.x = center.getX();
    this.y = center.getY();
    double dx=start.getX()-x, dy=start.getY()-y;
    this.r = Math.sqrt(dx*dx + dy*dy);
    this.angle = Math.atan(dy/dx);
    if (dx < 0) angle += Math.PI;
  }

  /** Constructor based on a center point and a radius.
    */ 
  public CirclePath(int x, int y, double r) {
    this.x = x;
    this.y = y;
    this.r = r;
    this.angle = 0;
  }
  
  /** Path reset method.
      @see Path#reset()
    */
  public void reset() {
    angle = 0;
  }

  /** Path nextPoint method.
      @see Path#nextPoint()
  */
  public Point nextPoint() {
    if (angle >= FULL_CIRCLE) {
      // angle = 0;
      // replaced with below to reduce jumping
      angle -= FULL_CIRCLE;
    } else {
      angle += ANGLE_INC;
    }
    
    return new Point((int)(x + r*Math.cos(angle)), 
		     (int)(y + r*Math.sin(angle)));
  }
}
