本文整理汇总了C#中Stroke.HitTest方法的典型用法代码示例。如果您正苦于以下问题:C# Stroke.HitTest方法的具体用法?C# Stroke.HitTest怎么用?C# Stroke.HitTest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Stroke
的用法示例。
在下文中一共展示了Stroke.HitTest方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ifEdgeGetNodes
/* Determines whether the following stroke could be interpreted as
* an edge (or edges) and if so, returns all the consecutive nodes that the
* stroke has gone through in order.
*/
public static Nodes ifEdgeGetNodes(Stroke s, Graph g)
{
Point[] sPoints = s.GetPoints();
Nodes strokeHitNodes = new Nodes();
Node prev = null;
for(int i=0; i<sPoints.Length; i++)
{
for(int j=0; j<g.Nodes.Length(); j++)
{
Node n = g.Nodes[j];
Rectangle r = n.Stroke.GetBoundingBox();
if(s.HitTest(n.CenterPoint,Math.Max(r.Width/2, r.Height/2)) && r.Contains(sPoints[i]) && !n.Equals(prev))
{
strokeHitNodes.Add(n);
prev = n;
break;
}
}
}
//If stroke hit one or less nodes, it is clearly not an edge.
if(strokeHitNodes.Length() < 2)
{
return null;
}
return strokeHitNodes;
}
示例2: HitNodeTest
/* Checks if the given stroke is within the bounds of a
* Node. It accomplishes this by using the stroke hit test.
*/
public static Node HitNodeTest(Stroke s, Graph g)
{
Rectangle rectS = s.GetBoundingBox();
Point sCenter = new Point(rectS.X + rectS.Width/2, rectS.Y + rectS.Height/2);
for(int i=0; i<g.Nodes.Length(); i++)
{
Node n = g.Nodes[i];
Rectangle rectN =n.Stroke.GetBoundingBox();
if(s.HitTest(n.CenterPoint, (float)Math.Max(rectN.Height/2.0, rectN.Width/2.0))
||n.Stroke.HitTest(sCenter, (float)Math.Max(rectS.Height/2.0, rectS.Width/2.0)))
{
return n;
}
}
return null;
}