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