001    //$HeadURL: svn+ssh://jwilden@svn.wald.intevation.org/deegree/base/branches/2.5_testing/src/org/deegree/crs/projections/azimuthal/AzimuthalProjection.java $
002    /*----------------------------------------------------------------------------
003     This file is part of deegree, http://deegree.org/
004     Copyright (C) 2001-2009 by:
005       Department of Geography, University of Bonn
006     and
007       lat/lon GmbH
008    
009     This library is free software; you can redistribute it and/or modify it under
010     the terms of the GNU Lesser General Public License as published by the Free
011     Software Foundation; either version 2.1 of the License, or (at your option)
012     any later version.
013     This library is distributed in the hope that it will be useful, but WITHOUT
014     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
015     FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
016     details.
017     You should have received a copy of the GNU Lesser General Public License
018     along with this library; if not, write to the Free Software Foundation, Inc.,
019     59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020    
021     Contact information:
022    
023     lat/lon GmbH
024     Aennchenstr. 19, 53177 Bonn
025     Germany
026     http://lat-lon.de/
027    
028     Department of Geography, University of Bonn
029     Prof. Dr. Klaus Greve
030     Postfach 1147, 53001 Bonn
031     Germany
032     http://www.geographie.uni-bonn.de/deegree/
033    
034     e-mail: info@deegree.org
035    ----------------------------------------------------------------------------*/
036    
037    package org.deegree.crs.projections.azimuthal;
038    
039    import static org.deegree.crs.projections.ProjectionUtils.EPS10;
040    import static org.deegree.crs.projections.ProjectionUtils.HALFPI;
041    
042    import javax.vecmath.Point2d;
043    
044    import org.deegree.crs.Identifiable;
045    import org.deegree.crs.components.Unit;
046    import org.deegree.crs.coordinatesystems.GeographicCRS;
047    import org.deegree.crs.projections.Projection;
048    
049    /**
050     * The <code>AzimuthalProjection</code> class functions as a super class to all azimuthal projections.
051     * <p>
052     * (From wikipedia) Azimuthal projections have the property that directions from a central point are preserved (and
053     * hence, great circles through the central point are represented by straight lines on the map). Usually these
054     * projections also have radial symmetry in the scales and hence in the distortions: map distances from the central
055     * point are computed by a function r(d) of the true distance d, independent of the angle; correspondingly, circles with
056     * the central point as center are mapped into circles which have as center the central point on the map.
057     * </p>
058     *
059     * <p>
060     * The mapping of radial lines can be visualized by imagining a plane tangent to the Earth, with the central point as
061     * tangent point.
062     * </p>
063     *
064     * @author <a href="mailto:bezema@lat-lon.de">Rutger Bezema</a>
065     *
066     * @author last edited by: $Author: mschneider $
067     *
068     * @version $Revision: 18195 $, $Date: 2009-06-18 17:55:39 +0200 (Do, 18 Jun 2009) $
069     *
070     */
071    
072    public abstract class AzimuthalProjection extends Projection {
073    
074        private static final long serialVersionUID = -8316492116621029077L;
075    
076        /**
077         * Defining that the center of this azimuthal projection is at the north pole
078         */
079        public final static int NORTH_POLE = 0;
080    
081        /**
082         * Defining that the center of this azimuthal projection is at the south pole
083         */
084        public final static int SOUTH_POLE = 1;
085    
086        /**
087         * Defining that the center of this azimuthal projection is at the equator
088         */
089        public final static int EQUATOR = 2;
090    
091        /**
092         * Defining that the center of this azimuthal projection is oblique
093         */
094        public final static int OBLIQUE = 3;
095    
096        private int mode;
097    
098        /**
099         * @param geographicCRS
100         * @param falseNorthing
101         * @param falseEasting
102         * @param naturalOrigin
103         * @param units
104         * @param scale
105         * @param conformal
106         * @param equalArea
107         * @param id
108         *            an identifiable instance containing information about this projection
109         */
110        public AzimuthalProjection( GeographicCRS geographicCRS, double falseNorthing, double falseEasting,
111                                    Point2d naturalOrigin, Unit units, double scale, boolean conformal, boolean equalArea,
112                                    Identifiable id ) {
113            super( geographicCRS, falseNorthing, falseEasting, naturalOrigin, units, scale, conformal, equalArea, id );
114            if ( Math.abs( Math.abs( getProjectionLatitude() ) - HALFPI ) < EPS10 ) {
115                mode = getProjectionLatitude() < 0. ? SOUTH_POLE : NORTH_POLE;
116            } else if ( Math.abs( getProjectionLatitude() ) > EPS10 ) {
117                mode = OBLIQUE;
118            } else {
119                mode = EQUATOR;
120            }
121        }
122    
123        /**
124         * @return the mode.
125         */
126        public final int getMode() {
127            return mode;
128        }
129    
130        /**
131         * Implementation as proposed by Joshua Block in Effective Java (Addison-Wesley 2001), which supplies an even
132         * distribution and is relatively fast. It is created from field <b>f</b> as follows:
133         * <ul>
134         * <li>boolean -- code = (f ? 0 : 1)</li>
135         * <li>byte, char, short, int -- code = (int)f</li>
136         * <li>long -- code = (int)(f ^ (f &gt;&gt;&gt;32))</li>
137         * <li>float -- code = Float.floatToIntBits(f);</li>
138         * <li>double -- long l = Double.doubleToLongBits(f); code = (int)(l ^ (l &gt;&gt;&gt; 32))</li>
139         * <li>all Objects, (where equals(&nbsp;) calls equals(&nbsp;) for this field) -- code = f.hashCode(&nbsp;)</li>
140         * <li>Array -- Apply above rules to each element</li>
141         * </ul>
142         * <p>
143         * Combining the hash code(s) computed above: result = 37 * result + code;
144         * </p>
145         *
146         * @return (int) ( result >>> 32 ) ^ (int) result;
147         *
148         * @see java.lang.Object#hashCode()
149         */
150        @Override
151        public int hashCode() {
152            // the 2nd millionth prime, :-)
153            long code = 32452843;
154            code = code * 37 + super.hashCode();
155            code = code * 37 + getMode();
156            return (int) ( code >>> 32 ) ^ (int) code;
157        }
158    }