org.openmali.vecmath2
Class Tuple2i

java.lang.Object
  extended by org.openmali.vecmath2.Tuple2i
All Implemented Interfaces:
java.io.Externalizable, java.io.Serializable
Direct Known Subclasses:
Point2i, Vector2i

public class Tuple2i
extends java.lang.Object
implements java.io.Externalizable

A simple two-dimensional tuple implementation. Inspired by Kenji Hiranabe's Tuple2i implementation

Author:
Marvin Froehlich (aka Qudus)
See Also:
Serialized Form

Field Summary
protected static int N
           
protected  int roTrick
           
protected  int[] values
           
 
Constructor Summary
  Tuple2i()
          Creates a new Tuple2i instance.
protected Tuple2i(boolean readOnly)
          Creates a new Tuple2i instance.
protected Tuple2i(boolean readOnly, int[] values)
          Creates a new Tuple2i instance.
protected Tuple2i(boolean readOnly, int x, int y)
          Creates a new Tuple2i instance.
protected Tuple2i(boolean readOnly, Tuple2i that)
          Creates a new Tuple2i instance.
  Tuple2i(int[] values)
          Creates a new Tuple2i instance.
  Tuple2i(int x, int y)
          Creates a new Tuple2i instance.
  Tuple2i(Tuple2i that)
          Creates a new Tuple2i instance.
 
Method Summary
 Tuple2i absolute()
          Sets each component of the tuple parameter to its absolute value and places the modified values into this tuple.
 Tuple2i absolute(Tuple2i tuple)
          Sets each component of the tuple parameter to its absolute value and places the modified values into this tuple.
 Tuple2i add(int x, int y)
          Adds the given parameters to this tuple's values.
 Tuple2i add(Tuple2i tuple2)
          Sets the value of this tuple to the vector sum of itself and tuple t1.
 Tuple2i add(Tuple2i tuple1, Tuple2i tuple2)
          Sets the value of this tuple to the vector sum of tuples t1 and t2.
 Tuple2i addX(int v)
          Adds v to this tuple's x value.
 Tuple2i addY(int v)
          Adds v to this tuple's y value.
 Tuple2i clamp(int min, int max)
          Clamps this tuple to the range [min, max].
 Tuple2i clamp(int min, int max, Tuple2i tuple)
          Clamps the tuple parameter to the range [min, max] and places the values into this tuple.
 Tuple2i clampMax(int max)
          Clamps the maximum value of this tuple to the max parameter.
 Tuple2i clampMax(int max, Tuple2i tuple)
          Clamps the maximum value of the tuple parameter to the max parameter and places the values into this tuple.
 Tuple2i clampMin(int min)
          Clamps the minimum value of this tuple to the min parameter.
 Tuple2i clampMin(int min, Tuple2i tuple)
          Clamps the minimum value of the tuple parameter to the min parameter and places the values into this tuple.
 Tuple2i clone()
          Creates and returns a copy of this object.
 int deserialize(int pos, byte[] buffer)
          Deserializes this instanc'es data from the byte array.
 Tuple2i div(int vx, int vy)
          Divides this tuple's values by vx, vy, vz.
 Tuple2i divX(int v)
          Divides this tuple's x value by v.
 Tuple2i divY(int v)
          Divides this tuple's y value by v.
 boolean equals(java.lang.Object tuple2)
          Returns true if the Object t1 is of type Tuple3f and all of the data members of t1 are equal to the corresponding data members in this Tuple2f.
 boolean equals(Tuple2i tuple2)
          Returns true if all of the data members of Tuple3f t1 are equal to the corresponding data members in this
static Tuple2i fromPool()
          Allocates an Tuple2i instance from the pool.
static Tuple2i fromPool(int x, int y)
          Allocates an Tuple2i instance from the pool.
static Tuple2i fromPool(Tuple2i tuple)
          Allocates an Tuple2i instance from the pool.
 void get(int[] buffer)
          Writes all values of this Tuple to the specified buffer.
 void get(Tuple2i buffer)
          Writes all values of this Tuple to the specified buffer Tuple.
protected  int getSerializationBufferSize()
           
 int getSize()
           
 int getValue(int i)
           
 int getX()
           
 int getY()
           
 int hashCode()
          Returns a hash number based on the data values in this object.
 boolean isDirty()
           
 boolean isReadOnly()
           
 Tuple2i mul(int vx, int vy)
          Multiplies this tuple's values with vx, vy.
 Tuple2i mulX(int v)
          Multiplies this tuple's x value with v.
 Tuple2i mulY(int v)
          Multiplies this tuple's y value with v.
 Tuple2i negate()
          Negates the value of this vector in place.
 Tuple2i negate(Tuple2i tuple)
          Sets the value of this tuple to the negation of tuple that.
static Tuple2i newReadOnly()
          Creates a new Tuple2i instance.
static Tuple2i newReadOnly(int[] values)
          Creates a new Tuple2i instance.
static Tuple2i newReadOnly(int x, int y)
          Creates a new Tuple2i instance.
static Tuple2i newReadOnly(Tuple2i tuple)
          Creates a new Tuple2i instance.
 void readExternal(java.io.ObjectInput in)
           
 Tuple2i scale(int factor)
          Sets the value of this tuple to the scalar multiplication of itself.
 Tuple2i scale(int factorX, int factorY)
          Sets the value of this tuple to the scalar multiplication of tuple t1.
 Tuple2i scale(int factor, Tuple2i tuple)
          Sets the value of this tuple to the scalar multiplication of tuple t1.
 Tuple2i scaleAdd(int factor, Tuple2i tuple2)
          Sets the value of this tuple to the scalar multiplication of itself and then adds tuple t1 (this = s*this + t1).
 Tuple2i scaleAdd(int factor, Tuple2i tuple1, Tuple2i tuple2)
          Sets the value of this tuple to the scalar multiplication of tuple t1 and then adds tuple t2 (this = s*t1 + t2).
 int serialize(int pos, byte[] buffer)
          Serializes this instanc'es data into the byte array.
 Tuple2i set(int[] values)
          Sets all values of this Tuple to the specified ones.
 Tuple2i set(int x, int y)
          Sets all three values of this Tuple to the specified ones.
 Tuple2i set(Tuple2i tuple)
          Sets all three values of this Tuple to the specified ones.
 boolean setClean()
          Marks this tuple non-dirty.
 Tuple2i setValue(int i, int v)
          Sets the value of the i-th element of this tuple.
 Tuple2i setX(int x)
          Sets the value of the x-element of this tuple.
 Tuple2i setY(int y)
          Sets the value of the y-element of this tuple.
 Tuple2i setZero()
          Sets all components to zero.
 Tuple2i sub(int x, int y)
          Subtracts the given parameters from this tuple's values.
 Tuple2i sub(Tuple2i tuple2)
          Sets the value of this tuple to the vector difference of itself and tuple t1 (this = this - t1).
 Tuple2i sub(Tuple2i tuple1, Tuple2i tuple2)
          Sets the value of this tuple to the vector difference of tuple t1 and t2 (this = t1 - t2).
 Tuple2i subX(int v)
          Subtracts v from this tuple's x value.
 Tuple2i subY(int v)
          Subtracts v from this tuple's y value.
static void toPool(Tuple2i o)
          Stores the given Tuple2i instance in the pool.
 java.lang.String toString()
          Returns a string that contains the values of this Tuple2f.
 void writeExternal(java.io.ObjectOutput out)
           
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

N

protected static final int N
See Also:
Constant Field Values

values

protected final int[] values

roTrick

protected final int roTrick
Constructor Detail

Tuple2i

protected Tuple2i(boolean readOnly,
                  int x,
                  int y)
Creates a new Tuple2i instance.

Parameters:
readOnly -
x - the x element to use
y - the y element to use

Tuple2i

protected Tuple2i(boolean readOnly,
                  int[] values)
Creates a new Tuple2i instance.

Parameters:
readOnly -
values - the values array (must be at least size 2)

Tuple2i

protected Tuple2i(boolean readOnly,
                  Tuple2i that)
Creates a new Tuple2i instance.

Parameters:
readOnly -
that - the Tuple2i to copy the values from

Tuple2i

protected Tuple2i(boolean readOnly)
Creates a new Tuple2i instance.

Parameters:
readOnly -

Tuple2i

public Tuple2i(int x,
               int y)
Creates a new Tuple2i instance.

Parameters:
x - the x element to use
y - the y element to use

Tuple2i

public Tuple2i(int[] values)
Creates a new Tuple2i instance.

Parameters:
values - the values array (must be at least size 2)

Tuple2i

public Tuple2i(Tuple2i that)
Creates a new Tuple2i instance.

Parameters:
that - the Tuple2i to copy the values from

Tuple2i

public Tuple2i()
Creates a new Tuple2i instance.

Method Detail

isReadOnly

public final boolean isReadOnly()
Returns:
Is this tuple a read-only one?

setClean

public final boolean setClean()
Marks this tuple non-dirty. Any value-manipulation will mark it dirty again.

Returns:
the old value

isDirty

public final boolean isDirty()
Returns:
This tuple's dirty-flag

getSize

public final int getSize()
Returns:
this Tuple's size().

setValue

public final Tuple2i setValue(int i,
                              int v)
Sets the value of the i-th element of this tuple.

Parameters:
i -
v -
Returns:
itself

getValue

public final int getValue(int i)
Returns:
the value of the i-th element of this tuple.

setX

public final Tuple2i setX(int x)
Sets the value of the x-element of this tuple.

Parameters:
x -
Returns:
itself

setY

public final Tuple2i setY(int y)
Sets the value of the y-element of this tuple.

Parameters:
y -
Returns:
itself

getX

public final int getX()
Returns:
the value of the x-element of this tuple.

getY

public final int getY()
Returns:
the value of the y-element of this tuple.

set

public final Tuple2i set(int x,
                         int y)
Sets all three values of this Tuple to the specified ones.

Parameters:
x - the x element to use
y - the y element to use
Returns:
itself

set

public final Tuple2i set(int[] values)
Sets all values of this Tuple to the specified ones.

Parameters:
values - the values array (must be at least size 3)
Returns:
itself

set

public final Tuple2i set(Tuple2i tuple)
Sets all three values of this Tuple to the specified ones.

Parameters:
tuple - the tuple to be copied
Returns:
itself

get

public final void get(int[] buffer)
Writes all values of this Tuple to the specified buffer.

Parameters:
buffer - the buffer array to write the values to

get

public final void get(Tuple2i buffer)
Writes all values of this Tuple to the specified buffer Tuple.

Parameters:
buffer - the buffer Tuple to write the values to

setZero

public final Tuple2i setZero()
Sets all components to zero.

Returns:
itself

negate

public final Tuple2i negate(Tuple2i tuple)
Sets the value of this tuple to the negation of tuple that.

Parameters:
tuple - the source vector
Returns:
itself

negate

public final Tuple2i negate()
Negates the value of this vector in place.

Returns:
itself

absolute

public final Tuple2i absolute()
Sets each component of the tuple parameter to its absolute value and places the modified values into this tuple.

Returns:
itself

absolute

public final Tuple2i absolute(Tuple2i tuple)
Sets each component of the tuple parameter to its absolute value and places the modified values into this tuple.

Parameters:
tuple - the source tuple, which will not be modified
Returns:
itself

addX

public final Tuple2i addX(int v)
Adds v to this tuple's x value.

Parameters:
v -
Returns:
itself

addY

public final Tuple2i addY(int v)
Adds v to this tuple's y value.

Parameters:
v -
Returns:
itself

add

public final Tuple2i add(int x,
                         int y)
Adds the given parameters to this tuple's values.

Parameters:
x -
y -
Returns:
itself

subX

public final Tuple2i subX(int v)
Subtracts v from this tuple's x value.

Parameters:
v -
Returns:
itself

subY

public final Tuple2i subY(int v)
Subtracts v from this tuple's y value.

Parameters:
v -
Returns:
itself

sub

public final Tuple2i sub(int x,
                         int y)
Subtracts the given parameters from this tuple's values.

Parameters:
x -
y -
Returns:
itself

mulX

public final Tuple2i mulX(int v)
Multiplies this tuple's x value with v.

Parameters:
v -
Returns:
itself

mulY

public final Tuple2i mulY(int v)
Multiplies this tuple's y value with v.

Parameters:
v -
Returns:
itself

mul

public final Tuple2i mul(int vx,
                         int vy)
Multiplies this tuple's values with vx, vy.

Parameters:
vx -
vy -
Returns:
itself

divX

public final Tuple2i divX(int v)
Divides this tuple's x value by v.

Parameters:
v -
Returns:
itself

divY

public final Tuple2i divY(int v)
Divides this tuple's y value by v.

Parameters:
v -
Returns:
itself

div

public final Tuple2i div(int vx,
                         int vy)
Divides this tuple's values by vx, vy, vz.

Parameters:
vx -
vy -
Returns:
itself

add

public final Tuple2i add(Tuple2i tuple1,
                         Tuple2i tuple2)
Sets the value of this tuple to the vector sum of tuples t1 and t2.

Parameters:
tuple1 - the first tuple
tuple2 - the second tuple
Returns:
itself

add

public final Tuple2i add(Tuple2i tuple2)
Sets the value of this tuple to the vector sum of itself and tuple t1.

Parameters:
tuple2 - the other tuple
Returns:
itself

sub

public final Tuple2i sub(Tuple2i tuple1,
                         Tuple2i tuple2)
Sets the value of this tuple to the vector difference of tuple t1 and t2 (this = t1 - t2).

Parameters:
tuple1 - the first tuple
tuple2 - the second tuple
Returns:
itself

sub

public final Tuple2i sub(Tuple2i tuple2)
Sets the value of this tuple to the vector difference of itself and tuple t1 (this = this - t1).

Parameters:
tuple2 - the other tuple
Returns:
itself

scale

public final Tuple2i scale(int factorX,
                           int factorY)
Sets the value of this tuple to the scalar multiplication of tuple t1.

Parameters:
factorX -
factorY -
Returns:
itself

scale

public final Tuple2i scale(int factor,
                           Tuple2i tuple)
Sets the value of this tuple to the scalar multiplication of tuple t1.

Parameters:
factor - the scalar value
tuple - the source tuple
Returns:
itself

scale

public final Tuple2i scale(int factor)
Sets the value of this tuple to the scalar multiplication of itself.

Parameters:
factor - the scalar value
Returns:
itself

scaleAdd

public final Tuple2i scaleAdd(int factor,
                              Tuple2i tuple1,
                              Tuple2i tuple2)
Sets the value of this tuple to the scalar multiplication of tuple t1 and then adds tuple t2 (this = s*t1 + t2).

Parameters:
factor - the scalar value
tuple1 - the tuple to be multipled
tuple2 - the tuple to be added
Returns:
itself

scaleAdd

public final Tuple2i scaleAdd(int factor,
                              Tuple2i tuple2)
Sets the value of this tuple to the scalar multiplication of itself and then adds tuple t1 (this = s*this + t1).

Parameters:
factor - the scalar value
tuple2 - the tuple to be added
Returns:
itself

clampMin

public final Tuple2i clampMin(int min)
Clamps the minimum value of this tuple to the min parameter.

Parameters:
min - the lowest value in this tuple after clamping
Returns:
itself

clampMax

public final Tuple2i clampMax(int max)
Clamps the maximum value of this tuple to the max parameter.

Parameters:
max - the highest value in the tuple after clamping
Returns:
itself

clamp

public final Tuple2i clamp(int min,
                           int max)
Clamps this tuple to the range [min, max].

Parameters:
min - the lowest value in this tuple after clamping
max - the highest value in this tuple after clamping
Returns:
itself

clamp

public final Tuple2i clamp(int min,
                           int max,
                           Tuple2i tuple)
Clamps the tuple parameter to the range [min, max] and places the values into this tuple.

Parameters:
min - the lowest value in the tuple after clamping
max - the highest value in the tuple after clamping
tuple - the source tuple, which will not be modified
Returns:
itself

clampMin

public final Tuple2i clampMin(int min,
                              Tuple2i tuple)
Clamps the minimum value of the tuple parameter to the min parameter and places the values into this tuple.

Parameters:
min - the lowest value in the tuple after clamping
tuple - the source tuple, which will not be modified
Returns:
itself

clampMax

public final Tuple2i clampMax(int max,
                              Tuple2i tuple)
Clamps the maximum value of the tuple parameter to the max parameter and places the values into this tuple.

Parameters:
max - the highest value in the tuple after clamping
tuple - the source tuple, which will not be modified
Returns:
itself

hashCode

public int hashCode()
Returns a hash number based on the data values in this object. Two different Tuple3f objects with identical data values (ie, returns true for equals(Tuple3f) ) will return the same hash number. Two vectors with different data members may return the same hash value, although this is not likely.

Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(Tuple2i tuple2)
Returns true if all of the data members of Tuple3f t1 are equal to the corresponding data members in this

Parameters:
tuple2 - the vector with which the comparison is made.

equals

public boolean equals(java.lang.Object tuple2)
Returns true if the Object t1 is of type Tuple3f and all of the data members of t1 are equal to the corresponding data members in this Tuple2f.

Overrides:
equals in class java.lang.Object
Parameters:
tuple2 - the Object with which the comparison is made
Returns:
true or false

toString

public java.lang.String toString()
Returns a string that contains the values of this Tuple2f. The form is (x, y).

Overrides:
toString in class java.lang.Object
Returns:
the String representation

clone

public Tuple2i clone()
Creates and returns a copy of this object.

Overrides:
clone in class java.lang.Object
Returns:
a clone of this instance.
Throws:
java.lang.OutOfMemoryError - if there is not enough memory.
See Also:
Cloneable

serialize

public int serialize(int pos,
                     byte[] buffer)
Serializes this instanc'es data into the byte array.

Parameters:
pos -
buffer -
Returns:
the incremented position

deserialize

public int deserialize(int pos,
                       byte[] buffer)
Deserializes this instanc'es data from the byte array.

Parameters:
pos -
buffer -
Returns:
the incremented position

getSerializationBufferSize

protected int getSerializationBufferSize()
Returns:
the necessary size for a serialization byte array.

writeExternal

public void writeExternal(java.io.ObjectOutput out)
                   throws java.io.IOException
Specified by:
writeExternal in interface java.io.Externalizable
Throws:
java.io.IOException

readExternal

public void readExternal(java.io.ObjectInput in)
                  throws java.io.IOException,
                         java.lang.ClassNotFoundException
Specified by:
readExternal in interface java.io.Externalizable
Throws:
java.io.IOException
java.lang.ClassNotFoundException

newReadOnly

public static Tuple2i newReadOnly(int x,
                                  int y)
Creates a new Tuple2i instance.

Parameters:
x - the x element to use
y - the y element to use

newReadOnly

public static Tuple2i newReadOnly(int[] values)
Creates a new Tuple2i instance.

Parameters:
values - the values array (must be at least size 2)

newReadOnly

public static Tuple2i newReadOnly(Tuple2i tuple)
Creates a new Tuple2i instance.

Parameters:
tuple - the Tuple2f to copy the values from

newReadOnly

public static Tuple2i newReadOnly()
Creates a new Tuple2i instance.


fromPool

public static Tuple2i fromPool()
Allocates an Tuple2i instance from the pool.


fromPool

public static Tuple2i fromPool(int x,
                               int y)
Allocates an Tuple2i instance from the pool.


fromPool

public static Tuple2i fromPool(Tuple2i tuple)
Allocates an Tuple2i instance from the pool.


toPool

public static void toPool(Tuple2i o)
Stores the given Tuple2i instance in the pool.

Parameters:
o -