import java.io.*;

public class V2x1
{
// a hack around javas' lack of enumeration
public static int ADD      = 0;
public static int SUBTRACT = 1;
public static int MULTIPLY = 2;

    
public double X;
public double Y;
    
public V2x1(double x, double y) // constructs a rotational matrix 
    {
	X=x;
	Y=y;
    }

public V2x1(V2x1 a)
    {
	X=a.X;
	Y=a.Y;
    }

public V2x1(V2x1 a, V2x1 b, int op)
    {
	if(op == ADD)
	    {
		X = a.X + b.X;
		Y = a.Y + b.Y;
	    }
	else if(op == SUBTRACT)
	    {
		X = a.X - b.X;
		Y = a.Y - b.Y;
	    }
	else if(op == MULTIPLY)
	    {
		X = a.X * b.X;
		Y = a.Y * b.Y;
	    }
    }

public V2x1(M3x3 a, V2x1 b)
    {
	X = a.M[0][0]*b.X + a.M[0][1]*b.Y;
	Y = a.M[1][0]*b.X + a.M[1][1]*b.Y;
    }
    
public void normalize() // constructs a rotational matrix 
    {
	double mag = magnitude();
	if(mag != 0)
	    {
		X=X/mag;
		Y=Y/mag;
	    }
    }

public void boundaries(double top, double bottom, double left, double right, int width, int height)
    {
	if(X > right)
	    X -= width;
	else if(X < left)
	    X += width;
	if(Y > bottom)
	    Y -= height;
	else if(Y < top)
	    Y += height;
    }
    
public void reverse()
    {
	X=-X;
	Y=-Y;
    }
    
public double magnitude()
    {
	return Math.sqrt(X*X + Y*Y);
    }
    
public double mag_squared()
    {
	return (X*X + Y*Y);
    }

public void add(V2x1 a)
    {
	X=X+a.X;
	Y=Y+a.Y;
    }


public void mult(double a)
    {
	X=X*a;
	Y=Y*a;
    }

    
public double x()
    {
	return X;
    }

public double y()
    {
	return X;
    }

public int x_int()
    {
	return ((int)X);
    }

public int y_int()
    {
	return ((int)Y);
    }

public void dump()
    {
	System.out.print("[");
	System.out.print(X);
	System.out.print(" ");
	System.out.print(Y);
	System.out.println("]");
    }

public void dump(String s)
    {
	System.out.println(s);
	System.out.print("[");
	System.out.print(X);
	System.out.print(" ");
	System.out.print(Y);
	System.out.println("]");
    }
}

