001 //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/tags/2.1/src/org/deegree/io/rtree/HyperPoint.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 * Point in multidimensional space.
027 * Based on double coordinates.
028 * </p>
029 * @author Wolfgang Baer - WBaer@gmx.de
030 */
031 public class HyperPoint implements Serializable {
032
033 private double[] coords;
034
035 /**
036 * Constructor.<br>
037 * Length of given array sets the dimension.
038 * @param coords - array with double values of the coordinates.
039 */
040 public HyperPoint( double[] coords ) {
041 //this.coords = coords;
042 this.coords = new double[] { coords[0], coords[1] };
043 }
044
045 /**
046 * Creates a null HyperPoint with coordinates Double.NaN.
047 * Mostly used internal.
048 * @param dimension - int for dimension of point
049 * @return HyperPoint
050 */
051 protected static HyperPoint getNullHyperPoint(int dimension) {
052 double[] point = new double[dimension];
053 for ( int i = 0; i < dimension; i++ )
054 point[i] = Double.NaN;
055 return new HyperPoint( point );
056 }
057
058 /**
059 * Returns the coordinates as double array.
060 * @return double[]
061 *
062 */
063 public double[] getCoords() {
064 return coords;
065 }
066
067 /**
068 * Returns the coordinate for given index.
069 * @param index - int
070 * @return double - coordinate
071 */
072 public double getCoord( int index ) {
073 return coords[index];
074 }
075
076 /**
077 * Returns the dimension of the HyperPoint.
078 * @return int
079 */
080 public int getDimension() {
081 return coords.length;
082 }
083
084 /**
085 * Builds a String representation of the HyperPoint.
086 * @return String
087 */
088 public String toString() {
089 String ret = "";
090
091 for ( int i = 0; i < coords.length; i++ ) {
092 ret += ( coords[i] + ", " );
093 }
094
095 return ret;
096 }
097
098 /**
099 * Implements equals
100 * @see java.lang.Object#equals(java.lang.Object)
101 */
102 public boolean equals( Object obj ) {
103 HyperPoint point = (HyperPoint)obj;
104 for ( int i = 0; i < coords.length; i++ ) {
105 if(this.coords[i] != point.coords[i])
106 return false;
107 }
108 return true;
109 }
110
111
112 /**
113 * Implements clone.
114 * @see java.lang.Object#clone()
115 */
116 protected Object clone() {
117 double[] point = new double[coords.length];
118
119 for ( int i = 0; i < coords.length; i++ )
120 point[i] = coords[i];
121
122 return new HyperPoint( point );
123 }
124 }/* ********************************************************************
125 Changes to this class. What the people have been up to:
126 $Log$
127 Revision 1.5 2006/07/12 14:46:17 poth
128 comment footer added
129
130 ********************************************************************** */