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