确定哪些对象落在选择矩形(选取框)内
我正在编写一个程序(除其他外)为用户提供类似 IDE 的环境,用户可以在其中使用矩形选择工具选择一个或多个对象。
所有选择都将是一个简单的矩形,所有可选择的对象也将是简单的矩形。
我已经有了代码(VB.Net)来在视觉上创建橡皮筋效果 - 我需要的是一种有效的算法,它可以告诉我哪些对象的至少一部分区域位于最终选择矩形内。
如果它有助于可视化,我想要做的将与在 Windows 桌面上的图标上拖动选择框相同...无论哪个图标的部分区域位于该选择选取框内,都会突出显示(选定)。
任何帮助将不胜感激...提前谢谢您
I'm writing a program that (amongst other things) provides an IDE-like environment for the user where they can select one or more objects with a rectangualr selection tool.
All selections will be a simple rectangle, and all selectable objects will be simple rectangles as well.
I already have the code (VB.Net) to create the rubber-banding effect visually - what I need is an efficient algorithm that will tell me what objects have at least a portion of their area within the final selection rectangle.
If it helps to visualize, what I want to do would be identical to dragging a selection box over icons on the Windows desktop... whichever icons have even a portion of their areas located within that selection marquee are highlighted (selected).
Any help would be appreciated... thank you in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
IntersectsWith 的作用如下BigFunger 已经提到过。但此外,您应该检查矩形是否 包含 另一个矩形(intersectsWith 仅检查相交)。
一个小样本表格演示了它:
更新:将此代码更改为 1.首先在两个方向上进行检查,2.对您来说更重要的是:还检查一个矩形是否不仅与另一个矩形相交,而且还检查是否它包含另一个。
IntersectsWith works as BigFunger already has mentioned. But aditionally you should check if a rectangle contains another rectangle(intersectsWith only checks for intersection).
A small sample-form that demonstrates it:
UPDATE: changed this code to 1.first check in both directions and 2. and more important for you: checks also if one rectangle not only intersects another but additionally if it contains another.