package nxm.sys.libg;

import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.util.Arrays;

import nxm.sys.inc.InternalUseOnly;

/** Describes the intersect of a line with a rectangular area
 *
 *  @author Jeanette McCall
 *  @since NeXtMidas 3.9.1
 *
 */
@InternalUseOnly
public class IntersectingLine {

  /** the border it intersects with, or if it is enclosed (i.e. no intersection) */
  @InternalUseOnly
  public enum IntersectLocation {
    /** Line is enclosed within a box */
    ENCLOSED,
    /** Intersect Location at X1 border */
    X1_BORDER,
    /** Intersect Location at X2 border */
    X2_BORDER,
    /** Intersect Location at Y1 border */
    Y1_BORDER,
    /** Intersect Location at Y2 border */
    Y2_BORDER,
  }

  /** the different corners of the rectangle */
  @InternalUseOnly
  public enum Corner {
    /** X1-Y1 Corner */
    X1_Y1_CORNER,
    /** X1-Y2 Corner */
    X1_Y2_CORNER,
    /** X2-Y1 Corner */
    X2_Y1_CORNER,
    /** X2-Y2 Corner */
    X2_Y2_CORNER
  }

  Line2D.Double line;
  IntersectLocation[] locations;

  IntersectingLine (Line2D.Double line, IntersectLocation intersectLoc1, IntersectLocation intersectLoc2) {
    this.line = line;
    this.locations = new IntersectLocation[] {intersectLoc1, intersectLoc2};
  }

  IntersectingLine (Point2D.Double point1, IntersectLocation intersectLoc1, Point2D.Double point2, IntersectLocation intersectLoc2) {
    this.line = new Line2D.Double(point1, point2);
    this.locations = new IntersectLocation[] {intersectLoc1, intersectLoc2};
  }

  Line2D.Double getLine () {
    return line;
  }

  IntersectLocation[] getLocations () {
    return locations;
  }

  public String toString() {
    return "IntersectingLine line ("+line.x1+","+line.y1+") to ("
            +line.x2+","+line.y2+") locations:"+Arrays.toString(locations);
  }
}
