[giv] Fixed aspect ratio related bug when fitting vector data without image.



commit 277a5fa44eab181dd92ff98762eb00444a855a92
Author: Dov Grobgeld <dov grobgeld gmail com>
Date:   Tue Nov 8 18:51:42 2011 +0200

    Fixed aspect ratio related bug when fitting vector data without image.
    
    2011-11-08  Dov Grobgeld  <dov grobgeld gmail com>
    
            * giv-win.gob : Taken into account the aspect ratio when calculating
            the auto fit scale ratio.

 ChangeLog       |    5 +++++
 src/giv-win.gob |   11 +++++++----
 2 files changed, 12 insertions(+), 4 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 26a381d..37879a8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2011-11-08  Dov Grobgeld  <dov grobgeld gmail com>
+
+        * giv-win.gob : Taken into account the aspect ratio when calculating
+        the auto fit scale ratio.
+
 2011-10-30  Dov Grobgeld  <dov grobgeld gmail com>
 
         * giv-win.gob, giv-widget.gob : Added support for pixel grid.
diff --git a/src/giv-win.gob b/src/giv-win.gob
index a1b6785..9027551 100644
--- a/src/giv-win.gob
+++ b/src/giv-win.gob
@@ -3482,18 +3482,21 @@ fit_marks_in_window(GivWin *self)
     }
     else {
         margin= 10;
+        int cnv_width = selfp->w_imgv->allocation.width;
+        int cnv_height = selfp->w_imgv->allocation.height;
+        double aspect_ratio = 1.0*cnv_height/cnv_width;
 
         // The following is a hack around the problem of too thin
         // data in x or y... It should be solved in the gtk_image_viewer.
         if (max_x - min_x < max_y-min_y) {
             double avg_x = 0.5*(max_x+min_x);
-            min_x = avg_x - 0.5*(max_y-min_y);
-            max_x = avg_x + 0.5*(max_y-min_y);
+            min_x = avg_x - 0.5/aspect_ratio*(max_y-min_y);
+            max_x = avg_x + 0.5/aspect_ratio*(max_y-min_y);
         }
         if (max_y - min_y < max_x-min_x) {
             double avg_y = 0.5*(max_y+min_y);
-            min_y = avg_y - 0.5*(max_x-min_x);
-            max_y = avg_y + 0.5*(max_x-min_x);
+            min_y = avg_y - aspect_ratio*0.5*(max_x-min_x);
+            max_y = avg_y + aspect_ratio*0.5*(max_x-min_x);
         }
         
         gtk_image_viewer_set_scroll_region(GTK_IMAGE_VIEWER(selfp->w_imgv),



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]