Normand Briere
2019-10-15 67d823555c17c4ea3d31832c72e375b03cffa859
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// Hyper-Rectangle class supporting KDTree class
 
//package edu.wlu.cs.levy.CG;
 
class HRect {
 
    protected HPoint min;
    protected HPoint max;
 
    protected HRect(int ndims) {
   min = new HPoint(ndims);
   max = new HPoint(ndims);
    }
 
    protected HRect(HPoint vmin, HPoint vmax) {
 
   min = (HPoint)vmin.clone();
   max = (HPoint)vmax.clone();
    }
 
    protected Object clone() {
   
   return new HRect(min, max);
    }
 
    // from Moore's eqn. 6.6
    protected HPoint closest(HPoint t) {
 
   HPoint p = new HPoint(t.coord.length);
 
   for (int i=0; i<t.coord.length; ++i) {
           if (t.coord[i]<=min.coord[i]) {
               p.coord[i] = min.coord[i];
           }
           else if (t.coord[i]>=max.coord[i]) {
               p.coord[i] = max.coord[i];
           }
           else {
               p.coord[i] = t.coord[i];
           }
   }
   
   return p;
    }
 
    // used in initial conditions of KDTree.nearest()
    protected static HRect infiniteHRect(int d) {
   
   HPoint vmin = new HPoint(d);
   HPoint vmax = new HPoint(d);
   
   for (int i=0; i<d; ++i) {
       vmin.coord[i] = Double.NEGATIVE_INFINITY;
       vmax.coord[i] = Double.POSITIVE_INFINITY;
   }
 
   return new HRect(vmin, vmax);
    }
 
    // currently unused
    protected HRect intersection(HRect r) {
 
   HPoint newmin = new HPoint(min.coord.length);
   HPoint newmax = new HPoint(min.coord.length);
 
   for (int i=0; i<min.coord.length; ++i) {
       newmin.coord[i] = Math.max(min.coord[i], r.min.coord[i]);
       newmax.coord[i] = Math.min(max.coord[i], r.max.coord[i]);
       if (newmin.coord[i] >= newmax.coord[i]) return null;
   }
 
   return new HRect(newmin, newmax);
    }
 
    // currently unused
    protected double area () {
 
   double a = 1;
 
   for (int i=0; i<min.coord.length; ++i) {
       a *= (max.coord[i] - min.coord[i]);
   }
 
   return a;
    }
 
    public String toString() {
   return min + "\n" + max + "\n";
    }
}