以整数精度合并(布尔并集)矩形区域

发布于 2024-09-25 10:42:47 字数 352 浏览 0 评论 0原文

给定任意数量的相交、不相交和接触的矩形,如何找到(多条)轮廓折线?矩形是在像素坐标中定义的,因此它们具有整数精度,但它们可能有数千个单位大。

Box collection

我确实需要轮廓的数字坐标,合并 GDI 区域是行不通的。我知道我可以通过创建 GDI 区域并调用 GetRegionScans 来简化问题,但它仍然无法解决问题。

这是实时 UI 的一部分,因此算法需要相当快(我猜永远不会超过十几个盒子,也许一百个)。

我正在用 C# 执行此操作,但由于这是一个算法问题,所以我并不真正关心语言。任何想法都非常受欢迎。

Given any number of intersection, disjoint and touching rectangles, how to find the (multiple) outline polylines? Rectangles are defined in pixel coordinates so they have integer accuracy, but they may be thousands of units large.

Box collection

I really need numeric coordinates for the outlines, merging GDI regions won't do. I know I can simplify the problem by creating a GDI region and calling GetRegionScans, but it still won't solve the problem.

This is part of real-time UI, so the algorithm needs to be reasonably fast (I'm guessing never more than a dozen or so boxes, maybe a hundred).

I'm doing this in C#, but since this is an algorithmic question I don't really care about language. Any ideas most welcome.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

┼── 2024-10-02 10:42:47

我不知道这是否满足您的性能要求,但它应该有效:

  1. 从一组空的矩形开始。
  2. 将每个矩形添加到集合中。如果一个矩形与现有矩形重叠,则根据需要将矩形拆分为多个矩形,以便没有矩形与另一个矩形重叠。
  3. 将每个不重叠矩形的四个边添加到一组线中。
  4. 删除所有不唯一的行。

结果集包含构成轮廓的所有线条。


            插图

I have no idea if this satisfies your performance requirements, but it should work:

  1. Start with an empty set of rectangles.
  2. Add each rectangle to the set. If a rectangle overlaps an existing rectangle, split the rectangles into as many rectangles as needed, such that no rectangle overlaps another.
  3. Add the four sides of each non-overlapping rectangle to a set of lines.
  4. Remove all lines that are not unique.

The resulting set contains all the lines that make up the outline.


            Illustration

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文