Ported over bamboo benchmarks for use as non-Bamboo java benchmarks.
[IRC.git] / Robust / src / Benchmarks / Scheduling / GC / NON_BAMBOO / voronoi / Vec2.java
1
2
3 /**
4  * Vector Routines from CMU vision library.  
5  * They are used only for the Voronoi Diagram, not the Delaunay Triagulation.
6  * They are slow because of large call-by-value parameters.
7  **/
8 class Vec2 
9 {
10   float x,y;
11   float norm;
12
13   public Vec2() {}
14   
15   public Vec2(float xx, float yy) 
16   {
17     x = xx;
18     y = yy;
19     norm =  (float)(x*x + y*y);
20   }
21
22   public float X()
23   {
24     return x;
25   }
26
27   public float Y()
28   {
29     return y;
30   }
31
32   public float Norm()
33   {
34     return norm;
35   }
36   
37   public void setNorm(float d)
38   {
39     norm = d;
40   }
41
42   /*public String toString()
43   {
44     return x + " " + y;
45   }*/
46
47   Vec2 circle_center(Vec2 b, Vec2 c)
48   {
49     Vec2 vv1 = b.sub(c);
50     float d1 = vv1.magn();
51     vv1 = sum(b);
52     Vec2 vv2 = vv1.times(0.5f);
53     if (d1 < 0.0) /*there is no intersection point, the bisectors coincide. */
54       return(vv2);
55     else {
56       Vec2 vv3 = b.sub(this);
57       Vec2 vv4 = c.sub(this); 
58       float d3 = vv3.cprod(vv4) ;
59       float d2 = (float)(-2.0f * d3) ;
60       Vec2 vv5 = c.sub(b);
61       float d4 = vv5.dot(vv4);
62       Vec2 vv6 = vv3.cross();
63       Vec2 vv7 = vv6.times((float)(d4/d2));
64       return vv2.sum(vv7);
65     }
66   }
67
68
69
70   /**
71    * cprod: forms triple scalar product of [u,v,k], where k = u cross v 
72    * (returns the magnitude of u cross v in space)
73    **/
74   float cprod(Vec2 v)
75   {
76     return((float)(x * v.y - y * v.x)); 
77   }
78
79   /* V2_dot: vector dot product */
80
81   float dot(Vec2 v)
82   {
83     return((float)(x * v.x + y * v.y));
84   }
85
86   /* V2_times: multiply a vector by a scalar */
87
88   Vec2 times(float c)
89   {
90     return (new Vec2((float)(c*x), (float)(c*y)));
91   }
92
93   /* V2_sum, V2_sub: Vector addition and subtraction */
94
95   Vec2 sum(Vec2 v)
96   {
97     return (new Vec2((float)(x + v.x), (float)(y + v.y)));
98   }
99
100   Vec2 sub(Vec2 v)
101   {
102      return(new Vec2((float)(x - v.x), (float)(y - v.y)));
103   }
104
105 /* V2_magn: magnitude of vector */
106
107   float magn()
108   {
109     return (float) (Math.sqrt((float)(x*x+y*y)));
110   }
111
112   /* returns k X v (cross product).  this is a vector perpendicular to v */
113
114   Vec2 cross()
115   {
116     return(new Vec2((float)y,(float)(-x)));
117   }
118 }
119
120
121