org.openmali.vecmath2
Class TupleNf<T extends TupleNf<T>>

java.lang.Object
  extended by org.openmali.vecmath2.TupleNf<T>
Type Parameters:
T - the generic parameter for coefficients
All Implemented Interfaces:
TupleInterface<T>
Direct Known Subclasses:
Quaternion4f, Tuple2f, Tuple3f, VectorNf

public abstract class TupleNf<T extends TupleNf<T>>
extends java.lang.Object
implements TupleInterface<T>

This is a base-class for all float tuples like Tuple2f, Tuple3f, VectorNf, etc.


Field Summary
protected  boolean[] isDirty
           
protected  int roTrick
           
protected  float[] values
           
 
Constructor Summary
protected TupleNf(boolean readOnly, float[] values, boolean[] isDirty, int n, boolean copy)
          Creates a new TupleNf instance.
protected TupleNf(boolean readOnly, float[] values, int n)
          Creates a new TupleNf instance.
protected TupleNf(boolean readOnly, int n)
          Creates a new TupleNf instance.
protected TupleNf(boolean readOnly, TupleNf<?> that)
          Creates a new Tuple3f instance.
  TupleNf(float[] values, int n)
          Creates a new TupleNf instance.
  TupleNf(int n)
          Creates a new TupleNf instance.
  TupleNf(TupleNf<?> that)
          Creates a new Tuple3f instance.
 
Method Summary
 T absolute()
          Sets each component of the tuple parameter to its absolute value and places the modified values into this tuple.
 T absolute(T tuple)
          Sets each component of the tuple parameter to its absolute value and places the modified values into this tuple.
 T add(T tuple2)
          Sets the value of this tuple to the vector sum of itself and tuple t1.
 T add(T tuple1, T tuple2)
          Sets the value of this tuple to the vector sum of tuples t1 and t2.
 T addValue(int i, float v)
          Adds v to this tuple's i'th value.
abstract  T asReadOnly()
           
 T clamp(float min, float max)
          Clamps this tuple to the range [min, max].
 T clamp(float min, float max, T tuple)
          Clamps the tuple parameter to the range [min, max] and places the values into this tuple.
 T clampMax(float max)
          Clamps the maximum value of this tuple to the max parameter.
 T clampMax(float max, T tuple)
          Clamps the maximum value of the tuple parameter to the max parameter and places the values into this tuple.
 T clampMin(float min)
          Clamps the minimum value of this tuple to the min parameter.
 T clampMin(float min, T tuple)
          Clamps the minimum value of the tuple parameter to the min parameter and places the values into this tuple.
 int deserialize(int pos, byte[] buffer)
          Deserializes this instanc'es data from the byte array.
 T div(float v)
          Divides all components of this tuple by v.
 T divValue(int i, float v)
          Divides this tuple's i'th value by v.
 boolean epsilonEquals(T v2, float epsilon)
          Returns true if the L-infinite distance between this vector and vector v1 is less than or equal to the epsilon parameter, otherwise returns false.
 boolean equals(java.lang.Object o)
          
 boolean equals(T v2)
          Returns true if all of the data members of GVector vector1 are equal to the corresponding data members in this GVector.
 T fill(float f)
          Sets all values of this TupleNf to f.
 void get(float[] buffer)
          Writes all values of this Tuple to the specified buffer.
 void get(float[] buffer, int offset)
          Writes all values of this Tuple to the specified buffer.
 void get(TupleNf<?> buffer)
          Writes all values of this Tuple to the specified buffer Tuple.
abstract  T getReadOnly()
           
protected  int getSerializationBufferSize()
           
 int getSize()
          
 float getValue(int i)
          Sets the i-th value of this tuple.
 int hashCode()
          Returns a hash number based on the data values in this object.
 void interpolate(T t2, float alpha)
          Linearly interpolates between this tuple and tuple t2 and places the result into this tuple: this = (1 - alpha) * this + alpha * t1.
 void interpolate(T t1, T t2, float alpha)
          Linearly interpolates between tuples t1 and t2 and places the result into this tuple: this = (1 - alpha) * t1 + alpha * t2.
 boolean isDirty()
          
 boolean isReadOnly()
          
 T mul(float v)
          Multiplies all components of this tuple with v.
 T mulValue(int i, float v)
          Multiplies v to this tuple's i'th value.
 T negate()
          Negates the value of this vector in place.
 T negate(T tuple)
          Sets the value of this tuple to the negation of tuple that.
 void readExternal(java.io.ObjectInput in)
           
 java.nio.FloatBuffer readFromBuffer(java.nio.FloatBuffer buffer)
          Reads the contents for this tuple from a FloatBuffer.
 java.nio.FloatBuffer readFromBuffer(java.nio.FloatBuffer buffer, int position)
          Reads the contents for this tuple from a FloatBuffer.
static java.nio.FloatBuffer readFromBuffer(TupleNf<?>[] tuples, java.nio.FloatBuffer buffer)
          Reads the contents for this tuple from a FloatBuffer.
static java.nio.FloatBuffer readFromBuffer(TupleNf<?>[] tuples, java.nio.FloatBuffer buffer, int position)
          Reads the contents for this tuple from a FloatBuffer.
 T round(int decPlaces)
          Rounds this tuple to the given number of decimal places.
 T round(T tuple, int decPlaces)
          Rounds this tuple to the given number of decimal places.
 T scale(float factor)
          Sets the value of this tuple to the scalar multiplication of itself.
 T scale(float factor, T tuple)
          Sets the value of this tuple to the scalar multiplication of tuple t1.
 T scaleAdd(float factor, T tuple2)
          Sets the value of this tuple to the scalar multiplication of itself and then adds tuple t1 (this = s*this + t1).
 T scaleAdd(float factor, T tuple1, T 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.
 T set(float[] values)
          Sets all values of this Tuple to the specified ones.
 T set(float[] values, int offset)
          Sets all values of this Tuple to the specified ones.
 T set(TupleNf<?> tuple)
          Sets all three values of this Tuple to the specified ones.
 boolean setClean()
          Marks this tuple non-dirty.
 T setValue(int i, float v)
          Sets the i-th value of this tuple.
 T setZero()
          Sets all components to zero.
 T sub(T tuple2)
          Sets the value of this tuple to the vector difference of itself and tuple t1 (this = this - t1).
 T sub(T tuple1, T tuple2)
          Sets the value of this tuple to the vector difference of tuple t1 and t2 (this = t1 - t2).
 T subValue(int i, float v)
          Subtracts v of this tuple's i'th value.
 java.lang.String toString()
          Returns a string that contains the values of this Vector.
 void writeExternal(java.io.ObjectOutput out)
           
 java.nio.FloatBuffer writeToBuffer(java.nio.FloatBuffer buffer, boolean clear, boolean flip)
          Writes the contents of this tuple to a FloatBuffer.
 java.nio.FloatBuffer writeToBuffer(java.nio.FloatBuffer buffer, int position, boolean clear, boolean flip)
          Writes the contents of this tuple to a FloatBuffer.
static java.nio.FloatBuffer writeToBuffer(TupleNf<?>[] tuples, java.nio.FloatBuffer buffer, boolean clear, boolean flip)
          Writes the contents of this tuple to a FloatBuffer.
static java.nio.FloatBuffer writeToBuffer(TupleNf<?>[] tuples, java.nio.FloatBuffer buffer, int position, boolean clear, boolean flip)
          Writes the contents of this tuple to a FloatBuffer.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

values

protected final float[] values

roTrick

protected final int roTrick

isDirty

protected final boolean[] isDirty
Constructor Detail

TupleNf

protected TupleNf(boolean readOnly,
                  int n)
Creates a new TupleNf instance.

Parameters:
readOnly -
n - the number of elements

TupleNf

protected TupleNf(boolean readOnly,
                  float[] values,
                  boolean[] isDirty,
                  int n,
                  boolean copy)
Creates a new TupleNf instance.

Parameters:
readOnly -
values - the values array (must be at least size 3)
isDirty - the isDirty-value
n - the number of elements
copy - copy the array?

TupleNf

protected TupleNf(boolean readOnly,
                  float[] values,
                  int n)
Creates a new TupleNf instance.

Parameters:
readOnly -
values - the values array (must be at least size n)
n - the number of elements to copy

TupleNf

protected TupleNf(boolean readOnly,
                  TupleNf<?> that)
Creates a new Tuple3f instance.

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

TupleNf

public TupleNf(int n)
Creates a new TupleNf instance.

Parameters:
n - the number of elements

TupleNf

public TupleNf(float[] values,
               int n)
Creates a new TupleNf instance.

Parameters:
values - the values array (must be at least size n)
n - the number of elements to copy

TupleNf

public TupleNf(TupleNf<?> that)
Creates a new Tuple3f instance.

Parameters:
that - the TupleNf to copy the values from
Method Detail

isReadOnly

public final boolean isReadOnly()

Specified by:
isReadOnly in interface TupleInterface<T extends TupleNf<T>>
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.

Specified by:
setClean in interface TupleInterface<T extends TupleNf<T>>
Returns:
the old value

isDirty

public final boolean isDirty()

Specified by:
isDirty in interface TupleInterface<T extends TupleNf<T>>
Returns:
This tuple's dirty-flag

getSize

public final int getSize()

Specified by:
getSize in interface TupleInterface<T extends TupleNf<T>>
Returns:
this Tuple's size().

setValue

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

Specified by:
setValue in interface TupleInterface<T extends TupleNf<T>>
Returns:
itself

getValue

public final float getValue(int i)
Sets the i-th value of this tuple.

Specified by:
getValue in interface TupleInterface<T extends TupleNf<T>>

writeToBuffer

public final java.nio.FloatBuffer writeToBuffer(java.nio.FloatBuffer buffer,
                                                boolean clear,
                                                boolean flip)
Writes the contents of this tuple to a FloatBuffer.

Parameters:
buffer -
clear - clear the buffer before writing data?
flip - flip the buffer after writing data?

writeToBuffer

public final java.nio.FloatBuffer writeToBuffer(java.nio.FloatBuffer buffer,
                                                int position,
                                                boolean clear,
                                                boolean flip)
Writes the contents of this tuple to a FloatBuffer.

Parameters:
buffer -
position - position in the buffer
clear - clear the buffer before writing data?
flip - flip the buffer after writing data?

writeToBuffer

public static final java.nio.FloatBuffer writeToBuffer(TupleNf<?>[] tuples,
                                                       java.nio.FloatBuffer buffer,
                                                       boolean clear,
                                                       boolean flip)
Writes the contents of this tuple to a FloatBuffer.

Parameters:
tuples -
buffer -
clear - clear the buffer before writing data?
flip - flip the buffer after writing data?

writeToBuffer

public static final java.nio.FloatBuffer writeToBuffer(TupleNf<?>[] tuples,
                                                       java.nio.FloatBuffer buffer,
                                                       int position,
                                                       boolean clear,
                                                       boolean flip)
Writes the contents of this tuple to a FloatBuffer.

Parameters:
tuples -
buffer -
position - position in the buffer
clear - clear the buffer before writing data?
flip - flip the buffer after writing data?

readFromBuffer

public final java.nio.FloatBuffer readFromBuffer(java.nio.FloatBuffer buffer)
Reads the contents for this tuple from a FloatBuffer.

Parameters:
buffer -

readFromBuffer

public final java.nio.FloatBuffer readFromBuffer(java.nio.FloatBuffer buffer,
                                                 int position)
Reads the contents for this tuple from a FloatBuffer.

Parameters:
buffer -
position - position in the buffer

readFromBuffer

public static final java.nio.FloatBuffer readFromBuffer(TupleNf<?>[] tuples,
                                                        java.nio.FloatBuffer buffer)
Reads the contents for this tuple from a FloatBuffer.

Parameters:
buffer -

readFromBuffer

public static final java.nio.FloatBuffer readFromBuffer(TupleNf<?>[] tuples,
                                                        java.nio.FloatBuffer buffer,
                                                        int position)
Reads the contents for this tuple from a FloatBuffer.

Parameters:
buffer -
position - position in the buffer

fill

public final T fill(float f)
Sets all values of this TupleNf to f.

Specified by:
fill in interface TupleInterface<T extends TupleNf<T>>
Returns:
itself

addValue

public final T addValue(int i,
                        float v)
Adds v to this tuple's i'th value.

Specified by:
addValue in interface TupleInterface<T extends TupleNf<T>>
Parameters:
i - the index of the value to modify
v - modification amount
Returns:
itself

subValue

public final T subValue(int i,
                        float v)
Subtracts v of this tuple's i'th value.

Specified by:
subValue in interface TupleInterface<T extends TupleNf<T>>
Parameters:
i - the index of the value to modify
v - modification amount
Returns:
itself

mulValue

public final T mulValue(int i,
                        float v)
Multiplies v to this tuple's i'th value.

Specified by:
mulValue in interface TupleInterface<T extends TupleNf<T>>
Parameters:
i - the index of the value to modify
v - modification amount
Returns:
itself

mul

public final T mul(float v)
Multiplies all components of this tuple with v.

Specified by:
mul in interface TupleInterface<T extends TupleNf<T>>
Parameters:
v - modification amount
Returns:
itself

divValue

public final T divValue(int i,
                        float v)
Divides this tuple's i'th value by v.

Specified by:
divValue in interface TupleInterface<T extends TupleNf<T>>
Parameters:
i - the index of the value to modify
v - modification amount
Returns:
itself

div

public final T div(float v)
Divides all components of this tuple by v.

Specified by:
div in interface TupleInterface<T extends TupleNf<T>>
Parameters:
v - modification amount
Returns:
itself

set

public T set(float[] values,
             int offset)
Sets all values of this Tuple to the specified ones.

Specified by:
set in interface TupleInterface<T extends TupleNf<T>>
Parameters:
values - the values array (must be at least size getSize())
offset - the offset in the (source) values array
Returns:
itself

set

public T set(float[] values)
Sets all values of this Tuple to the specified ones.

Specified by:
set in interface TupleInterface<T extends TupleNf<T>>
Parameters:
values - the values array (must be at least size getSize())
Returns:
itself

set

public final T set(TupleNf<?> tuple)
Sets all three values of this Tuple to the specified ones.

Specified by:
set in interface TupleInterface<T extends TupleNf<T>>
Parameters:
tuple - the tuple to be copied
Returns:
itself

get

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

Specified by:
get in interface TupleInterface<T extends TupleNf<T>>
Parameters:
buffer - the buffer array to write the values to
offset - the offset in the (target) buffer array

get

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

Specified by:
get in interface TupleInterface<T extends TupleNf<T>>
Parameters:
buffer - the buffer array to write the values to

get

public final void get(TupleNf<?> buffer)
Writes all values of this Tuple to the specified buffer Tuple.

Specified by:
get in interface TupleInterface<T extends TupleNf<T>>
Parameters:
buffer - the buffer Tuple to write the values to

setZero

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

Specified by:
setZero in interface TupleInterface<T extends TupleNf<T>>
Returns:
itself

negate

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

Specified by:
negate in interface TupleInterface<T extends TupleNf<T>>
Returns:
itself

negate

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

Specified by:
negate in interface TupleInterface<T extends TupleNf<T>>
Parameters:
tuple - the source vector
Returns:
itself

absolute

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

Specified by:
absolute in interface TupleInterface<T extends TupleNf<T>>
Returns:
itself

absolute

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

Specified by:
absolute in interface TupleInterface<T extends TupleNf<T>>
Parameters:
tuple - the source tuple, which will not be modified
Returns:
itself

add

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

Specified by:
add in interface TupleInterface<T extends TupleNf<T>>
Parameters:
tuple1 - the first tuple
tuple2 - the second tuple
Returns:
itself

add

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

Specified by:
add in interface TupleInterface<T extends TupleNf<T>>
Parameters:
tuple2 - the other tuple
Returns:
itself

sub

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

Specified by:
sub in interface TupleInterface<T extends TupleNf<T>>
Parameters:
tuple1 - the first tuple
tuple2 - the second tuple
Returns:
itself

sub

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

Specified by:
sub in interface TupleInterface<T extends TupleNf<T>>
Parameters:
tuple2 - the other tuple
Returns:
itself

scale

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

Specified by:
scale in interface TupleInterface<T extends TupleNf<T>>
Parameters:
factor - the scalar value
tuple - the source tuple
Returns:
itself

scale

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

Specified by:
scale in interface TupleInterface<T extends TupleNf<T>>
Parameters:
factor - the scalar value
Returns:
itself

scaleAdd

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

Specified by:
scaleAdd in interface TupleInterface<T extends TupleNf<T>>
Parameters:
factor - the scalar value
tuple1 - the tuple to be multipled
tuple2 - the tuple to be added
Returns:
itself

scaleAdd

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

Specified by:
scaleAdd in interface TupleInterface<T extends TupleNf<T>>
Parameters:
factor - the scalar value
tuple2 - the tuple to be added
Returns:
itself

clampMin

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

Specified by:
clampMin in interface TupleInterface<T extends TupleNf<T>>
Parameters:
min - the lowest value in this tuple after clamping
Returns:
itself

clampMax

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

Specified by:
clampMax in interface TupleInterface<T extends TupleNf<T>>
Parameters:
max - the highest value in the tuple after clamping
Returns:
itself

clamp

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

Specified by:
clamp in interface TupleInterface<T extends TupleNf<T>>
Parameters:
min - the lowest value in this tuple after clamping
max - the highest value in this tuple after clamping
Returns:
itself

clamp

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

Specified by:
clamp in interface TupleInterface<T extends TupleNf<T>>
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 T clampMin(float min,
                        T tuple)
Clamps the minimum value of the tuple parameter to the min parameter and places the values into this tuple.

Specified by:
clampMin in interface TupleInterface<T extends TupleNf<T>>
Parameters:
min - the lowest value in the tuple after clamping
tuple - the source tuple, which will not be modified
Returns:
itself

clampMax

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

Specified by:
clampMax in interface TupleInterface<T extends TupleNf<T>>
Parameters:
max - the highest value in the tuple after clamping
tuple - the source tuple, which will not be modified
Returns:
itself

round

public final T round(T tuple,
                     int decPlaces)
Rounds this tuple to the given number of decimal places.

Specified by:
round in interface TupleInterface<T extends TupleNf<T>>
Returns:
itself

round

public final T round(int decPlaces)
Rounds this tuple to the given number of decimal places.

Specified by:
round in interface TupleInterface<T extends TupleNf<T>>
Returns:
itself

interpolate

public void interpolate(T t2,
                        float alpha)
Linearly interpolates between this tuple and tuple t2 and places the result into this tuple: this = (1 - alpha) * this + alpha * t1.

Specified by:
interpolate in interface TupleInterface<T extends TupleNf<T>>
Parameters:
t2 - the first tuple
alpha - the alpha interpolation parameter

interpolate

public final void interpolate(T t1,
                              T t2,
                              float alpha)
Linearly interpolates between tuples t1 and t2 and places the result into this tuple: this = (1 - alpha) * t1 + alpha * t2.

Specified by:
interpolate in interface TupleInterface<T extends TupleNf<T>>
Parameters:
t1 - the first tuple
t2 - the second tuple
alpha - the alpha interpolation parameter

asReadOnly

public abstract T asReadOnly()
Returns:
a new instance sharing the values array with this instance. The new instance is read-only. Changes to this instance will be reflected in the new read-only-instance.
See Also:
getReadOnly()

getReadOnly

public abstract T getReadOnly()
Returns:
a single instance sharing the values array with this instance (one unique instance per 'master-instance'). The instance is read-only. Changes to this instance will be reflected in the read-only-instance.
See Also:
asReadOnly()

equals

public boolean equals(T v2)
Returns true if all of the data members of GVector vector1 are equal to the corresponding data members in this GVector.

Parameters:
v2 - The vector with which the comparison is made.
Returns:
true or false

equals

public boolean equals(java.lang.Object o)

Overrides:
equals in class java.lang.Object

epsilonEquals

public boolean epsilonEquals(T v2,
                             float epsilon)
Returns true if the L-infinite distance between this vector and vector v1 is less than or equal to the epsilon parameter, otherwise returns false. The L-infinite distance is equal to MAX[abs(x1-x2), abs(y1-y2), . . . ].

Specified by:
epsilonEquals in interface TupleInterface<T extends TupleNf<T>>
Parameters:
v2 - The vector to be compared to this vector
epsilon - the threshold value

hashCode

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

Overrides:
hashCode in class java.lang.Object
Returns:
the integer hash value

toString

public java.lang.String toString()
Returns a string that contains the values of this Vector.

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

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
Throws:
java.io.IOException

readExternal

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