/**
 * Author: S. Smith
 * Revised: March 5, 2017
 * 
 * Description: Vector ADT class
 */

import java.util.Objects;
import static java.lang.Math.*;

public class VectorT implements Comparable<VectorT>
{

   public static final double TOLERANCE = 1e-15;

   protected double xc;

   protected double yc;

   public VectorT(double x, double y)
   {
     xc = x;
     yc = y;
   }

   public double xcrd()
   {
     return xc;
   }

   public double ycrd()
   {
     return yc;
   }

   public double mag()
   {
     return sqrt(pow(xc, 2.0) + pow(yc, 2.0));
   }

   @Override
   public boolean equals(Object o)
   {
     if (o == this) return true;
     if (!(o instanceof VectorT)) 
     {
       return false;
     }
     VectorT v = (VectorT) o;
     return (abs(xc-v.xc) <= TOLERANCE) && (abs(yc-v.yc) <= TOLERANCE);
   }

   @Override
   public int hashCode()
   {
     return Objects.hash(xc, yc);
   }

   @Override
   public int compareTo(VectorT v)
   {
     double left = this.mag();
     double right = v.mag();
     if (left < right)
     {
       return -1;
     }
     if (left > right)
     {
       return 1;
     }
     return 0;
   }
}