最优布局算法
我正在基于本文在 ASP.NET 应用程序中实现 CSS Sprites 设置。
http://weblogs.asp.net/zowens/archive/2008/03/05/css-sprite-for-asp-net.aspx
中“已经获得 SPRITE!”...作者说...
“唯一真正的缺点是所有图像都是垂直排列的。我不太确定这很重要,但大多数其他生成器都能够以某种方式将图像垂直和水平排列。”
我确信这一定是一个以前解决过的问题,所以我的问题是,“给定一组矩形,你能以最佳方式有效地布置它们吗?”(我想这取决于我的定义最佳,但最接近正方形作为开始(尽管实际上可能并非如此。))此外,您是否需要提前所有矩形,或者可以逐步完成吗?
I'm implementing a CSS Sprites setup in my ASP.NET application based on this article..
http://weblogs.asp.net/zowens/archive/2008/03/05/css-sprite-for-asp-net.aspx
In the section "Get the SPRITE already!"... the author says...
"The only real down side to this is that all your images are lined up vertically. I'm not quite sure that this matters, but most other generators have the ability to somehow line the images up vertically and horizontally."
I'm sure this must be a previously solved problem so my question is, "Given a collection of rectangles, can you efficiently lay these out in an optimal way?" (I suppose it depends on my definition of optimal, but being the closest possible to a square as a start. (although this may not actually be the case.)) Also, would you need all the rectangles in advance or could this be done progressively?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这称为矩形填充问题。 即使在非常简单的情况下,找到最佳解决方案也是 NP 困难的,尽管通常有很好的启发式方法。 谷歌搜索矩形包装给出了一些有趣的算法和代码。
This is known as the rectangle packing problem. Even in very simple cases, finding the optimal solution is NP-hard, although often there are good heuristics. Googling rectangle packing gives some interesting algorithms and code.