package nxm.sys.libg;

import java.util.ArrayList;

import nxm.sys.libg.IntersectingLine.IntersectLocation;

/** class for finding the intersection of a shape with a rectangular bounds
 *  and creating a line set to represent the portions visible within the bounds
 *  Note: this is used to avoid integer saturation when going to Pixels
 *
 *  @author Jeanette McCall
 *
 */
public class VisibleLinePixSet {

  /** x pixels */         private ArrayList<Integer> xPixels = new ArrayList<>();
  /** y pixels */         private ArrayList<Integer> yPixels = new ArrayList<>();
  /** locations */        private ArrayList<IntersectLocation> locations = new ArrayList<>();
  /** original indices */ private ArrayList<Integer> originalIndices = new ArrayList<>();

  /** default constructor */
  public VisibleLinePixSet () {

  }

  /** add visible pixel
   *
   * @param xPix           x pixel
   * @param yPix           y pixel
   * @param pixLocation    pixel location
   * @param originalIndex  original index
   */
  public void addVisiblePix(int xPix, int yPix, IntersectLocation pixLocation, int originalIndex) {
    xPixels.add(xPix);
    yPixels.add(yPix);
    locations.add(pixLocation);
    originalIndices.add(originalIndex);
  }

  /** get x pixels
   *  @return x pixels as an ArrayList
   */
  public ArrayList<Integer> getXPixels () {
    return xPixels;
  }

  /** get x pixels as an array
   *  @return x pixels as an array
   */
  public int[] getXPixelsAsArray () {
    return arrayListIntegerToIntArray(xPixels);
  }

  /** get x pixel at specific index
   *
   *  @param index pixel index
   *  @return x pixel corresponding to that index
   */
  public int getXPixel (int index) {
    return xPixels.get(index);
  }

  /** get y pixels
   *  @return y pixels as an ArrayList
   */
  public ArrayList<Integer> getYPixels () {
    return yPixels;
  }

  /** get y pixels as an array
   *  @return y pixels as an array
   */
  public int[] getYPixelsAsArray () {
    return arrayListIntegerToIntArray(yPixels);
  }

  /** get y pixel at specific index
  *
  *  @param index pixel index
  *  @return y pixel corresponding to that index
  */
  public int getYPixel (int index) {
    return yPixels.get(index);
  }

  private int[] arrayListIntegerToIntArray (ArrayList<Integer> integerArrayList) {
    int[] intArray = new int[integerArrayList.size()];
    for (int i = 0; i < intArray.length; i++) {
      intArray[i] = integerArrayList.get(i);
    }
    return intArray;
  }

}
