2 Copyright (C) 1997,1998,1999
3 Kenji Hiranabe, Eiwa System Management, Inc.
5 This program is free software.
6 Implemented by Kenji Hiranabe(hiranabe@esm.co.jp),
7 conforming to the Java(TM) 3D API specification by Sun Microsystems.
9 Permission to use, copy, modify, distribute and sell this software
10 and its documentation for any purpose is hereby granted without fee,
11 provided that the above copyright notice appear in all copies and
12 that both that copyright notice and this permission notice appear
13 in supporting documentation. Kenji Hiranabe and Eiwa System Management,Inc.
14 makes no representations about the suitability of this software for any
15 purpose. It is provided "AS IS" with NO WARRANTY.
20 * A generic 3 element tuple that is represented by double precision floating
21 * point x,y and z coordinates.
23 * @version specification 1.1, implementation $Revision: 1.9 $, $Date:
24 * 2006/07/28 17:01:32 $
25 * @author Kenji hiranabe
27 * additions by Bob Hanson hansonr@stolaf.edu 9/30/2012
28 * for unique constructor and method names
29 * for the optimization of compiled JavaScript using Java2Script.
32 public abstract class T3d {
49 * Constructs and initializes a Tuple3d to (0,0,0).
55 * Sets the value of this tuple to the specified xyz coordinates.
64 public final void set(double x, double y, double z) {
71 * Sets the value of this tuple from the 3 values specified in the array.
74 * the array of length 3 containing xyz in order
76 public final void setA(double t[]) {
77 // ArrayIndexOutOfBounds is thrown if t.length < 3
84 * Sets the value of this tuple to the value of the Tuple3d argument.
87 * the tuple to be copied
89 public final void setT(T3d t1) {
96 * Sets the value of this tuple to the vector sum of tuples t1 and t2.
103 public final void add2(T3d t1, T3d t2) {
110 * Sets the value of this tuple to the vector sum of itself and tuple t1.
115 public final void add(T3d t1) {
122 * Sets the value of this tuple to the vector difference of tuple t1 and t2
130 public final void sub2(T3d t1, T3d t2) {
137 * Sets the value of this tuple to the vector difference of itself and tuple
138 * t1 (this = this - t1).
143 public final void sub(T3d t1) {
150 * Sets the value of this tuple to the scalar multiplication of itself.
155 public final void scale(double s) {
162 * Sets the value of this tuple to the scalar multiplication of tuple t1 and
163 * then adds tuple t2 (this = s*t1 + t2).
168 * the tuple to be multipled
170 * the tuple to be added
172 public final void scaleAdd(double s, T3d t1, T3d t2) {
179 * Returns a hash number based on the data values in this object. Two
180 * different Tuple3d objects with identical data values (ie, returns true for
181 * equals(Tuple3d) ) will return the same hash number. Two vectors with
182 * different data members may return the same hash value, although this is not
186 public int hashCode() {
187 long xbits = doubleToLongBits0(x);
188 long ybits = doubleToLongBits0(y);
189 long zbits = doubleToLongBits0(z);
190 return (int) (xbits ^ (xbits >> 32) ^ ybits ^ (ybits >> 32) ^ zbits ^ (zbits >> 32));
193 static long doubleToLongBits0(double d) {
194 // Check for +0 or -0
195 return (d == 0 ? 0 : Double.doubleToLongBits(d));
199 * Returns true if all of the data members of Tuple3d t1 are equal to the
200 * corresponding data members in this
203 * the vector with which the comparison is made.
206 public boolean equals(Object t1) {
207 if (!(t1 instanceof T3d))
210 return (this.x == t2.x && this.y == t2.y && this.z == t2.z);
214 * Returns a string that contains the values of this Tuple3d. The form is
217 * @return the String representation
220 public String toString() {
221 return "{" + x + ", " + y + ", " + z + "}";