java gdi_GDI绘图1——自定义函数

bool JudgingState(List shapeList, int X, intY)

{var shape =JudgingShape(shapeList, X, Y);return shape == null ? false : true;

}//功能函数,当鼠标在指定区域内,判断是哪个元素发生改变

Shape JudgingShape(List shapeList, int X, intY)

{

Shape shapeItem=null;foreach (Shape item inshapeList)

{if (item != null)

{if (item isLine)

{double bianC =CountDistance(item.P1.X, item.P1.Y, item.P2.X, item.P2.Y);double bianA =CountDistance(item.P1.X, item.P1.Y, X, Y);double bianB =CountDistance(item.P2.X, item.P2.Y, X, Y);if (bianA + bianB < bianC +rongChaZhi)

{

shapeItem=item;break;

}

}else if (item isMyRectangle)

{double bianC1 =CountDistance(item.P1.X, item.P1.Y, item.P2.X, item.P1.Y);double bianC2 =CountDistance(item.P2.X, item.P1.Y, item.P2.X, item.P2.Y);double bianC3 =CountDistance(item.P2.X, item.P2.Y, item.P1.X, item.P2.Y);double bianC4 =CountDistance(item.P1.X, item.P2.Y, item.P1.X, item.P1.Y);double bianC1A =CountDistance(X, Y, item.P1.X, item.P1.Y);double bianC1B =CountDistance(X, Y, item.P2.X, item.P1.Y);double bianC2A =CountDistance(X, Y, item.P2.X, item.P1.Y);double bianC2B =CountDistance(X, Y, item.P2.X, item.P2.Y);double bianC3A =CountDistance(X, Y, item.P2.X, item.P2.Y);double bianC3B =CountDistance(X, Y, item.P1.X, item.P2.Y);double bianC4A =CountDistance(X, Y, item.P1.X, item.P2.Y);double bianC4B =CountDistance(X, Y, item.P1.X, item.P1.Y);if (bianC1A + bianC1B < bianC1 + rongChaZhi || bianC2A + bianC2B < bianC2 + rongChaZhi || bianC3A + bianC3B < bianC3 + rongChaZhi || bianC4A + bianC4B < bianC4 +rongChaZhi)

{

shapeItem=item;break;

}

}else if (item isEllipse)

{

}else{

shapeItem= null;

}

}

}returnshapeItem;

}//计算距离公式

private double CountDistance(double pAx, double pAy, double pBx, doublepBy)

{return Math.Sqrt(Math.Abs(pAx - pBx) * Math.Abs(pAx - pBx) + Math.Abs(pAy - pBy) * Math.Abs(pAy -pBy));

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值