Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7632861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:43:59+00:00 2026-05-31T06:43:59+00:00

One critical piece of code on my application involves enumerating all rectangles on a

  • 0

One critical piece of code on my application involves enumerating all rectangles on a 2-D surface. The rectangles do not intersect each other and I must be able to enumerate all rectangles within a given rectangular boundary.

I already have a function to return the rectangle for a given coordinate, if it exists

GetRectangle( int row, int col )

Here is how I would call the resulting code.

foreach( var rect in GetRectangles( row, col, rowCount, colCount ) ) {
   //..  my processing code here
}

Obviously, I could call the function GetRectangle() for each of the points in the surface. I can also skip the width of the rectangle that was returned from the previous call as I know that they do not intersect. But, this is still not efficient enough.

Are you aware of such an algorithm?

UPDATE: The surface is not necessarily covered by rectangles but it can be for some special cases. So, the function GetRectangle( int row, int col ) might return null.

Think of the surface as a bitmap filled with random rectangles (which don’t intersect). The task is to return all rectangles on that surface that falls within (i.e. intersects) a given frame. Hope this will clarify the question.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T06:44:00+00:00Added an answer on May 31, 2026 at 6:44 am

    For best results, organize your collection of rectangles into a spatial lookup structure. In this case it sounds as though a R-tree would be a good bet. But if you can’t do that, and GetRectangle is all you’ve got, then here is what I’d do:

    The plan is to maintain a list of integers xj for 0 ≤ j < rowCount, where xj is the leftmost point on row j for which I have not yet found a rectangle covering it.

    1. Start by initializing xj := 0 for all j.

    2. If xj = colCount for all j, we are done. Stop.

    3. Let J = min(j | xj = min(xi)). Then xJ is the topmost leftmost point that I have not yet found a rectangle that covers it.

    4. Call GetRectangle(xJ, J). If this does not return a rectangle, then the point is uncovered. Set xJ := xJ + 1 and go to step 2.

    5. Otherwise, we have a rectangle with top left corner at (xJ, J). Call its width w and height h. For J ≤ j < J + h, set xj := xj + w. Go to step 2.

    Here’s an example run of this algorithm. The list of xj is shown by the numbers at the left, with the topmost leftmost highlighted in bold. The orange rectangle is the one that’s discovered at that step of the algorithm.

    The algorithm finds seven rectangles in seven steps

    For efficient discovery of the minimum at step 3, you might want to keep the list of xj in a heap.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have time-critical piece of code in my app. I made the thread which
The lock statement ensures that one thread does not enter a critical section of
We are considering development of a mission critical application in Java EE, and one
I am optimizing a c++ code. at one critical step, I want to implement
iTunes Connect's developer guide left out one critical piece of information about editing titles
I have a working NSCollectionView with one minor, but critical, exception. Getting and highlighting
Every time a database diagram gets looked out, one area people are critical of
One may not always know the Type of an object at compile-time, but may
I am trying to use Aspose.Words library through COM Interop. There is one critical
I'm using ParallelPython to develop a performance-critical script. I'd like to share one value

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.