Welcome, Guest. Please login or register.

Author Topic: One for the algorithm fanatics..  (Read 1816 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline volmer

  • Newbie
  • *
  • Join Date: Feb 2002
  • Posts: 28
    • Show all replies
    • http://qeep.dk/~volmer/
Re: One for the algorithm fanatics..
« on: March 10, 2004, 02:55:15 PM »
Hi,

Sounds like a fun problem. If I understand it correctly, you have a list of (in some cases overlapping) rectangles, and from that you want to generate a new list of rectangles that together cover the same area as the rectangles of the original list, but where none of them overlap. Is that correct?

After some paper sketching :) here are my initial thoughts about it in pseudo code:

Code: [Select]

// Pop the largest rectangle from original list
while rect = olist.pop()
 
  // Get rectangles overlapping 'rect' in new list
  overlapping = nlist.overlapping(rect)
 
  // For each overlapping rectangle
  for each overlap in overlapping
 
    // If 'rect' takes priority over 'overlap'
    if rect.stronger(overlap)
   
      segments = overlap.divide(rect)        // Divide 'overlap' into segments
     
      nlist.replace(overlap, segments.pop()) // Replace 'overlap' with largest segment  
      olist.join(segments)                   // Put remaining segments in original list
     
    else
 
      segments = rect.divide(overlap) // Divide 'rect' into segments
      rect     = segments.pop()       // Set 'rect' to be the largest segment
      olist.join(segments)            // Put remaining segments in original list
     
    end if
     
  end for each
 
  // If rect hasn't gone away
  if rect.size > 0
   
    // Put it in new list
    nlist.push(rect)
   
  end if
 
end while