1 /*
2  *  This file is part of Healpix Java.
3  *
4  *  This code is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; either version 2 of the License, or
7  *  (at your option) any later version.
8  *
9  *  This code is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with this code; if not, write to the Free Software
16  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17  *
18  *  For more information about HEALPix, see http://healpix.sourceforge.net
19  */
20 
21 package healpix.essentials;
22 
23 /** Class for storing a position on the unit sphere as a (z,phi)-tuple.
24 
25     @copyright (C) 2011 Max-Planck-Society
26     @author Martin Reinecke */
27 public final  class Zphi
28   {
29   /** Cosine of the colatitude, or z component of unit vector; Range [-1;1]. */
30   public double z;
31 
32   /** Longitude in radians; Range [0; 2Pi]. */
33   public double phi;
34 
35   /** Default constructor */
Zphi()36   public Zphi() {}
37 
38   /** Creation from individual components */
Zphi(double z_, double phi_)39   public Zphi (double z_, double phi_)
40     { z=z_; phi=phi_; }
41 
42   /** Conversion from {@link Vec3} */
Zphi(Vec3 v)43   public Zphi (Vec3 v)
44     { z = v.z/v.length(); phi = FastMath.atan2(v.y,v.x); }
45 
46   /** Conversion from {@link Pointing} */
Zphi(Pointing ptg)47   public Zphi (Pointing ptg)
48     { z = FastMath.cos(ptg.theta); phi=ptg.phi; }
49 
toString()50   public String toString()
51     {
52     StringBuilder s = new StringBuilder();
53     s.append("zphi(");s.append(z);
54     s.append(",");s.append(phi);
55     s.append(")");
56     return s.toString();
57     }
58 
equals(Object o)59   public boolean equals(Object o)
60     {
61     if (this == o) return true;
62     if (o == null || getClass() != o.getClass()) return false;
63     Zphi zphi = (Zphi) o;
64     if (Double.compare(zphi.phi, phi) != 0) return false;
65     if (Double.compare(zphi.z, z) != 0) return false;
66     return true;
67     }
68 
hashCode()69   public int hashCode()
70     {
71     long temp = z != +0.0d ? Double.doubleToLongBits(z) : 0L;
72     int result = (int) (temp ^ (temp >>> 32));
73     temp = phi != +0.0d ? Double.doubleToLongBits(phi) : 0L;
74     result = 31 * result + (int) (temp ^ (temp >>> 32));
75     return result;
76     }
77   }
78