This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Chunkbar displays wrong.

Tags: None
(comma "," separated)
imported4-Anonymous
Registered Member
Posts
329
Karma
0

Chunkbar displays wrong.

Sun Nov 13, 2005 10:24 am
When chunkCount>barWidth and chunkCount<2*barWidth the bar ends when chunkNumber=barWidth.

Fix (Applied on SVS-version 480096)
Change UNIT32 to double on chunks_per_pixel
--------------------------------------
chunkbar.cpp
Code: Select all
void ChunkBar::drawMoreChunksThenPixels(QPainter *p,const BitSet & bs,const QColor & color)
   {
      Uint32 w = contentsRect().width();
      double chunks_per_pixel = (double)bs.getNumBits() / w;   
      QValueList<Range> rs;
      
      for (Uint32 i = 0;i < w;i++)
      {
         Uint32 num_dl = 0;
         Uint32 jEnd= (Uint32)((i+1)*chunks_per_pixel+0.5);
         for (Uint32 j = (Uint32)(i*chunks_per_pixel);j < jEnd;j++)
            if (bs.get(j))
               num_dl++;
   
         if (num_dl == 0)
            continue;



Pär H
[/code]
imported4-Anonymous
Registered Member
Posts
329
Karma
0

Sun Nov 13, 2005 10:40 am
Sorry, Korrektion.
Chunks did never reach 100%
Code: Select all
   void ChunkBar::drawMoreChunksThenPixels(QPainter *p,const BitSet & bs,const QColor & color)
   {
      Uint32 w = contentsRect().width();
      double chunks_per_pixel = (double)bs.getNumBits() / w;   
      QValueList<Range> rs;
      
      for (Uint32 i = 0;i < w;i++)
      {
         Uint32 num_dl = 0;
         Uint32 jStart=(Uint32)(i*chunks_per_pixel);
         Uint32 jEnd= (Uint32)((i+1)*chunks_per_pixel+0.5);
         for (Uint32 j = jStart;j < jEnd;j++)
            if (bs.get(j))
               num_dl++;
   
         if (num_dl == 0)
            continue;
   
         int fac = int(100*num_dl / (jEnd-jStart));

George
Moderator
Posts
5421
Karma
1

Sun Nov 13, 2005 7:19 pm
You're right, using an integer for chunks per pixel could cause some rounding errors.
imported4-Anonymous
Registered Member
Posts
329
Karma
0

Sun Nov 13, 2005 7:59 pm
You missed the calculation of fac, the roundning of the value almost newer reach 100%, 99% is interpreted as 75 when setting colour.

For example:
Code: Select all
int fac = int(100*((double)num_dl / (jEnd-jStart)) + 0.5);
George
Moderator
Posts
5421
Karma
1

Sun Nov 13, 2005 8:23 pm
Fixed, thanks !
Pär H
Registered Member
Posts
28
Karma
0

Tue Nov 15, 2005 8:59 pm
Additional korrektion.

change:
int fac = int(100*((double)num_dl / (jEnd - jStart) + 0.5));
to
int fac = int(100*((double)num_dl / (jEnd - jStart)) + 0.5);
-----------

if
num_dl=(jEnd-jStart)=5 for example
then
int(100*(5/5+0.5)) = 150
and 150!=100 when selecting colour

korrekt
int (100*(5/5))+0.5) = int (100.5) = 100

Last edited by Pär H on Wed Nov 16, 2005 9:01 pm, edited 1 time in total.
George
Moderator
Posts
5421
Karma
1

Wed Nov 16, 2005 8:46 pm
* takes precendence over +

So 100*(5/5)+0.5) = 100 + 0.5 = 100.5
Pär H
Registered Member
Posts
28
Karma
0

Wed Nov 16, 2005 8:59 pm
() take precendence over both + and *
George
Moderator
Posts
5421
Karma
1

Wed Nov 16, 2005 9:04 pm
**** didn't see them, just looked at your example.

EDIT: it's fixed now


Bookmarks



Who is online

Registered users: bancha, Bing [Bot], Google [Bot], Sogou [Bot]