Fixed issues with compilation.
[IRC.git] / Robust / src / Benchmarks / Scheduling / GC / NON_BAMBOO / RayTracer / Vec.java
1 package RayTracer;
2
3 /**************************************************************************
4  *                                                                         *
5  *             Java Grande Forum Benchmark Suite - Version 2.0             *
6  *                                                                         *
7  *                            produced by                                  *
8  *                                                                         *
9  *                  Java Grande Benchmarking Project                       *
10  *                                                                         *
11  *                                at                                       *
12  *                                                                         *
13  *                Edinburgh Parallel Computing Centre                      *
14  *                                                                         *
15  *                email: epcc-javagrande@epcc.ed.ac.uk                     *
16  *                                                                         *
17  *                 Original version of this code by                        *
18  *            Florian Doyon (Florian.Doyon@sophia.inria.fr)                *
19  *              and  Wilfried Klauser (wklauser@acm.org)                   *
20  *                                                                         *
21  *      This version copyright (c) The University of Edinburgh, 1999.      *
22  *                         All rights reserved.                            *
23  *                                                                         *
24  **************************************************************************/
25
26
27
28
29 /**
30  * This class reflects the 3d vectors used in 3d computations
31  */
32 public class Vec
33 //implements java.io.Serializable 
34 {
35
36   /**
37    * The x coordinate
38    */
39   public float x; 
40
41   /**
42    * The y coordinate
43    */
44   public float y;
45
46   /**
47    * The z coordinate
48    */
49   public float z;
50
51   /**
52    * Constructor
53    * @param a the x coordinate
54    * @param b the y coordinate
55    * @param c the z coordinate
56    */
57   public Vec(float a, float b, float c) {
58     x = a;
59     y = b;
60     z = c;
61   }
62
63   /**
64    * Copy constructor
65    */
66   public Vec(Vec a) {
67     x = a.x;
68     y = a.y;
69     z = a.z;
70   }
71   /**
72    * Default (0,0,0) constructor
73    */
74   public Vec() {
75     x = (float) 0.0;
76     y = (float) 0.0; 
77     z = (float) 0.0;
78   }
79
80   /**
81    * Add a vector to the current vector
82    * @param: a The vector to be added
83    */
84   public final void add(Vec a) {
85     x+=a.x;
86     y+=a.y;
87     z+=a.z;
88   }  
89
90   /**
91    * adds: Returns a new vector such as
92    * new = sA + B
93    */
94   public static Vec adds(float s, Vec a, Vec b) {
95     return new Vec(s * a.x + b.x, s * a.y + b.y, s * a.z + b.z);
96   }
97
98   /**
99    * Adds vector such as:
100    * this+=sB
101    * @param: s The multiplier
102    * @param: b The vector to be added
103    */
104   public final void adds(float s,Vec b){
105     x+=s*b.x;
106     y+=s*b.y;
107     z+=s*b.z;
108   }
109
110   /**
111    * Substracs two vectors
112    */
113   public static Vec sub(Vec a, Vec b) {
114     return new Vec(a.x - b.x, a.y - b.y, a.z - b.z);
115   }
116
117   /**
118    * Substracts two vects and places the results in the current vector
119    * Used for speedup with local variables -there were too much Vec to be gc'ed
120    * Consumes about 10 units, whether sub consumes nearly 999 units!! 
121    * cf thinking in java p. 831,832
122    */
123   public final void sub2(Vec a,Vec b) {
124     this.x=a.x-b.x;
125     this.y=a.y-b.y;
126     this.z=a.z-b.z;
127   }
128
129   public static Vec mult(Vec a, Vec b) {
130     return new Vec(a.x * b.x, a.y * b.y, a.z * b.z);
131   }
132
133   public static Vec cross(Vec a, Vec b) {
134     return
135         new Vec(a.y*b.z - a.z*b.y,
136             a.z*b.x - a.x*b.z,
137             a.x*b.y - a.y*b.x);
138   }
139
140   public static float dot(Vec a, Vec b) {
141     return a.x*b.x + a.y*b.y + a.z*b.z;
142   }
143
144   public static Vec comb(float a, Vec A, float b, Vec B) {
145     return
146         new Vec(a * A.x + b * B.x,
147             a * A.y + b * B.y,
148             a * A.z + b * B.z);
149   }
150
151   public final void comb2(float a,Vec A,float b,Vec B) {
152     x=a * A.x + b * B.x;
153     y=a * A.y + b * B.y;
154     z=a * A.z + b * B.z;      
155   }
156
157   public final void scale(float t) {
158     x *= t;
159     y *= t;
160     z *= t;
161   }
162
163   public final void negate() {
164     x = -x;
165     y = -y;
166     z = -z;
167   }
168
169   public final float normalize() {
170     float len;
171     len =(float)  Math.sqrt(x*x + y*y + z*z);
172     if (len > 0.0) {
173       x /= len;
174       y /= len;
175       z /= len;
176     }
177     return len;
178   }
179
180   public final String toString() {
181     return "<" + x + "," + y + "," + z + ">";
182   }
183 }