Results 1 to 3 of 3

Thread: Packing known number of uniform-sized squares into a known rect

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2010
    Posts
    73
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    6
    Thanked 8 Times in 8 Posts

    Default Re: Packing known number of uniform-sized squares into a known rect

    If you state that s must be an integer, then I guess that I missed it, so i will assume that it is not an integer.

    You know that the total area is given by wh and that there are n squares. Divide wh by n and you have the maximum size for each square. So, you can set an upper bound on s as (s^2 <= w * h / n).

    We are not using an integer for s, so we know that there will be an exact fit on either the width or the height. So, take the square root of (w * h / n) and set this to s.

    Let a = w / s - floor(w/s)
    Let b = h / s - floor(h/s)

    No time to finish my thoughts, and I have not worked this out, but, I am thinking about reducing s such that either w / s or h / s is an integer (which should be a simple calculation). Uggg!

  2. #2
    Join Date
    Jan 2010
    Posts
    73
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    6
    Thanked 8 Times in 8 Posts

    Default Re: Packing known number of uniform-sized squares into a known rect

    The entire floor thing is not correct I think. I believe the following to be true (assuming s is known):

    w/s * floor(h/s) <= n <= w / s * ceiling(h/s) <= w / s * h / s = w*h / s^2

    I think that I would explore an initial guess of s as D = sqrt(w * h / n), then do something silly like

    We know that s <= D.

    E = min(h / ceiling(h/D), w / ceiling(w/D))

    E is designed such that either h/E or W/E is an integer. The point to note is that this provides a value for s such that it completely fills one of the dimensions. My guess is that (if there is no rounding) that this will provide you with the optimal solution.

Similar Threads

  1. QListView Icons with uniform sizes
    By psih128 in forum Qt Programming
    Replies: 2
    Last Post: 23rd November 2009, 11:25
  2. How to make a QMainWindow fixed sized?
    By Goldmmbr in forum Newbie
    Replies: 2
    Last Post: 18th November 2009, 09:52
  3. Non-uniform cells
    By ttvo in forum Qt Programming
    Replies: 2
    Last Post: 22nd April 2009, 20:20
  4. how to put different sized icons in a QListView
    By namume in forum Qt Programming
    Replies: 1
    Last Post: 5th February 2008, 11:57
  5. Dynamically sized QTableWidget
    By therealjag in forum Qt Programming
    Replies: 3
    Last Post: 31st March 2006, 22:06

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.