Description: fix aspect ratio for TSC projection
Origin: upstream, http://xplanet.svn.sf.net/viewvc/xplanet?view=rev&revision=160
Index: xplanet-1.2.1/src/drawProjection.cpp
===================================================================
--- xplanet-1.2.1.orig/src/drawProjection.cpp	2010-12-02 10:22:14.713716623 -0500
+++ xplanet-1.2.1/src/drawProjection.cpp	2010-12-02 10:22:31.288720978 -0500
@@ -136,34 +136,39 @@
         LineSegment *ls = NULL;
 
         int blockWidth = width/4;
+        int blockHeight = blockWidth;
+        int hp0 = (height + blockHeight)/2;
+        int hp1 = hp0 + height/30;
+        int hm0 = (height - blockHeight)/2;
+        int hm1 = hm0 - height/30;
         for (int i = 0; i < 4; i++)
         {
             if (i == 1) continue;
 
             double X0 = i * blockWidth;
 
-            ls = new LineSegment(black, thickness, X0, height/3, 
-                                 X0+width/40, 9*height/30);
+            ls = new LineSegment(black, thickness, X0, hp0, 
+                                 X0+width/40, hp1);
             annotationMap.insert(pair<const double, Annotation*>(Z, ls));
 
-            ls = new LineSegment(black, thickness, X0+width/4, height/3, 
-                                 X0+9*width/40, 9*height/30);
+            ls = new LineSegment(black, thickness, X0+width/4, hp0, 
+                                 X0+9*width/40, hp1);
             annotationMap.insert(pair<const double, Annotation*>(Z, ls));
 
-            ls = new LineSegment(black, thickness, X0+width/40, 9*height/30, 
-                                 X0+9*width/40, 9*height/30);
+            ls = new LineSegment(black, thickness, X0+width/40, hp1, 
+                                 X0+9*width/40, hp1);
             annotationMap.insert(pair<const double, Annotation*>(Z, ls));
 
-            ls = new LineSegment(black, thickness, X0, 2*height/3, 
-                                 X0+width/40, 21*height/30);
+            ls = new LineSegment(black, thickness, X0, hm0, 
+                                 X0+width/40, hm1);
             annotationMap.insert(pair<const double, Annotation*>(Z, ls));
 
-            ls = new LineSegment(black, thickness, X0+width/4, 2*height/3, 
-                                 X0+9*width/40, 21*height/30);
+            ls = new LineSegment(black, thickness, X0+width/4, hm0, 
+                                 X0+9*width/40, hm1);
             annotationMap.insert(pair<const double, Annotation*>(Z, ls));
 
-            ls = new LineSegment(black, thickness, X0+width/40, 21*height/30, 
-                                 X0+9*width/40, 21*height/30);
+            ls = new LineSegment(black, thickness, X0+width/40, hm1, 
+                                 X0+9*width/40, hm1);
             annotationMap.insert(pair<const double, Annotation*>(Z, ls));
         }
 
Index: xplanet-1.2.1/src/libprojection/ProjectionTSC.cpp
===================================================================
--- xplanet-1.2.1.orig/src/libprojection/ProjectionTSC.cpp	2010-12-02 10:22:14.737732596 -0500
+++ xplanet-1.2.1/src/libprojection/ProjectionTSC.cpp	2010-12-02 10:22:31.288720978 -0500
@@ -21,8 +21,11 @@
     xScale_ = 1;
     yScale_ = 2./3.;
 
-    xOffset_ = -width_/8;
-    yOffset_ = 0;
+    trueWidth_ = width_;
+    trueHeight_ = static_cast<int> (0.75 * trueWidth_);
+
+    xOffset_ = trueWidth_/8;
+    yOffset_ = (trueHeight_ - height_)/2;
 
     // find the pixel values of the center of each cube face
     bool rotateSave = rotate_;
@@ -33,7 +36,8 @@
         GetCenterLatLon(i, lat_c, lon_c);
         sphericalToPixel(lon_c, lat_c, xPixel_[i], yPixel_[i]);
 
-        xPixel_[i] -= xOffset_;
+        xPixel_[i] += xOffset_;
+        yPixel_[i] += yOffset_;
     }
     rotate_ = rotateSave;
 }
@@ -165,7 +169,7 @@
 {
     int returnVal = -1;
 
-    double dist = width_;
+    double dist = trueWidth_;
     for (int i = 0; i < 6; i++)
     {
         const double dx = x - xPixel_[i];
@@ -180,8 +184,8 @@
     }
 
     // check that the point is on the cube face
-    if (fabs(x - xPixel_[returnVal]) > width_/8) return(-1);
-    if (fabs(y - yPixel_[returnVal]) > height_/6) return(-1);
+    if (fabs(x - xPixel_[returnVal]) > trueWidth_/8) return(-1);
+    if (fabs(y - yPixel_[returnVal]) > trueHeight_/6) return(-1);
 
     return(returnVal);
 }
@@ -190,11 +194,11 @@
 ProjectionTSC::pixelToSpherical(const double x, const double y,
                                 double &lon, double &lat)
 {
-    const double offsetX = x + width_/2 - centerX_ - xOffset_;
-    const double offsetY = y + height_/2 - centerY_ - yOffset_;
+    const double offsetX = x + width_/2 - centerX_ + xOffset_;
+    const double offsetY = y + height_/2 - centerY_ + yOffset_;
 
-    const double X = TWO_PI * (offsetX/width_ - 0.5)/xScale_;
-    const double Y = M_PI * (0.5 - offsetY/height_)/yScale_;
+    const double X = TWO_PI * (offsetX/trueWidth_ - 0.5)/xScale_;
+    const double Y = M_PI * (0.5 - offsetY/trueHeight_)/yScale_;
 
     const int face = GetFace(offsetX, offsetY);
     if (face < 0) return(false);
@@ -260,11 +264,11 @@
     const double X = lon_c + chi * M_PI / 4;
     const double Y = lat_c + psi * M_PI / 4;
 
-    x = width_ * (X * xScale_ / TWO_PI + 0.5);
-    y = height_ * (0.5 - Y * yScale_ / M_PI);
+    x = trueWidth_ * (X * xScale_ / TWO_PI + 0.5);
+    y = trueHeight_ * (0.5 - Y * yScale_ / M_PI);
 
-    x += (centerX_ - width_/2 + xOffset_);
-    y += (centerY_ - height_/2 + yOffset_);
+    x += (centerX_ - width_/2 - xOffset_);
+    y += (centerY_ - height_/2 - yOffset_);
 
     if (y < 0 || y >= height_) return(false);
 
Index: xplanet-1.2.1/src/libprojection/ProjectionTSC.h
===================================================================
--- xplanet-1.2.1.orig/src/libprojection/ProjectionTSC.h	2010-12-02 10:22:14.725720244 -0500
+++ xplanet-1.2.1/src/libprojection/ProjectionTSC.h	2010-12-02 10:22:31.292733429 -0500
@@ -13,6 +13,9 @@
     bool sphericalToPixel(double lon, double lat, double &x, double &y) const;
 
  private:
+    int trueWidth_;
+    int trueHeight_;
+
     double xOffset_;
     double yOffset_;
     
