cdx
Class Vector2d

java.lang.Object
  extended by cdx.Vector2d

public final class Vector2d
extends java.lang.Object

The Vector2d class implements a 2-dimensional vector that can represent the position or velocity of an object within a 2D space. This implementation uses public, non-final fields to avoid as much object creation as possible. Java does not have value types per se, but these vector classes are the closest thing that is possible.


Field Summary
 float x
          Fields for the x and y coordinates of the vector.
 float y
          Fields for the x and y coordinates of the vector.
 
Constructor Summary
Vector2d()
          The default constructor for the Vector2d class returns an object representing the zero vector.
Vector2d(float x, float y)
          The main constructor for the Vector2d class takes the two coordinates as parameters and produces an object representing that vector.
Vector2d(Vector2d v)
          The secondary constructor for the Vector2d class takes a vector to copy into this new instance and returns an instance that represents a copy of that vector.
 
Method Summary
 boolean equals(java.lang.Object o)
          Check for equality of two Vector2d objects
 boolean equals(Vector2d b)
          Check for equality of two Vector2d objects
 int hashCode()
          The hashfuction for Vector2d
 void set(float x, float y)
          The set method is basically a convenience method that sets the internal values of the coordinates.
 void set(Vector2d v)
          The set method is basically a convenience method that sets the internal values of the coordinates copying them from another vector.
 java.lang.String toString()
          Convert a Vector2d to a string
 void zero()
          The zero method is a convenience method to zero the coordinates of the vector.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

x

public float x
Fields for the x and y coordinates of the vector.


y

public float y
Fields for the x and y coordinates of the vector.

Constructor Detail

Vector2d

public Vector2d()
The default constructor for the Vector2d class returns an object representing the zero vector.


Vector2d

public Vector2d(float x,
                float y)
The main constructor for the Vector2d class takes the two coordinates as parameters and produces an object representing that vector.

Parameters:
x - the coordinate on the x (east-west) axis
y - the coordinate on the y (north-south) axis

Vector2d

public Vector2d(Vector2d v)
The secondary constructor for the Vector2d class takes a vector to copy into this new instance and returns an instance that represents a copy of that vector.

Parameters:
v - the vector to copy into this new instance
Method Detail

set

public void set(float x,
                float y)
The set method is basically a convenience method that sets the internal values of the coordinates.

Parameters:
x - the coordinate on the x (east-west) axis
y - the coordinate on the y (north-south) axis

set

public void set(Vector2d v)
The set method is basically a convenience method that sets the internal values of the coordinates copying them from another vector.

Parameters:
v - the coordinate on the x and y axis as a Vecter2d

zero

public void zero()
The zero method is a convenience method to zero the coordinates of the vector.


equals

public boolean equals(java.lang.Object o)
               throws java.lang.ClassCastException
Check for equality of two Vector2d objects

Overrides:
equals in class java.lang.Object
Throws:
java.lang.ClassCastException

equals

public boolean equals(Vector2d b)
Check for equality of two Vector2d objects


hashCode

public int hashCode()
The hashfuction for Vector2d

Overrides:
hashCode in class java.lang.Object

toString

public java.lang.String toString()
Convert a Vector2d to a string

Overrides:
toString in class java.lang.Object