Index: /trunk/psLib/src/astro/psCoord.c
===================================================================
--- /trunk/psLib/src/astro/psCoord.c	(revision 1530)
+++ /trunk/psLib/src/astro/psCoord.c	(revision 1531)
@@ -10,6 +10,6 @@
 *  @author George Gusciora, MHPCC
 *
-*  @version $Revision: 1.17 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2004-08-12 01:32:21 $
+*  @version $Revision: 1.18 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2004-08-13 23:33:13 $
 *
 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -90,11 +90,12 @@
 }
 
-// XXX: I have no idea how this works.  This algorithm comes from an email
-// from Gene.  I assume (x,y) corresponds to (r,d) in the sphere coordinates.
-
-// XXX: In Gene's email, there are different variables with similar names
-// (y and Y) and in the code, there's cos_y, cos_Y, and cos(y).  Verify that
-// there are no typo's.
-
+/******************************************************************************
+This algorithm comes from an email from Gene.  I assume (x,y) corresponds to
+(r,d) in the sphere coordinates.
+ 
+XXX: In Gene's email, there are different variables with similar names (y
+and Y) and in the code, there's cos_y, cos_Y, and cos(y).  Verify that there
+are no typo's.
+ *****************************************************************************/
 psSphere* psSphereTransformApply(psSphere* out,
                                  const psSphereTransform* transform,
@@ -161,5 +162,4 @@
 }
 
-// XXX: Is this the correct way to calculate this?
 float cot(float x)
 {
@@ -167,5 +167,7 @@
 }
 
-// This is some kind of arc tan function.
+/******************************************************************************
+XXX: Verify this arc tan function.
+ *****************************************************************************/
 float arg(float x,
           float y)
@@ -187,6 +189,8 @@
 }
 
-// XXX: Waiting for the definition of the PS_PROJ_PAR projection.
-// XXX: Waiting for the definition of the PS_PROJ_GLS projection.
+/******************************************************************************
+XXX: Waiting for the definition of the PS_PROJ_PAR projection.
+XXX: Waiting for the definition of the PS_PROJ_GLS projection.
+ *****************************************************************************/
 psPlane* psProject(const psSphere* coord,
                    const psProjection* projection)
@@ -230,6 +234,8 @@
 }
 
-// XXX: Waiting for the definition of the PS_PROJ_PAR projection.
-// XXX: Waiting for the definition of the PS_PROJ_GLS projection.
+/******************************************************************************
+XXX: Waiting for the definition of the PS_PROJ_PAR projection.
+XXX: Waiting for the definition of the PS_PROJ_GLS projection.
+ *****************************************************************************/
 psSphere* psDeproject(const psPlane* coord,
                       const psProjection* projection)
@@ -278,6 +284,14 @@
 }
 
-// XXX: Do I need to check for unacceptable transformation parameters?
-// Maybe, if the points are on the North/South Pole, etc?
+/******************************************************************************
+The basic idea is to project both positions onto the linear plane, with
+position1 at the center, then calculate the linear offset between those
+projections.
+ 
+XXX: Do I need to check for unacceptable transformation parameters?  Maybe,
+     if the points are on the North/South Pole, etc?
+ 
+XXX: Do I need to somehow scale this projection?
+ *****************************************************************************/
 psSphere* psSphereGetOffset(const psSphere* restrict position1,
                             const psSphere* restrict position2,
@@ -285,5 +299,5 @@
                             psSphereOffsetUnit unit)
 {
-    // psPlane* lin;
+    psPlane* lin;
     psProjection proj;
     psSphere* tmp;
@@ -292,10 +306,4 @@
 
     if (mode == PS_LINEAR) {
-        // XXX: I have no idea how to construct this.  Maybe project both
-        // sperical positions onto the plane, set the origin at one of the
-        // points on the plane, then deproject?
-
-        // XXX: Do I need to somehow scale this projection?
-        // project position1? Will it project to (0.0, 0.0)?
         proj.R = position1->r;
         proj.D = position1->d;
@@ -304,6 +312,6 @@
         proj.type = PS_PROJ_TAN;
 
-        // lin = psProject(position2, proj);
-        // tmp = psDeproject(lin, proj);
+        lin = psProject(position2, &proj);
+        tmp = psDeproject(lin, &proj);
 
         // XXX: Do we need to convert units in tmp?
@@ -328,9 +336,10 @@
 
         tmp = (psSphere* ) psAlloc(sizeof(psSphere));
-        tmp->r = tmpR;
-        tmp->d = tmpD;
+        // XXX: Wrap these to an acceptable range.  Is this correct?
+        tmp->r = fmod(tmpR, 2*M_PI);
+        tmp->d = fmod(tmpD, 2*M_PI);
         tmp->rErr = 0.0;
         tmp->dErr = 0.0;
-        // XXX: Do we need to wrap these to an acceptable range?
+
         return (tmp);
     }
@@ -339,7 +348,13 @@
 }
 
-// XXX: Do I need to check for unacceptable transformation parameters?
-// Maybe, if the points are on the North/South Pole, etc?
-// XXX: I copied the algorithm from the ADD exactly.
+/******************************************************************************
+XXX: Do I need to check for unacceptable transformation parameters?  Maybe,
+     if the points are on the North/South Pole, etc?
+ 
+XXX: Do I need to somehow scale this projection?
+ 
+XXX: I copied the algorithm from the ADD exactly.
+ *****************************************************************************/
+
 psSphere* psSphereSetOffset(const psSphere* restrict position,
                             const psSphere* restrict offset,
@@ -384,11 +399,12 @@
 
         tmp = (psSphere* ) psAlloc(sizeof(psSphere));
+        // XXX: Is this an acceptable way to wrap the angular output?
         tmp->r = position->r + tmpR;
-        tmp->r = position->d + tmpD;
+        tmp->r = fmod(tmp->r, 2.0*M_PI);
+        tmp->d = position->d + tmpD;
+        tmp->d = fmod(tmp->d, 2.0*M_PI);
         tmp->rErr = 0.0;
         tmp->dErr = 0.0;
 
-        // XXX: wrap tmp->r and tmp->d to the allowed range (-PI to PI)
-        // and (0 to 2*PI).
         return (tmp);
     }
Index: /trunk/psLib/src/astronomy/psCoord.c
===================================================================
--- /trunk/psLib/src/astronomy/psCoord.c	(revision 1530)
+++ /trunk/psLib/src/astronomy/psCoord.c	(revision 1531)
@@ -10,6 +10,6 @@
 *  @author George Gusciora, MHPCC
 *
-*  @version $Revision: 1.17 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2004-08-12 01:32:21 $
+*  @version $Revision: 1.18 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2004-08-13 23:33:13 $
 *
 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -90,11 +90,12 @@
 }
 
-// XXX: I have no idea how this works.  This algorithm comes from an email
-// from Gene.  I assume (x,y) corresponds to (r,d) in the sphere coordinates.
-
-// XXX: In Gene's email, there are different variables with similar names
-// (y and Y) and in the code, there's cos_y, cos_Y, and cos(y).  Verify that
-// there are no typo's.
-
+/******************************************************************************
+This algorithm comes from an email from Gene.  I assume (x,y) corresponds to
+(r,d) in the sphere coordinates.
+ 
+XXX: In Gene's email, there are different variables with similar names (y
+and Y) and in the code, there's cos_y, cos_Y, and cos(y).  Verify that there
+are no typo's.
+ *****************************************************************************/
 psSphere* psSphereTransformApply(psSphere* out,
                                  const psSphereTransform* transform,
@@ -161,5 +162,4 @@
 }
 
-// XXX: Is this the correct way to calculate this?
 float cot(float x)
 {
@@ -167,5 +167,7 @@
 }
 
-// This is some kind of arc tan function.
+/******************************************************************************
+XXX: Verify this arc tan function.
+ *****************************************************************************/
 float arg(float x,
           float y)
@@ -187,6 +189,8 @@
 }
 
-// XXX: Waiting for the definition of the PS_PROJ_PAR projection.
-// XXX: Waiting for the definition of the PS_PROJ_GLS projection.
+/******************************************************************************
+XXX: Waiting for the definition of the PS_PROJ_PAR projection.
+XXX: Waiting for the definition of the PS_PROJ_GLS projection.
+ *****************************************************************************/
 psPlane* psProject(const psSphere* coord,
                    const psProjection* projection)
@@ -230,6 +234,8 @@
 }
 
-// XXX: Waiting for the definition of the PS_PROJ_PAR projection.
-// XXX: Waiting for the definition of the PS_PROJ_GLS projection.
+/******************************************************************************
+XXX: Waiting for the definition of the PS_PROJ_PAR projection.
+XXX: Waiting for the definition of the PS_PROJ_GLS projection.
+ *****************************************************************************/
 psSphere* psDeproject(const psPlane* coord,
                       const psProjection* projection)
@@ -278,6 +284,14 @@
 }
 
-// XXX: Do I need to check for unacceptable transformation parameters?
-// Maybe, if the points are on the North/South Pole, etc?
+/******************************************************************************
+The basic idea is to project both positions onto the linear plane, with
+position1 at the center, then calculate the linear offset between those
+projections.
+ 
+XXX: Do I need to check for unacceptable transformation parameters?  Maybe,
+     if the points are on the North/South Pole, etc?
+ 
+XXX: Do I need to somehow scale this projection?
+ *****************************************************************************/
 psSphere* psSphereGetOffset(const psSphere* restrict position1,
                             const psSphere* restrict position2,
@@ -285,5 +299,5 @@
                             psSphereOffsetUnit unit)
 {
-    // psPlane* lin;
+    psPlane* lin;
     psProjection proj;
     psSphere* tmp;
@@ -292,10 +306,4 @@
 
     if (mode == PS_LINEAR) {
-        // XXX: I have no idea how to construct this.  Maybe project both
-        // sperical positions onto the plane, set the origin at one of the
-        // points on the plane, then deproject?
-
-        // XXX: Do I need to somehow scale this projection?
-        // project position1? Will it project to (0.0, 0.0)?
         proj.R = position1->r;
         proj.D = position1->d;
@@ -304,6 +312,6 @@
         proj.type = PS_PROJ_TAN;
 
-        // lin = psProject(position2, proj);
-        // tmp = psDeproject(lin, proj);
+        lin = psProject(position2, &proj);
+        tmp = psDeproject(lin, &proj);
 
         // XXX: Do we need to convert units in tmp?
@@ -328,9 +336,10 @@
 
         tmp = (psSphere* ) psAlloc(sizeof(psSphere));
-        tmp->r = tmpR;
-        tmp->d = tmpD;
+        // XXX: Wrap these to an acceptable range.  Is this correct?
+        tmp->r = fmod(tmpR, 2*M_PI);
+        tmp->d = fmod(tmpD, 2*M_PI);
         tmp->rErr = 0.0;
         tmp->dErr = 0.0;
-        // XXX: Do we need to wrap these to an acceptable range?
+
         return (tmp);
     }
@@ -339,7 +348,13 @@
 }
 
-// XXX: Do I need to check for unacceptable transformation parameters?
-// Maybe, if the points are on the North/South Pole, etc?
-// XXX: I copied the algorithm from the ADD exactly.
+/******************************************************************************
+XXX: Do I need to check for unacceptable transformation parameters?  Maybe,
+     if the points are on the North/South Pole, etc?
+ 
+XXX: Do I need to somehow scale this projection?
+ 
+XXX: I copied the algorithm from the ADD exactly.
+ *****************************************************************************/
+
 psSphere* psSphereSetOffset(const psSphere* restrict position,
                             const psSphere* restrict offset,
@@ -384,11 +399,12 @@
 
         tmp = (psSphere* ) psAlloc(sizeof(psSphere));
+        // XXX: Is this an acceptable way to wrap the angular output?
         tmp->r = position->r + tmpR;
-        tmp->r = position->d + tmpD;
+        tmp->r = fmod(tmp->r, 2.0*M_PI);
+        tmp->d = position->d + tmpD;
+        tmp->d = fmod(tmp->d, 2.0*M_PI);
         tmp->rErr = 0.0;
         tmp->dErr = 0.0;
 
-        // XXX: wrap tmp->r and tmp->d to the allowed range (-PI to PI)
-        // and (0 to 2*PI).
         return (tmp);
     }
