• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: | 推荐给好友 上一篇 | 下一篇

Check两个物件是否相碰

发布: 2007-6-21 21:57 | 作者:   | 来源:   | 查看: 17次 | 进入软件测试论坛讨论

领测软件测试网

    Check两个物件是否相碰


作者: cww 

    基本上这两个物件要是一个四方形的区域,如果是不规则形者,不在此限,
这个问题似乎没有很大的困难,不过API有提供了,何不用上一用省得程式得长,又

Bug就不好了。
  另外,如果Check某个点有没有在某个RECT中,则用PtInRect API,这应没有什麽太困
难,所以没有范例,而某条线和Rect又有没有相交呢?似乎没有什麽API来做,所以可
以考虑使用PtInRect()来做,将线条的每个点传进去Check不就知道,只是如何取得线
条上的每一个点,我只会土法炼钢,程式臭臭长长的,不敢拿出来给大家叁考,所以
若有人有其演算法,可以Mail给我

注释:以下在.Bas中
Type RECT 注释:榘形的四个座标
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
End Type
Type POINTAPI
        x As Long
        y As Long
End Type
Declare Function IntersectRect Lib "user32" (lpDestRect As RECT,  _
        lpSrc1Rect As RECT, lpSrc2Rect As RECT) As Long
Declare Function PtInRect Lib "user32" (lpRect As RECT,  _
        pt As POINTAPI) As Long

注释:Check rect1, rect2有没有相交集,若有,则Orect存相交集的四个座标
Public Function GetOverlap(rect1 As RECT, rect2 As RECT, Orect As RECT) _
       As  Boolean
Dim i As Long
GetOverlap = False
i = IntersectRect(Orect, rect1, rect2)
If i <> 0 Then GetOverlap = True
End Function

注释:以下在Form中,form中放两个CommandBox
Private Sub Form_Load()
Dim i As Long, rect1 As RECT, rect2 As RECT, rect3 As RECT
Dim oo As Boolean
rect1.Top = Command1.Top
rect1.Left = Command1.Left
rect1.Bottom = Command1.Top + Command1.Height
rect1.Right = Command1.Left + Command1.Width

rect2.Top = Command2.Top
rect2.Left = Command2.Left
rect2.Bottom = Command2.Top + Command2.Height
rect2.Right = Command2.Left + Command2.Width

oo = GetOverlap(rect1, rect2, rect3)
End Sub


文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备10010545号-5
技术支持和业务联系:info@testage.com.cn 电话:010-51297073

软件测试 | 领测国际ISTQBISTQB官网TMMiTMMi认证国际软件测试工程师认证领测软件测试网