org.instantreality.InstantIO
Class Vec2f

java.lang.Object
  extended by org.instantreality.InstantIO.Vec2f

public class Vec2f
extends java.lang.Object

Helper class for exchanging vectors of two float components.

Vec2f is a basic helper class for exchanging vectors of two float components between different software components. It does not contain any means for vector arithmetics, only methods for setting and getting the components. It is not meant to be used directly by software components for vector representation. Instead, software components should use their own, appropriate classes for handling vectors. Only when sending vectors to an OutSlot, or when receiving vectors from an InSlot, the internal representation of vectors should be converted to Vec2f's. This ensures the interoperability between different software components that use different internal representations for vectors.

The following example creates a Vec2f object and prints its components to the console:

 Vec2f vec = new Vec2f(1.0f, 2.0f);
 System.out.println("x component = " + vec.getX());
 System.out.println("y component = " + vec.getY());
 

Author:
Patrick Dähne

Field Summary
static Vec2f NULL
          The null vector <0,0>.
 
Constructor Summary
Vec2f(float[] vec)
          Constructor that initializes the components of the Vec2f object with the values of a given float array.
Vec2f(float x, float y)
          Constructor that initializes the components of the Vec2f object with the given float values.
Vec2f(Vec2f vec)
          Constructor that initializes the components of the Vec2f object with the components taken from another Vec2f object.
 
Method Summary
 boolean equals(java.lang.Object obj)
          Compares the vector to another object.
 void get(float[] vec)
          Returns the values of the x and y components.
 float getX()
          Returns the value of the x component.
 float getY()
          Returns the value of the y component.
 java.lang.String toString()
          Converts the vector to a string.
static Vec2f valueOf(java.lang.String str)
          Converts a string to a Vec2f object.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

NULL

public static final Vec2f NULL
The null vector <0,0>.

Constructor Detail

Vec2f

public Vec2f(float x,
             float y)
Constructor that initializes the components of the Vec2f object with the given float values.

The following example demonstrates how to create a Vec2f object:

 float x_component = 1.0f;
 float y_component = 2.0f;
 Vec2f vec = new Vec2f(x_component, y_component);
 

Parameters:
x - Value of the x component of the new vector.
y - Value of the y component of the new vector.

Vec2f

public Vec2f(float[] vec)
Constructor that initializes the components of the Vec2f object with the values of a given float array.

The following example demonstrates how to create a Vec2f object:

 float x_component = 1.0f;
 float y_component = 2.0f;
 float[] vector_components = new float[] { x_component, y_component };
 Vec2f vec = new Vec2f(vector_components);
 

Parameters:
vec - An array of at least two float values. The x component of the vector is set to the value of the first element of the array, and the y component is set to the value of the second element of the array.

Vec2f

public Vec2f(Vec2f vec)
Constructor that initializes the components of the Vec2f object with the components taken from another Vec2f object.

The following example demonstrates how to create a Vec2f object that is an exact copy of another Vec2f object:

 Vec2f given_vec = ...;
 Vec2f vec = new Vec2f(given_vec);
 

Parameters:
vec - The other vector used to initialize the new vector.
Method Detail

getX

public final float getX()
Returns the value of the x component.

The following example demonstrates how to print the x component of a Vec2f object to the console:

 Vec2f vec = ...;
 System.out.println("x component = " + vec.getX());
 

Returns:
The value of the x component

getY

public final float getY()
Returns the value of the y component.

The following example demonstrates how to print the y component of a Vec2f object to the console:

 Vec2f vec = ...;
 System.out.println("y component = " + vec.getY());
 

Returns:
The value of the y component

get

public final void get(float[] vec)
Returns the values of the x and y components.

The following example prints the components of a Vec2f object to the console:

 Vec2f vec = ...;
 float[] vector_components = new float[2];
 vec.get(vector_components);
 System.out.println("x component = " + vector_components[0]);
 System.out.println("y component = " + vector_components[1]);
 

Parameters:
vec - A float array that gets filled with the components of the vector. This array must have at least two elements. The first element of the array is set to the x component of the vector, and the second element of the array is set to the y component of the vector.

equals

public final boolean equals(java.lang.Object obj)
Compares the vector to another object. The result is true if the object is not null and is a Vec2f object and the components of the other Vec2f object are the same as the components of this vector.

The following example compares two vectors and prints the result to the console:

 Vec2f vec1 = ...;
 Vec2f vec2 = ...;
 System.out.println("Vectors are the same: " + vec1.equals(vec2));
 

Overrides:
equals in class java.lang.Object
Parameters:
obj - the object to compare the vector to
Returns:
true when the vectors are equal, false otherwise

toString

public final java.lang.String toString()
Converts the vector to a string. The string representation consists of the x component and the y component, separated by space characters.

The following example prints the string representation of a Vec2f object to the console:

 Vec2f vec = ...;
 System.out.println("Vector = " + vec.toString());
 

Overrides:
toString in class java.lang.Object
Returns:
A string representation of the vector

valueOf

public static final Vec2f valueOf(java.lang.String str)
Converts a string to a Vec2f object. The string must consist of the x and y components, separated by space characters.

The following example creates a new Vec2f object:

 Vec2f vec = Vec2f.valueOf("1.0 2.0");
 

Parameters:
str - The string representation of the vector.
Returns:
The new Vec2f object, parsed from the string.