Changeset 913


Ignore:
Timestamp:
Sep 25, 2006, 1:42:53 AM (15 years ago)
Author:
livings124
Message:

Use square root instead of a while loop.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/nat-traversal/PiecesWindowController.m

    r911 r913  
    108108    }
    109109   
    110     int numPieces = MAX_ACROSS * MAX_ACROSS;
    111     if (numPieces > [fTorrent pieceCount])
     110    int numPieces = MAX_ACROSS * MAX_ACROSS, across;
     111    if ([fTorrent pieceCount] < numPieces)
     112    {
    112113        numPieces = [fTorrent pieceCount];
    113    
    114     //determine how many boxes
    115     int across = MAX_ACROSS;
    116     while (numPieces <= (across - 1) * (across - 1))
    117         across -= 1;
    118    
    119     float width = ([fExistingImage size].width - (float)((across + 1) * BETWEEN)) / (float)across;
     114       
     115        //determine how many boxes
     116        across = sqrt(numPieces);
     117        if (across * across < numPieces)
     118            across++;
     119    }
     120    else
     121        across = MAX_ACROSS;
     122   
     123    float width = ([fExistingImage size].width - (float)(across + 1) * BETWEEN) / (float)across;
    120124   
    121125    int8_t * pieces = malloc(numPieces);
Note: See TracChangeset for help on using the changeset viewer.