JAL-1807 Bob's first commit -- Applet loaded; needs image
[jalview.git] / src / javajs / util / T3i.java
1 /*
2    Copyright (C) 1997,1998,1999
3    Kenji Hiranabe, Eiwa System Management, Inc.
4
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.
8
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.
16 */
17 package javajs.util;
18
19 import java.io.Serializable;
20
21 /**
22  * A 3-element tuple represented by signed integer x,y,z coordinates.
23  * 
24  * @since Java 3D 1.2
25  * @version specification 1.2, implementation $Revision: 1.9 $, $Date:
26  *          2006/07/28 17:01:32 $
27  * @author Kenji hiranabe
28  * 
29  *         additions by Bob Hanson hansonr@stolaf.edu 9/30/2012 for unique
30  *         constructor and method names for the optimization of compiled
31  *         JavaScript using Java2Script
32  */
33 public abstract class T3i implements Serializable {
34
35   /**
36    * The x coordinate.
37    */
38   public int x;
39
40   /**
41    * The y coordinate.
42    */
43   public int y;
44
45   /**
46    * The z coordinate.
47    */
48   public int z;
49
50   /**
51    * Constructs and initializes a Tuple3i to (0,0,0).
52    */
53   public T3i() {
54   }
55
56   /**
57    * Sets the value of this tuple to to the specified x, y, and z coordinates.
58    * 
59    * @param x
60    *        the x coordinate.
61    * @param y
62    *        the y coordinate.
63    * @param z
64    *        the z coordinate.
65    */
66   public final void set(int x, int y, int z) {
67     this.x = x;
68     this.y = y;
69     this.z = z;
70   }
71
72   /**
73    * Sets the value of this tuple to the value of tuple t1.
74    * 
75    * @param t1
76    *        the tuple to be copied.
77    */
78   public final void setT(T3i t1) {
79     x = t1.x;
80     y = t1.y;
81     z = t1.z;
82   }
83
84   /**
85    * Sets the value of this tuple to the sum of itself and t1.
86    * 
87    * @param t
88    *        is the other tuple
89    */
90   public final void add(T3i t) {
91     x += t.x;
92     y += t.y;
93     z += t.z;
94   }
95
96   /**
97    * Sets the value of this tuple to the scalar multiplication of tuple t1 plus
98    * tuple t2 (this = s*t1 + t2).
99    * 
100    * @param s
101    *        the scalar value
102    * @param t1
103    *        the tuple to be multipled
104    * @param t2
105    *        the tuple to be added
106    */
107   public final void scaleAdd(int s, T3i t1, T3i t2) {
108     x = s * t1.x + t2.x;
109     y = s * t1.y + t2.y;
110     z = s * t1.z + t2.z;
111   }
112
113   /**
114    * Returns a hash number based on the data values in this object. Two
115    * different Tuple3i objects with identical data values (ie, returns true for
116    * equals(Tuple3i) ) will return the same hash number. Two vectors with
117    * different data members may return the same hash value, although this is not
118    * likely.
119    */
120   @Override
121   public int hashCode() {
122     return x ^ y ^ z;
123   }
124
125   /**
126    * Returns true if the Object o is of type Tuple3i and all of the data members
127    * of t are equal to the corresponding data members in this Tuple3i.
128    * 
129    * @param o
130    *        the object with which the comparison is made.
131    */
132   @Override
133   public boolean equals(Object o) {
134     if (!(o instanceof T3i))
135       return false;
136     T3i t = (T3i) o;
137     return (this.x == t.x && this.y == t.y && this.z == t.z);
138   }
139
140   /**
141    * Returns a string that contains the values of this Tuple3i. The form is
142    * (x,y,z).
143    * 
144    * @return the String representation
145    */
146   @Override
147   public String toString() {
148     return "(" + x + ", " + y + ", " + z + ")";
149   }
150
151 }