处理板上形状的选择

发布于 2024-07-14 04:17:43 字数 451 浏览 5 评论 0原文

我有一块板作为画布,上面画了几个形状,其中一些是三角形、圆形、矩形,但所有形状都包含在它们自己的边界分隔矩形内。

“圆将位于矩形内”

我将两个圆 A、B 放在板上,其中 A 在 B 上方并且有一些区域发生碰撞。 如果我单击与容器框相对应的 A 区域,但不是实际的 A 圆形区域,我不会选择 A 圆形,但这会阻止我选择 B,因为我的 A 容器重叠并位于 B 之上。

在事件基础框架中,我猜子事件将传递给父事件而不是兄弟事件。

所以我的选择是检查所有形状容器,这些容器在 x 点有一些区域,按 z 索引排序。 然后对于每个容器检查其内部的形状是否发生碰撞。

看起来效率不是很高,但是还有其他方法吗?

---------
|    --------  
|    |      |
-----|      |
     --------

I have a board as a canvas with several shapes drawn on it, some of them are triangles, circles, rectangles but all are contained inside their own bound delimited rectangle.

"The circle will be inside a rectangle"

I put two circles A, B on the board where A is over B and has some area colliding.
If I click on A area corresponding to the container box but not the actual A circle shape area I wont select the A circle, however that would stop me from selecting B since my A container overlaps and is over B one.

In an event base framework, the child event will go to the parent not siblings I guess.

So my choice was to do a check for all shape container which have some area at point x ordered by z index. Then for each container check if the shape inside it collide.

It does not seem super efficient but is there any other ways?

---------
|    --------  
|    |      |
-----|      |
     --------

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

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

发布评论

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

评论(2

合约呢 2024-07-21 04:17:43

您正在处理它以及它可以处理的事情 - 窗口系统通常遵循 Z 顺序(层)。

无论如何,从长远来看,这会更好,特别是如果您希望能够通过在项目周围绘制选择框来选择多个项目。

有一些算法可以通过将矩形转换为 x 轴和 y 轴上的二维表示来查找矩形是否重叠。 您可以执行相同的操作,然后比较您的点以查看您的点重叠的对象:

检测两个矩形相交的算法?

只需将您的点选择(或矩形选择,如果您绘制边界框来选择多个项目)视为另一个矩形,以与其他矩形重叠进行比较。

-亚当

You're handling it about as well as it can be handled - windowing systems generally obey Z order (layers).

This will be better in the long run anyway, especially if you want to be able to select multiple items by drawing a selection box around them.

There are algorithms for finding if rectangles overlap by converting them into 2d representations on both the x and y axis. You can do the same thing, and then compare your point to see which objects your point overlaps:

Algorithm to detect intersection of two rectangles?

Just treat your point selection (or rectangle selection if you draw a bounding box to select multiple items) as another rectangle to be compared as overlapping to the others.

-Adam

千纸鹤带着心事 2024-07-21 04:17:43

如果您确实需要速度,可以使用一些技巧。 例如:

  • 如果您使用深托盘,则可以使用颜色的低位来标记对象。 然后查看像素即可获得对象,或者至少避免您快速彻底剔除列表。
  • 即使在低位深度下,如果对象都是单色的,您也可以使用整个颜色。
  • 如果分辨率足够低,您可以保留一个数组,说明哪个对象拥有哪个像素。
  • 在更高的分辨率下,您可以执行相同的操作,但使用 RLE 来缩小尺寸(同时查看四叉树)
  • 等等...

如果您只是追求简单的实现,一个快速技巧就是记录 X 和 X 值。 Y,重新绘制屏幕,​​并注意哪个对象绘制了该像素。

——马库斯Q

There are tricks you can play if you really need speed. For example:

  • If you are working with a deep pallet you can use the low order bits of the color to tag the objects. Then peeking at the pixel gives you the object or at least lest you quickly drastically cull the list.
  • Even at low bit depth, if the objects are all monochrome you can use the whole color
  • If you're in low enough resolution you can keep an array that says what object owns what pixel.
  • At higher res you can do the same but use RLE to keep the size down (also look into quad trees)
  • And so forth...

If it's just simple implementation you're after, one quick trick is to record the X & Y, repaint the screen, and note which object paints that pixel.

-- MarkusQ

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