Bug 120450 - Strange helper lines behavior in ratio crop tool
Summary: Strange helper lines behavior in ratio crop tool
Status: RESOLVED FIXED
Alias: None
Product: digikam
Classification: Unclassified
Component: Plugin-Editor-Crop (show other bugs)
Version: 4.9.0
Platform: Compiled Sources Linux
: NOR normal (vote)
Target Milestone: ---
Assignee: Digikam Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-01-19 13:13 UTC by Thorsten Schnebeck
Modified: 2016-06-29 19:35 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In: 0.9.3


Attachments
no more jumping lines. (4.55 KB, patch)
2007-06-14 12:53 UTC, Arnd Baecker
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Thorsten Schnebeck 2006-01-19 13:13:45 UTC
Version:            (using KDE KDE 3.5.0)
Installed from:    Compiled From Sources

When using the ratio crop tool in 3:4 mode and active golden mean helper lines I see a displacement of the helper lines when toggling "mirror horizontal/vertical". Cause the lines should be fully h/v-symmetrical *me* wonders about this displacement.

Bye

  Thorsten
Comment 1 Arnd Baecker 2007-06-14 12:53:05 UTC
Created attachment 20856 [details]
no more jumping lines.

The attached patch solves (at least for me ;-) 
the jumping helper lines under flip.
The origin of the problem were a combination of several 1 pixel round-off
errors.

Best, Arnd
Comment 2 Thorsten Schnebeck 2007-06-17 01:06:57 UTC
Patch looks fine. As its not applied can you change the bug status to confirmed (=NEW)?

Bye

  Thorsten
Comment 3 caulier.gilles 2007-06-17 09:17:40 UTC
SVN commit 676579 by cgilles:

digikam from KDE3 branch : Ratio Crop Tool : patch from Arnd Beacker about to fix round off error in helper lines computation.
BUG: 120450


 M  +35 -22    imageselectionwidget.cpp  


--- branches/extragear/kde3/graphics/digikam/imageplugins/coreplugin/ratiocrop/imageselectionwidget.cpp #676578:676579
@@ -29,10 +29,10 @@
 
 #define MINRANGE 0
 
-// Fibanocci irrationel Golden Number.
-#define PHI      1.618033988
+// Golden number (1+sqrt(5))/2
+#define PHI      1.61803398874989479
 // 1/PHI
-#define INVPHI   0.61803398903633
+#define INVPHI   0.61803398874989479
 
 // C++ includes.
 
@@ -858,43 +858,53 @@
             if (d->flipHorGoldenGuide)
                 p.scale(-1, 1);
 
-            // Flip verical.
+            // Flip vertical.
             if (d->flipVerGoldenGuide)
                 p.scale(1, -1);
 
             int w = d->localRegionSelection.width();
             int h = d->localRegionSelection.height();
 
-            QRect R1(-w/2, -h/2, 
-                     (int)(w/PHI), h);
-            QRect R2((int)(w*(INVPHI - 0.5)), (int)(h*(0.5 - INVPHI)), 
-                     (int)(w*(1 - INVPHI)), (int)(h/PHI)); 
-            QRect R3((int)(w/2 - R2.width()/PHI), -h/2, 
-                     (int)(R2.width()/PHI), h - R2.height());
+            // lengths for the golden mean and half the sizes of the region:
+            int w_g = (int)(w*INVPHI);
+            int h_g = (int)(h*INVPHI);
+            int w_2 = w/2;
+            int h_2 = h/2;
+
+            QRect R1(-w_2, -h_2, w_g, h);
+            // w - 2*w_2 corrects for one-pixel difference
+            // so that R2.right() is really at the right end of the region
+            QRect R2(w_g-w_2, h_2-h_g, w-w_g+1-(w - 2*w_2), h_g); 
+
+            QRect R3((int)(w_2 - R2.width()*INVPHI), -h_2, 
+                     (int)(R2.width()*INVPHI), h - R2.height());
             QRect R4(R2.x(), R1.y(), R3.x() - R2.x(), 
-                     (int)(R3.height()/PHI));
-            QRect R5(R4.x(), R4.bottom(), (int)(R4.width()/PHI), 
+                     (int)(R3.height()*INVPHI));
+            QRect R5(R4.x(), R4.bottom(), (int)(R4.width()*INVPHI), 
                      R3.height() - R4.height());
-            QRect R6(R5.x() + R5.width(), R5.bottom() - (int)(R5.height()/PHI), 
-                     R3.x() - R5.right(), (int)(R5.height()/PHI));
-            QRect R7(R6.right() - (int)(R6.width()/PHI), R4.bottom(), 
-                     (int)(R6.width()/PHI), R5.height() - R6.height());
+            QRect R6(R5.x() + R5.width(), R5.bottom() - (int)(R5.height()*INVPHI), 
+                     R3.x() - R5.right(), (int)(R5.height()*INVPHI));
+            QRect R7(R6.right() - (int)(R6.width()*INVPHI), R4.bottom(), 
+                     (int)(R6.width()*INVPHI), R5.height() - R6.height());
 
             p.setPen(QPen(Qt::white, d->guideSize, Qt::SolidLine));
 
             // Drawing Golden sections.
             if (d->drawGoldenSection)
             {
+               // horizontal lines:
                p.drawLine( R1.left(), R2.top(),
                            R2.right(), R2.top());
 
                p.drawLine( R1.left(), R1.top() + R2.height(),
                            R2.right(), R1.top() + R2.height());
 
-               p.drawLine( R2.right() - R1.width(), R1.top(),
-                           R2.right() - R1.width(), R1.bottom() );
+               // vertical lines:
+               p.drawLine( R1.right(), R1.top(),
+                           R1.right(), R1.bottom() );
 
-               p.drawLine( R1.topRight(), R1.bottomRight() );
+               p.drawLine( R1.left()+R2.width(), R1.top(),
+                           R1.left()+R2.width(), R1.bottom() );               
             }
 
             // Drawing Golden triangle guides.
@@ -966,16 +976,19 @@
             // Drawing Golden sections.
             if (d->drawGoldenSection)
             {
+               // horizontal lines:
                p.drawLine( R1.left(), R2.top(),
                            R2.right(), R2.top());
 
                p.drawLine( R1.left(), R1.top() + R2.height(),
                            R2.right(), R1.top() + R2.height());
 
-               p.drawLine( R2.right() - R1.width(), R1.top(),
-                           R2.right() - R1.width(), R1.bottom() );
+               // vertical lines:
+               p.drawLine( R1.right(), R1.top(),
+                           R1.right(), R1.bottom() );
 
-               p.drawLine( R1.topRight(), R1.bottomRight() );
+               p.drawLine( R1.left()+R2.width(), R1.top(),
+                           R1.left()+R2.width(), R1.bottom() );               
             }
 
             // Drawing Golden triangle guides.
Comment 4 caulier.gilles 2007-06-17 09:22:46 UTC
SVN commit 676582 by cgilles:

digikam from trunk (KDE4) : Ratio crop tool : backport patch from Arnd about helper lines round off error
CCBUGS: 120450


 M  +35 -22    imageselectionwidget.cpp  


--- trunk/extragear/graphics/digikam/imageplugins/coreplugin/ratiocrop/imageselectionwidget.cpp #676581:676582
@@ -29,10 +29,10 @@
 
 #define MINRANGE 0
 
-// Fibanocci irrationel Golden Number.
-#define PHI      1.618033988
+// Golden number (1+sqrt(5))/2
+#define PHI      1.61803398874989479
 // 1/PHI
-#define INVPHI   0.61803398903633
+#define INVPHI   0.61803398874989479
 
 // C++ includes.
 
@@ -862,43 +862,53 @@
             if (d->flipHorGoldenGuide)
                 p.scale(-1, 1);
 
-            // Flip verical.
+            // Flip vertical.
             if (d->flipVerGoldenGuide)
                 p.scale(1, -1);
 
             int w = d->localRegionSelection.width();
             int h = d->localRegionSelection.height();
 
-            QRect R1(-w/2, -h/2, 
-                     (int)(w/PHI), h);
-            QRect R2((int)(w*(INVPHI - 0.5)), (int)(h*(0.5 - INVPHI)), 
-                     (int)(w*(1 - INVPHI)), (int)(h/PHI)); 
-            QRect R3((int)(w/2 - R2.width()/PHI), -h/2, 
-                     (int)(R2.width()/PHI), h - R2.height());
+            // lengths for the golden mean and half the sizes of the region:
+            int w_g = (int)(w*INVPHI);
+            int h_g = (int)(h*INVPHI);
+            int w_2 = w/2;
+            int h_2 = h/2;
+
+            QRect R1(-w_2, -h_2, w_g, h);
+            // w - 2*w_2 corrects for one-pixel difference
+            // so that R2.right() is really at the right end of the region
+            QRect R2(w_g-w_2, h_2-h_g, w-w_g+1-(w - 2*w_2), h_g); 
+
+            QRect R3((int)(w_2 - R2.width()*INVPHI), -h_2, 
+                     (int)(R2.width()*INVPHI), h - R2.height());
             QRect R4(R2.x(), R1.y(), R3.x() - R2.x(), 
-                     (int)(R3.height()/PHI));
-            QRect R5(R4.x(), R4.bottom(), (int)(R4.width()/PHI), 
+                     (int)(R3.height()*INVPHI));
+            QRect R5(R4.x(), R4.bottom(), (int)(R4.width()*INVPHI), 
                      R3.height() - R4.height());
-            QRect R6(R5.x() + R5.width(), R5.bottom() - (int)(R5.height()/PHI), 
-                     R3.x() - R5.right(), (int)(R5.height()/PHI));
-            QRect R7(R6.right() - (int)(R6.width()/PHI), R4.bottom(), 
-                     (int)(R6.width()/PHI), R5.height() - R6.height());
+            QRect R6(R5.x() + R5.width(), R5.bottom() - (int)(R5.height()*INVPHI), 
+                     R3.x() - R5.right(), (int)(R5.height()*INVPHI));
+            QRect R7(R6.right() - (int)(R6.width()*INVPHI), R4.bottom(), 
+                     (int)(R6.width()*INVPHI), R5.height() - R6.height());
 
             p.setPen(QPen(Qt::white, d->guideSize, Qt::SolidLine));
 
             // Drawing Golden sections.
             if (d->drawGoldenSection)
             {
+               // horizontal lines:
                p.drawLine( R1.left(), R2.top(),
                            R2.right(), R2.top());
 
                p.drawLine( R1.left(), R1.top() + R2.height(),
                            R2.right(), R1.top() + R2.height());
 
-               p.drawLine( R2.right() - R1.width(), R1.top(),
-                           R2.right() - R1.width(), R1.bottom() );
+               // vertical lines:
+               p.drawLine( R1.right(), R1.top(),
+                           R1.right(), R1.bottom() );
 
-               p.drawLine( R1.topRight(), R1.bottomRight() );
+               p.drawLine( R1.left()+R2.width(), R1.top(),
+                           R1.left()+R2.width(), R1.bottom() );               
             }
 
             // Drawing Golden triangle guides.
@@ -970,16 +980,19 @@
             // Drawing Golden sections.
             if (d->drawGoldenSection)
             {
+               // horizontal lines:
                p.drawLine( R1.left(), R2.top(),
                            R2.right(), R2.top());
 
                p.drawLine( R1.left(), R1.top() + R2.height(),
                            R2.right(), R1.top() + R2.height());
 
-               p.drawLine( R2.right() - R1.width(), R1.top(),
-                           R2.right() - R1.width(), R1.bottom() );
+               // vertical lines:
+               p.drawLine( R1.right(), R1.top(),
+                           R1.right(), R1.bottom() );
 
-               p.drawLine( R1.topRight(), R1.bottomRight() );
+               p.drawLine( R1.left()+R2.width(), R1.top(),
+                           R1.left()+R2.width(), R1.bottom() );               
             }
 
             // Drawing Golden triangle guides.