/*
	Project: Balls2D
	Author: Simon Gayton
	Copyright 2007 (C) Simon Gayton
*/

/*
  This class represents a 2D edge, or wall.
*/
public class Edge2D {
  Vector2D v1, v2; // References to the two end points.
  Vector2D edge; // The vector from one end point to the other.
  Vector2D normal; // The unit normal of the edge.
  float magSqrd; // The length of the edge squared.

  /*
    Construct an edge from two end points.
  */
  Edge2D(Vector2D a, Vector2D b) {
    v1 = a;
    v2 = b;

    // Calculate the edge vector.
    edge = new Vector2D(v2.x-v1.x, v2.y-v1.y);

    // Calculate the normal vector.
    normal = new Vector2D(-edge.y, edge.x);
    normal.normalize();

    // Calculate the length of the edge squared.
    magSqrd = Vector2D.dot(edge, edge);
  }
}
