// Path: src/roquen/fake/Vect2f.java
// public class Vect2f {
//   public float x,y;
//   
//   public Vect2f set(float x, float y)
//   {
//     this.x=x; this.y=y;
//     return this;
//   }
//   
//   
//   /** */
//   private static final int HASH = hashMakeSeed(0);
//   
//   @Override
//   public int hashCode()
//   {
//     return hashComplete(hashAdd(HASH,x,y));
//   }
// }


import roquen.fake.Vect2f;

package roquen.interp;


/**
 * For performing in-order walks of cells on a uniform 2D grid which
 * are crossed by a line segment or ray.  It is equivalent to a
 * Bresenham's line walk. The basic mechanism is to determine a major
 * axis and walk a connected set of cells along that axis. 
 * <p>
 * Passed in values make the assumption that the extent of cells are
 * of one unit.  User code scaling is required for other sizes.
 * <p>
 * The name is actually a misnomer as the computation is in floating
 * point.  This drastically reduces the complexity of the update.
 */
public class DDA2D {  
  /** 
   * use-case specific cell offset. default=0 (lower left).
   * set to .5 for center of cell for example.
   */
  private double offset;
  
  /** current number of steps (integer) */
  private double step;
  
  /** inverse the number of steps (one rounding error) */
  private double in;
  
  /** coordinate of cell containing the first point (integer) */
  private double x0,y0;
  
  /** integer displacement from first to last cell (integer) */
  private double dx,dy;
  
  /** current step (cell) coordinate, includes fractional */
  public double x,y;
  
  public int set(float sx, float sy, float ex, float ey)
  {
    // find the cell coordinate of the end points
    x0 = Math.floor(sx);
    y0 = Math.floor(sy);
    
    double x1 = Math.floor(ex);
    double y1 = Math.floor(ey);
    
    // initialize current cell coordinate
    x = x0 + offset;
    y = y0 + offset;
    step = 1;
    
    // calculate the deltas and find the maximum magnitude
    dx = x1-x0;
    dy = y1-y0;
    
    double ax = Math.abs(dx);
    double ay = Math.abs(dy);
    double n  = ax > ay ? ax : ay;

    // calculate the step values
    in = 1.0/n;
    
    return (int)n;
  }
  
  /**
   * Sets the instance to iterate over all cells covered
   * by the line segment from p0 to p1 in order.  Return
   * the number of steps required.
   * <p>
   * The fields ({@link #x}, {@link #y}) are
   * set to the first cell coordinate.
   */

// Path: src/roquen/fake/Vect2f.java
// public class Vect2f {
//   public float x,y;
//   
//   public Vect2f set(float x, float y)
//   {
//     this.x=x; this.y=y;
//     return this;
//   }
//   
//   
//   /** */
//   private static final int HASH = hashMakeSeed(0);
//   
//   @Override
//   public int hashCode()
//   {
//     return hashComplete(hashAdd(HASH,x,y));
//   }
// }


// Path: src/roquen/interp/DDA2D.java
import roquen.fake.Vect2f;

package roquen.interp;


/**
 * For performing in-order walks of cells on a uniform 2D grid which
 * are crossed by a line segment or ray.  It is equivalent to a
 * Bresenham's line walk. The basic mechanism is to determine a major
 * axis and walk a connected set of cells along that axis. 
 * <p>
 * Passed in values make the assumption that the extent of cells are
 * of one unit.  User code scaling is required for other sizes.
 * <p>
 * The name is actually a misnomer as the computation is in floating
 * point.  This drastically reduces the complexity of the update.
 */
public class DDA2D {  
  /** 
   * use-case specific cell offset. default=0 (lower left).
   * set to .5 for center of cell for example.
   */
  private double offset;
  
  /** current number of steps (integer) */
  private double step;
  
  /** inverse the number of steps (one rounding error) */
  private double in;
  
  /** coordinate of cell containing the first point (integer) */
  private double x0,y0;
  
  /** integer displacement from first to last cell (integer) */
  private double dx,dy;
  
  /** current step (cell) coordinate, includes fractional */
  public double x,y;
  
  public int set(float sx, float sy, float ex, float ey)
  {
    // find the cell coordinate of the end points
    x0 = Math.floor(sx);
    y0 = Math.floor(sy);
    
    double x1 = Math.floor(ex);
    double y1 = Math.floor(ey);
    
    // initialize current cell coordinate
    x = x0 + offset;
    y = y0 + offset;
    step = 1;
    
    // calculate the deltas and find the maximum magnitude
    dx = x1-x0;
    dy = y1-y0;
    
    double ax = Math.abs(dx);
    double ay = Math.abs(dy);
    double n  = ax > ay ? ax : ay;

    // calculate the step values
    in = 1.0/n;
    
    return (int)n;
  }
  
  /**
   * Sets the instance to iterate over all cells covered
   * by the line segment from p0 to p1 in order.  Return
   * the number of steps required.
   * <p>
   * The fields ({@link #x}, {@link #y}) are
   * set to the first cell coordinate.
   */

  public int set(Vect2f p0, Vect2f p1)
