Private Function IsNotInEither(typObject As typDraw, X As Single, Y As Single) As Boolean
Dim sngA As Single, sngB As Single, Ratio As Single, Ratio1 As Single
Dim sngX1 As Single, sngY1 As Single, sngX2 As Single, sngY2 As Single
Dim lngR As Single
Dim blnIsNotInEither As Boolean
With typObject
sngX1 = .X1 * sngMulripleEnlarge
sngY1 = .Y1 * sngMulripleEnlarge
Select Case .Shape
Case conTLine '当对象为线时
sngX2 = .X2 * sngMulripleEnlarge
sngY2 = .Y2 * sngMulripleEnlarge
If sngX2 = sngX1 Then '判断是否为垂直线
Ratio = .BorderWidth * conBorder * sngMulripleEnlarge + conLineWidth
If (Y >= sngY1 - Ratio And Y <= sngY2 + Ratio And X > sngX1 - Ratio And X < sngX1 + Ratio) Or _
(Y >= sngY2 - Ratio And Y <= sngY1 + Ratio And X > sngX1 - Ratio And X < sngX1 + Ratio) Then blnIsNotInEither = True
Else
sngA = (sngY1 - sngY2) / (sngX1 - sngX2)
sngB = sngY1 - sngA * sngX1
Ratio1 = Y - sngA * X
Ratio = .BorderWidth * conBorder * sngMulripleEnlarge + conLineWidth
Ratio = Ratio * Sqr(1 + sngA * sngA)
If Ratio1 < sngB + Ratio And Ratio1 > sngB - Ratio Then
Ratio = .BorderWidth * conBorder + conLineWidth
If ((Y >= sngY1 - Ratio And Y <= sngY2 + Ratio) Or (Y >= sngY2 - Ratio And Y <= sngY1 + Ratio)) _
And ((X > sngX1 - Ratio And X < sngX2 + Ratio) Or (X > sngX2 - Ratio And X < sngX1 + Ratio)) Then blnIsNotInEither = True
End If
End If
Case conTRectangle '当对象为矩形时
由于GIS的信息海量,关于判断点是否在某个对象内,我们做程序时只能让CPU始终一直不停的Doing this Test,在我们的做法大致是这样的:
失量化的关键数据且比较小的全部读入内存,其他稍微较大的放在数据库中,当前屏幕逻辑坐标范围始终能计算出来,在相关的数据中皆有与屏幕对应的键值,这句话的意思说白了,将失量化图形划分为十几个区或几十个区,简化搜索范围。这样能提高效率!
现成提供几个函数.以供检测范围.
//计算点(x1,y1)与点(x2,y2)间的距离
float CDraw::CalDisp(long x1, long y1, long x2, long y2)
{
return (float)sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
//作用:计算点(xx,yy)到线段(x1,y1)(x2,y2)的距离,返回计算的距离值
//函数PointRgn作用:判断一个点是否在任意多边形区域内
//参数:Numble-边界点数,x,y是点的坐标,多边形顶点的坐标在结构数组PointList中
//返回:1-点在多边形区域0-不在
float CDraw::PointLine(long xx, long yy, long x1, long y1, long x2, long y2)
{
float a, b, c, ang1, ang2, ang;
//计算三条边的距离
a=CalDisp(x1, y1, xx, yy); if(a == 0.0) return 0.0;
b=CalDisp(x2, y2, xx, yy); if(b == 0.0) return 0.0;
c=CalDisp(x1, y1, x2, y2);
//检查矩形是否与屏幕矩形相交
BOOL IsRectCross(float minx,float miny,float maxx,float maxy)
{
if(minx>xMaxScreen and and maxx<xMinScreen and and miny>yMaxScreen and and maxy<yMinScreen) //两个矩形区域不相交
return 0; //如不相交函数返回0
else
return 1; //如果相交就返回1
}