Statistics
| Revision:

root / branches / Mobile_Compatible_Hito_1 / libFMap / src-data / org / gvsig / data / spatialprovisional / Extent.java @ 21606

History | View | Annotate | Download (2.6 KB)

1
package org.gvsig.data.spatialprovisional;
2

    
3
import java.awt.geom.Rectangle2D;
4

    
5
public class Extent implements IExtent{
6

    
7
        private int numberOfDimensions;
8
        private double[] min;
9
        private double[] max;
10
        private String[] dimensionLabel;
11

    
12
        public Extent (int dimiensions,double[] min, double[] max){
13
                //TODO
14

    
15
        }
16
        public Extent(double x1,double y1,double x2,double y2){
17
                this.initDimiensions(2);
18
                this.dimensionLabel[0] = "x";
19
                if (x1 < x2){
20
                        this.min[0] = x1;
21
                        this.max[0] = x2;
22
                } else {
23
                        this.min[0] = x2;
24
                        this.max[0] = x1;
25
                }
26
                this.dimensionLabel[1] = "y";
27
                if (y1 < y2){
28
                        this.min[0] = y1;
29
                        this.max[0] = y2;
30
                } else {
31
                        this.min[0] = y2;
32
                        this.max[0] = y1;
33
                }
34
        }
35

    
36
        public Extent(double x1,double y1,double z1,double x2,double y2,double z2){
37
                this.initDimiensions(3);
38
                this.dimensionLabel[0] = "x";
39
                if (x1 < x2){
40
                        this.min[0] = x1;
41
                        this.max[0] = x2;
42
                } else {
43
                        this.min[0] = x2;
44
                        this.max[0] = x1;
45
                }
46
                this.dimensionLabel[1] = "y";
47
                if (y1 < y2){
48
                        this.min[0] = y1;
49
                        this.max[0] = y2;
50
                } else {
51
                        this.min[0] = y2;
52
                        this.max[0] = y1;
53
                }
54
                this.dimensionLabel[2] = "z";
55
                if (z1 < z2){
56
                        this.min[0] = z1;
57
                        this.max[0] = z2;
58
                } else {
59
                        this.min[0] = z2;
60
                        this.max[0] = z1;
61
                }
62

    
63
        }
64
        public Extent(Rectangle2D bounds2D) {
65
                this.initDimiensions(2);
66
                this.dimensionLabel[0] = "x";
67
                this.dimensionLabel[0] = "y";
68
                this.min[0]=bounds2D.getMinX();
69
                this.min[1]=bounds2D.getMinY();
70
                this.max[0]=bounds2D.getMaxX();
71
                this.max[1]=bounds2D.getMaxY();
72
        }
73

    
74
        public void add(IExtent extent) {
75
                int maxDimension = Math.min(this.numberOfDimensions, extent.getDimiensionsCount());
76
                int i;
77
                for (i=0;i<maxDimension;i++){
78
                        this.min[i] = Math.min(this.min[i], extent.getMin(i));
79
                        this.max[i] = Math.max(this.max[i], extent.getMin(i));
80
                }
81
        }
82

    
83
        private void initDimiensions(int ndimensions){
84
                this.numberOfDimensions = ndimensions;
85
                this.min = new double[ndimensions];
86
                this.max = new double[ndimensions];
87
                this.dimensionLabel = new String[ndimensions];
88
        }
89

    
90

    
91
        public boolean contains(Object geometry) {
92
//                Extent bounds=new Extent(geometry.getBounds2D());
93
//                if (bounds.x1 == bounds.x2 || bounds.y1 == bounds.y2) {
94
//                    return false;
95
//                }
96
//                double x0 = x1;
97
//                double y0 = y1;
98
//                return (bounds.x1 >= x0 &&
99
//                        bounds.y1 >= y0 &&
100
//                        (bounds.x2) <= x2 &&
101
//                        (bounds.y2) <= y2);
102
                return false;
103
        }
104

    
105
        public String getDimiensionLabel(int index) {
106
                return this.getDimiensionLabel(index);
107
        }
108

    
109
        public int getDimiensionsCount() {
110
                return this.numberOfDimensions;
111
        }
112

    
113
        public double getMax(int index) {
114
                return this.max[index];
115
        }
116

    
117
        public double getMin(int index) {
118
                return this.min[index];
119
        }
120

    
121
}