Source Code Cross Referenced for HyperBoundingBox.java in  » GIS » deegree » org » deegree » io » rtree » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » GIS » deegree » org.deegree.io.rtree 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/trunk/src/org/deegree/io/rtree/HyperBoundingBox.java $
002:        //
003:        //RTree implementation.
004:        //Copyright (C) 2002-2004 Wolfgang Baer - WBaer@gmx.de
005:        //
006:        //This library is free software; you can redistribute it and/or
007:        //modify it under the terms of the GNU Lesser General Public
008:        //License as published by the Free Software Foundation; either
009:        //version 2.1 of the License, or (at your option) any later version.
010:        //
011:        //This library is distributed in the hope that it will be useful,
012:        //but WITHOUT ANY WARRANTY; without even the implied warranty of
013:        //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:        //Lesser General Public License for more details.
015:        //
016:        //You should have received a copy of the GNU Lesser General Public
017:        //License along with this library; if not, write to the Free Software
018:        //Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
019:
020:        package org.deegree.io.rtree;
021:
022:        import java.io.Serializable;
023:
024:        /**
025:         * <p>
026:         * HyperBoundingBox implementing a bounding box
027:         * object in the multidimensional space.
028:         * </p>
029:         * @author Wolfgang Baer - WBaer@gmx.de
030:         */
031:
032:        public class HyperBoundingBox implements  Serializable {
033:
034:            private HyperPoint pMin;
035:            private HyperPoint pMax;
036:
037:            /**
038:             * Constructor.<br>
039:             * Creates a HyperBoundingBox for given HyperPoints.
040:             * @param pMin - min point
041:             * @param pMax - max point
042:             */
043:            public HyperBoundingBox(HyperPoint pMin, HyperPoint pMax) {
044:                if (pMin.getDimension() != pMax.getDimension())
045:                    throw new IllegalArgumentException(
046:                            "HyperPoints need same dimension: "
047:                                    + pMin.getDimension() + " != "
048:                                    + pMax.getDimension());
049:
050:                this .pMin = pMin;
051:                this .pMax = pMax;
052:            }
053:
054:            /**
055:             * Creates a null HyperBoundingBox with null HyperPoints.
056:             * Mostly used internal.
057:             * @param dimension - int for dimension of point
058:             * @return HyperBoundingBox
059:             */
060:            protected static HyperBoundingBox getNullHyperBoundingBox(
061:                    int dimension) {
062:                return new HyperBoundingBox(HyperPoint
063:                        .getNullHyperPoint(dimension), HyperPoint
064:                        .getNullHyperPoint(dimension));
065:            }
066:
067:            /**
068:             * Returns the minimum HyperPoint
069:             * @return HyperPoint
070:             * 
071:             */
072:            public HyperPoint getPMin() {
073:                return pMin;
074:            }
075:
076:            /**
077:             * Returns the maximum HyperPoint
078:             * @return HyperPoint
079:             * 
080:             */
081:            public HyperPoint getPMax() {
082:                return pMax;
083:            }
084:
085:            /**
086:             * Returns the dimension of this HyperBoundingBox.
087:             * @return int
088:             */
089:            public int getDimension() {
090:                return pMin.getDimension();
091:            }
092:
093:            /**
094:             * Tests if this and the given HyperBoundingBox overlaps.
095:             * @param box - HyperBoundingBox to test
096:             * @return boolean
097:             */
098:            public boolean overlaps(HyperBoundingBox box) {
099:                boolean intersect = true;
100:
101:                for (int i = 0; i < getDimension(); i++) {
102:                    if ((pMin.getCoord(i) > box.getPMax().getCoord(i))
103:                            || (pMax.getCoord(i) < box.getPMin().getCoord(i))) {
104:                        intersect = false;
105:                        break;
106:                    }
107:                }
108:
109:                return intersect;
110:            }
111:
112:            /**
113:             * Tests if this contains the given HyperBoundingBox overlaps.
114:             * @param box - HyperBoundingBox to test
115:             * @return boolean
116:             */
117:            public boolean contains(HyperBoundingBox box) {
118:                boolean contains = true;
119:
120:                for (int i = 0; i < getDimension(); i++) {
121:                    if ((pMin.getCoord(i) > box.getPMin().getCoord(i))
122:                            || (pMax.getCoord(i) < box.getPMax().getCoord(i))) {
123:                        contains = false;
124:                        break;
125:                    }
126:                }
127:
128:                return contains;
129:            }
130:
131:            /**
132:             * Computes the area (over all dimension) of this.
133:             * @return double
134:             */
135:            public double getArea() {
136:                double area = 1;
137:
138:                for (int i = 0; i < pMin.getDimension(); i++)
139:                    area = area * (pMax.getCoord(i) - pMin.getCoord(i));
140:
141:                return area;
142:            }
143:
144:            /**
145:             * Computes the union of this with the given HyperBoundingBox.
146:             * @param box - given HyperBoundingBox
147:             * @return HyperBoundingBox
148:             */
149:            public HyperBoundingBox unionBoundingBox(HyperBoundingBox box) {
150:
151:                if (this .getDimension() != box.getDimension())
152:                    throw new IllegalArgumentException(
153:                            "HyperBoundingBoxes need same dimension "
154:                                    + this .getDimension() + " != "
155:                                    + box.getDimension());
156:
157:                if (this .equals(HyperBoundingBox.getNullHyperBoundingBox(this 
158:                        .getDimension())))
159:                    return box;
160:                if (box.equals(HyperBoundingBox.getNullHyperBoundingBox(this 
161:                        .getDimension())))
162:                    return this ;
163:
164:                double[] min = new double[this .getDimension()];
165:                double[] max = new double[this .getDimension()];
166:
167:                for (int i = 0; i < this .getDimension(); i++) {
168:
169:                    if (this .getPMin().getCoord(i) <= box.getPMin().getCoord(i)) {
170:                        min[i] = this .getPMin().getCoord(i);
171:                    } else {
172:                        min[i] = box.getPMin().getCoord(i);
173:                    }
174:                    if (this .getPMax().getCoord(i) >= box.getPMax().getCoord(i)) {
175:                        max[i] = this .getPMax().getCoord(i);
176:                    } else {
177:                        max[i] = box.getPMax().getCoord(i);
178:                    }
179:                }
180:                return new HyperBoundingBox(new HyperPoint(min),
181:                        new HyperPoint(max));
182:            }
183:
184:            /**
185:             * Computes the minimal distance square of this to the given HyperPoint.
186:             * After Roussopoulos Nick: Nearest Neighbor Queries - MINDIST
187:             * @param point - HyperPoint
188:             * @return double
189:             */
190:            public double minDist(HyperPoint point) {
191:                double min = 0;
192:                double ri = 0;
193:
194:                for (int i = 0; i < point.getDimension(); i++) {
195:                    if (point.getCoord(i) < this .pMin.getCoord(i)) {
196:                        ri = this .pMin.getCoord(i);
197:                    } else {
198:                        if (point.getCoord(i) > this .pMax.getCoord(i)) {
199:                            ri = this .pMax.getCoord(i);
200:                        } else {
201:                            ri = point.getCoord(i);
202:                        }
203:                    }
204:                    min = min + Math.pow(point.getCoord(i) - ri, 2);
205:                }
206:                return min;
207:            }
208:
209:            /**
210:             * Deep copy.
211:             * @see java.lang.Object#clone()
212:             */
213:            protected Object clone() {
214:                return new HyperBoundingBox((HyperPoint) pMin.clone(),
215:                        (HyperPoint) pMax.clone());
216:            }
217:
218:            /**
219:             * Builds a String representation of the HyperBoundingBox.
220:             * @return String 
221:             */
222:            public String toString() {
223:                return "BOX: P-Min (" + pMin.toString() + "), P-Max ("
224:                        + pMax.toString() + ")";
225:            }
226:
227:            /**
228:             * Implements equals
229:             * @see java.lang.Object#equals(java.lang.Object)
230:             */
231:            public boolean equals(Object obj) {
232:                HyperBoundingBox box = (HyperBoundingBox) obj;
233:                return (this.pMin.equals(box.pMin) && this.pMax
234:                        .equals(box.pMax));
235:            }
236:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.