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.
19 import java.io.Serializable;
22 * A generic 3 element tuple that is represented by double precision floating
23 * point x,y and z coordinates.
25 * @version specification 1.1, implementation $Revision: 1.9 $, $Date:
26 * 2006/07/28 17:01:32 $
27 * @author Kenji hiranabe
29 * additions by Bob Hanson hansonr@stolaf.edu 9/30/2012
30 * for unique constructor and method names
31 * for the optimization of compiled JavaScript using Java2Script
33 public abstract class T3d implements Serializable {
50 * Constructs and initializes a Tuple3d to (0,0,0).
56 * Sets the value of this tuple to the specified xyz coordinates.
65 public final void set(double x, double y, double z) {
72 * Sets the value of this tuple from the 3 values specified in the array.
75 * the array of length 3 containing xyz in order
77 public final void setA(double t[]) {
78 // ArrayIndexOutOfBounds is thrown if t.length < 3
85 * Sets the value of this tuple to the value of the Tuple3d argument.
88 * the tuple to be copied
90 public final void setT(T3d t1) {
97 * Sets the value of this tuple to the vector sum of tuples t1 and t2.
104 public final void add2(T3d t1, T3d t2) {
111 * Sets the value of this tuple to the vector sum of itself and tuple t1.
116 public final void add(T3d t1) {
123 * Sets the value of this tuple to the vector difference of tuple t1 and t2
131 public final void sub2(T3d t1, T3d t2) {
138 * Sets the value of this tuple to the vector difference of itself and tuple
139 * t1 (this = this - t1).
144 public final void sub(T3d t1) {
151 * Sets the value of this tuple to the scalar multiplication of itself.
156 public final void scale(double s) {
163 * Sets the value of this tuple to the scalar multiplication of tuple t1 and
164 * then adds tuple t2 (this = s*t1 + t2).
169 * the tuple to be multipled
171 * the tuple to be added
173 public final void scaleAdd(double s, T3d t1, T3d t2) {
180 * Returns a hash number based on the data values in this object. Two
181 * different Tuple3d objects with identical data values (ie, returns true for
182 * equals(Tuple3d) ) will return the same hash number. Two vectors with
183 * different data members may return the same hash value, although this is not
187 public int hashCode() {
188 long xbits = doubleToLongBits0(x);
189 long ybits = doubleToLongBits0(y);
190 long zbits = doubleToLongBits0(z);
191 return (int) (xbits ^ (xbits >> 32) ^ ybits ^ (ybits >> 32) ^ zbits ^ (zbits >> 32));
194 static long doubleToLongBits0(double d) {
195 // Check for +0 or -0
196 return (d == 0 ? 0 : Double.doubleToLongBits(d));
200 * Returns true if all of the data members of Tuple3d t1 are equal to the
201 * corresponding data members in this
204 * the vector with which the comparison is made.
207 public boolean equals(Object t1) {
208 if (!(t1 instanceof T3d))
211 return (this.x == t2.x && this.y == t2.y && this.z == t2.z);
215 * Returns a string that contains the values of this Tuple3d. The form is
218 * @return the String representation
221 public String toString() {
222 return "{" + x + ", " + y + ", " + z + "}";