处理板上形状的选择
我有一块板作为画布,上面画了几个形状,其中一些是三角形、圆形、矩形,但所有形状都包含在它们自己的边界分隔矩形内。
“圆将位于矩形内”
我将两个圆 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您正在处理它以及它可以处理的事情 - 窗口系统通常遵循 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
如果您确实需要速度,可以使用一些技巧。 例如:
如果您只是追求简单的实现,一个快速技巧就是记录 X 和 X 值。 Y,重新绘制屏幕,并注意哪个对象绘制了该像素。
——马库斯Q
There are tricks you can play if you really need speed. For example:
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