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 5959777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:43:57+00:00 2026-05-22T18:43:57+00:00

I need algorithm which splits big static sized rectangle to small ones. A perfect

  • 0

I need algorithm which splits big static sized rectangle to small ones. A perfect implementation for me look like this:

struct RECT
{
  int l,t,r,b;
};

class BigRect
{
public:
  // width and height of big rect
  BigRect( unsigned width, unsigned height );

  // returns -1 if rect cannot be allocated, otherwise returns id of found rect
  int GetRect( unsigned width, unsigned height, RECT &out );

  // returns allocated rect to big rectangle
  void FreeRect( int id );
};

void test()
{
  BigRect r( 10, 10 );

  RECT out;
  r.GetRect( 4, 4, out ); // rect found ({0,0,4,4} for example), returns 1
  r.GetRect( 5, 5, out ); // rect found ({4,0,9,5} for example), returns 2

  r.GetRect( 6, 6, out ); // no place found for rect, returns -1
  r.FreeRect( 2 );        // add {4,0,9,5} back to rect

  r.GetRect( 6, 6, out ); // rect found (4,0,10,6)
}

So I need algorithm for GetRect and FreeRect methods. Any ideas and links would be appreciated.

  • 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-22T18:43:58+00:00Added an answer on May 22, 2026 at 6:43 pm

    What you’re trying to do is online 2D bin packing. It’s online because you don’t have all your small pictures in hand before you attempt to pack them into the big picture. Furthermore some small pictures will be “deallocated” and their space will be freed up. On the other hand, an offline algorithm allows you to do things like sort your small pictures from largest to smallest before packing them.

    Here’s an article that surveys the state of the art in 2D packing: Survey on two-dimensional packing. It’s quite theoretical.

    This article A New Upper Bound on 2D Online Bin Packing cites other articles that describe online 2D packing algorithms.

    People in the gaming world have a similar problem as you do; they call it texture packing or texture atlas. However, they use offline algorithms.

    John Ratcliff posted a blog article on texture packing.

    See also this related question on gamedev: https://gamedev.stackexchange.com/questions/2829/texture-packing-algorithm

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

Sidebar

Related Questions

I need to find an algorithm which determines a relationship between a square and
Need Hints to design an efficient algorithm that takes the following input and spits
I have millions of short (up to 30 words) documents which I need to
I have a program in which I need to apply a 2-dimensional texture (simple
I have a game which I would like the time and score to be
I'm writing an application which processes a lot of xml files (>1000) with deep
I need to use a string as the ID to obtain some object. At
I have an algorithmic problem in which I have derived a transfer matrix between
I know that Floyd–Steinberg dithering algorithm can't be implemented with pixel shader, because that
I want to write a little helper utility to organize my digitized audiobooks collection.

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.