/* xy.h
 *
 * A class to store (x,y) coordinates, along with an input operator.
 */


#include <math.h>


class xyCoord {
public:

  float x, y;

  xyCoord() {}

  xyCoord( float xx, float yy )
    { x = xx; y = yy; }

  xyCoord operator + (xyCoord p)
    { return * new xyCoord( x+p.x, y+p.y ); }

  xyCoord operator - (xyCoord p)
    { return * new xyCoord( x-p.x, y-p.y ); }

  float operator * (xyCoord p)	/* dot product */
    { return x * p.x + y * p.y; }

  xyCoord operator * (float k)	/* scalar product */
    { return * new xyCoord( k * x, k * y ); }

  float operator ^ (xyCoord p)	/* cross product */
    { return x*p.y - p.x*y; }

  void normalize() {
    float len;
    len = sqrt( x*x + y*y );
    x /= len;
    y /= len;
  }

  friend istream& operator >> ( istream& stream, xyCoord & xy ) {
    
    char c;

    stream >> ws;
    stream.get(c);		// read first paren
    stream >> ws >> xy.x >> ws;	// read x
    stream.get(c);		// read comma
    stream >> ws >> xy.y >> ws;	// read y
    stream.get(c);		// read second paren

    return stream;
  }

  friend ostream& operator << ( ostream& stream, xyCoord & xy ) {
    
    stream << "(" << xy.x << "," << xy.y << ")";
    return stream;
  }
};
