Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hierarchy to Tuples #4

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 101 additions & 0 deletions src/javax/vecmath/Tuple.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package javax.vecmath;

/**
* This is the top-level class of the hierarchy of Tuples. It specifies
* methods which accept as their arguments other Tuples of the same number
* and type as the Tuple on which the method is invoked, or methods which
* accept no arguments. Methods which accept primitives are specified by the
* subclasses of Tuple.
*
* @param <T> The type of this tuple as a subclass of Tuple; the number and
* type of primitives held by this Tuple are determined by this parameter.
* Subclasses of Tuple should provide themselves to fill this parameter.
*
* @since 1.6
*/
public abstract class Tuple<T extends Tuple<T>>
implements java.io.Serializable, Cloneable {

private static final long serialVersionUID = 2172728256449529639L;

/**
* Sets each component of this tuple to its absolute value.
*/
public abstract void absolute();

/**
* Sets each component of the tuple parameter to its absolute
* value and places the modified values into this tuple.
* @param t the source tuple, which will not be modified
*/
public abstract void absolute(T t);

/**
* Sets the value of this tuple to the vector sum of itself and tuple t1.
* @param t1 the other tuple
*/
public abstract void add(T t1);

/**
* Sets the value of this tuple to the vector sum of tuples t1 and t2.
* @param t1 the first tuple
* @param t2 the second tuple
*/
public abstract void add(T t1, T t2);

/**
* Gets the value of this tuple and copies the values into t.
* @param t the Tuple object into which the values of this object are copied
*/
public abstract void get(T t);

/**
* Negates the value of this tuple in place.
*/
public abstract void negate();

/**
* Sets the value of this tuple to the negation of tuple t1.
* @param t1 the source tuple
*/
public abstract void negate(T t);

/**
* Sets the value of this tuple to the value of tuple t1.
* @param t1 the tuple to be copied
*/
public abstract void set(T t);

/**
* Sets the value of this tuple to the vector difference of
* itself and tuple t1 (this = this - t1) .
* @param t1 the other tuple
*/
public abstract void sub(T t1);

/**
* Sets the value of this tuple to the vector difference
* of tuples t1 and t2 (this = t1 - t2).
* @param t1 the first tuple
* @param t2 the second tuple
*/
public abstract void sub(T t1, T t2);

/**
* Returns true if the data members of t1 are equal to the corresponding
* data members in this Tuple.
* @param t1 the tuple with which the comparison is made
* @return true or false
*/
public abstract boolean equals(T t);

public Object clone() {
try {
return super.clone();
} catch (CloneNotSupportedException e) {
// this shouldn't happen, since we are Cloneable
throw new InternalError();
}
}

}
34 changes: 13 additions & 21 deletions src/javax/vecmath/Tuple2d.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
* floating point x,y coordinates.
*
*/
public abstract class Tuple2d implements java.io.Serializable, Cloneable {
public abstract class Tuple2d extends Tupled<Tuple2d> {

static final long serialVersionUID = 6205762482756093838L;

Expand Down Expand Up @@ -157,6 +157,18 @@ public final void get(double[] t)
}


/**
* Copies the x and y coordinates of this tuple into the tuple t.
* @param t the Tuple2d object into which the values of this object are copied
* @since vecmath 1.6
*/
public final void get(Tuple2d t)
{
t.x = this.x;
t.y = this.y;
}


/**
* Sets the value of this tuple to the vector sum of tuples t1 and t2.
* @param t1 the first tuple
Expand Down Expand Up @@ -534,26 +546,6 @@ public final void interpolate(Tuple2d t1, double alpha)

}

/**
* Creates a new object of the same class as this object.
*
* @return a clone of this instance.
* @exception OutOfMemoryError if there is not enough memory.
* @see java.lang.Cloneable
* @since vecmath 1.3
*/
@Override
public Object clone() {
// Since there are no arrays we can just use Object.clone()
try {
return super.clone();
} catch (CloneNotSupportedException e) {
// this shouldn't happen, since we are Cloneable
throw new InternalError();
}
}


/**
* Get the <i>x</i> coordinate.
*
Expand Down
34 changes: 13 additions & 21 deletions src/javax/vecmath/Tuple2f.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
* floating point x,y coordinates.
*
*/
public abstract class Tuple2f implements java.io.Serializable, Cloneable {
public abstract class Tuple2f extends Tuplef<Tuple2f> {

static final long serialVersionUID = 9011180388985266884L;

Expand Down Expand Up @@ -159,6 +159,18 @@ public final void get(float[] t)
}


/**
* Copies the x and y coordinates of this tuple into the tuple t.
* @param t the Tuple2f object into which the values of this object are copied
* @since vecmath 1.6
*/
public final void get(Tuple2f t)
{
t.x = this.x;
t.y = this.y;
}


/**
* Sets the value of this tuple to the vector sum of tuples t1 and t2.
* @param t1 the first tuple
Expand Down Expand Up @@ -538,26 +550,6 @@ public final void interpolate(Tuple2f t1, float alpha)

}

/**
* Creates a new object of the same class as this object.
*
* @return a clone of this instance.
* @exception OutOfMemoryError if there is not enough memory.
* @see java.lang.Cloneable
* @since vecmath 1.3
*/
@Override
public Object clone() {
// Since there are no arrays we can just use Object.clone()
try {
return super.clone();
} catch (CloneNotSupportedException e) {
// this shouldn't happen, since we are Cloneable
throw new InternalError();
}
}


/**
* Get the <i>x</i> coordinate.
*
Expand Down
31 changes: 11 additions & 20 deletions src/javax/vecmath/Tuple2i.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
*
* @since vecmath 1.4
*/
public abstract class Tuple2i implements java.io.Serializable, Cloneable {
public abstract class Tuple2i extends Tuplei<Tuple2i> {

static final long serialVersionUID = -3555701650170169638L;

Expand Down Expand Up @@ -286,6 +286,16 @@ public boolean equals(Object t1) {
}


@Override
public boolean equals(Tuple2i t1) {
try {
return (this.x == t1.x && this.y == t1.y);
} catch (NullPointerException e2) {
return false;
}
}


/**
* Returns a hash code value based on the data values in this
* object. Two different Tuple2i objects with identical data values
Expand Down Expand Up @@ -436,25 +446,6 @@ public final void absolute() {
y = Math.abs(y);
}

/**
* Creates a new object of the same class as this object.
*
* @return a clone of this instance.
* @exception OutOfMemoryError if there is not enough memory.
* @see java.lang.Cloneable
*/
@Override
public Object clone() {
// Since there are no arrays we can just use Object.clone()
try {
return super.clone();
} catch (CloneNotSupportedException e) {
// this shouldn't happen, since we are Cloneable
throw new InternalError();
}
}


/**
* Get the <i>x</i> coordinate.
*
Expand Down
21 changes: 1 addition & 20 deletions src/javax/vecmath/Tuple3d.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
* floating point x,y,z coordinates.
*
*/
public abstract class Tuple3d implements java.io.Serializable, Cloneable {
public abstract class Tuple3d extends Tupled<Tuple3d> {

static final long serialVersionUID = 5542096614926168415L;

Expand Down Expand Up @@ -665,25 +665,6 @@ public final void interpolate(Tuple3d t1, double alpha) {
this.z = (1-alpha)*this.z + alpha*t1.z;
}

/**
* Creates a new object of the same class as this object.
*
* @return a clone of this instance.
* @exception OutOfMemoryError if there is not enough memory.
* @see java.lang.Cloneable
* @since vecmath 1.3
*/
@Override
public Object clone() {
// Since there are no arrays we can just use Object.clone()
try {
return super.clone();
} catch (CloneNotSupportedException e) {
// this shouldn't happen, since we are Cloneable
throw new InternalError();
}
}

/**
* Get the <i>x</i> coordinate.
*
Expand Down
Loading