public static Rectangle GetVideoNodeRect(VideoNode node)
        {
            Rectangle rect = new Rectangle(
                node.ptLocation.X,
                node.ptLocation.Y,
                node.Image.Width,
                node.Image.Height);

            return(rect);
        }
        /// <summary>
        /// 查找距离某个点最近的Node
        /// </summary>
        /// <param name="nodes"></param>
        /// <param name="maxDis">查找的最大距离</param>
        /// <returns></returns>
        public static VideoNode GetNearestNode(List <VideoNode> nodes, Point pt, int maxDis)
        {
            int       dis         = int.MaxValue;
            VideoNode nearestNode = null;

            foreach (VideoNode node in nodes)
            {
                int X      = node.ptLocation.X + node.Image.Width / 2;
                int Y      = node.ptLocation.Y + node.Image.Height / 2;
                int curDis = (X - pt.X) * (X - pt.X) + (Y - pt.Y) * (Y - pt.Y);
                if (
                    curDis < dis &&
                    curDis < (maxDis + node.Image.Width / 2) * (maxDis + node.Image.Width / 2)
                    )
                {
                    dis         = curDis;
                    nearestNode = node;
                }
            }
            return(nearestNode);
        }
Esempio n. 3
0
 public ConnectLine(VideoNode start, VideoNode end)
 {
     this.startNode = start;
     this.endNode   = end;
 }
 /// <summary>
 /// 判断某个点是否在某个Node之内
 /// </summary>
 /// <param name="pt"></param>
 /// <param name="node"></param>
 /// <returns></returns>
 public static bool IsPointInNode(Point pt, VideoNode node)
 {
     return(IsPointInRectangle(pt, GetVideoNodeRect(node)));
 }