package rebelsky.vec; /** * A vector in two space. * * @author CSC152 2004F * @version 1.0 */ public abstract class Vec2D { /** Error permitted in comparing two coordiantes. */ private double BOUNDS = 0.0; // +----------+----------------------------------------------------- // | Mutators | // +----------+ // +-----------+---------------------------------------------------- // | Observers | // +-----------+ /** * Determine if this object equals another. */ public boolean equals(Object other) { if (other instanceof Vec2D) { Vec2D ovec = (Vec2D) other; return ((Math.abs(this.getX() - ovec.getX()) <= BOUNDS) && (Math.abs(this.getY() - ovec.getY()) <= BOUNDS)); } else { return false; } } // equals(Object) /** * Get the X coordinate of this vector. */ public abstract double getX(); /** * Get the Y coordinate of this vector. */ public abstract double getY(); /** * Get the angle of this vector from the origin. */ public abstract double getAngle(); /** * Get the radius of this vector. */ public abstract double getRadius(); /** * Rotate this vector for some amount around the origin. */ public abstract Vec2D rotate(double angle); /** * Stretch this vector by some amount. */ public abstract Vec2D stretch(double factor); /** * Compute the unit vector for this vector (radius 1, same * angle). */ public abstract Vec2D unitVector(); /** * Convert this vector to a string. */ public abstract String toString(); } // interface Vec2D