In the past, Hans has explained the first-fit layout algorithm for polygonal shaped exclusions. This algorithm is used to find the topmost location that a content box can fit into. Now he has written up a post on using the first-fit algorithm on rounded rectangle shapes. Interestingly enough, rounded rectangles do not only include rectangles with rounded corners; standard rectangles, ellipses, and even circles can all be specified as rounded rectangles. Thus, this algorithm can be used to fit content inside of all of these shapes. Even if you’re not interested in all of the implementation details, Hans’s post includes an interactive demonstration of the algorithm that is worth checking out.
Read more at Hans Muller’s blog.