Пример #1
0
        private bool HitTestForOutLine(System.Drawing.PointF[] points, Point hitPoint)
        {
            bool retVal = false;

            for (int i = 0; i < HandleCount - 1; i++)
            {
                // Create path which contains wide line
                // for easy mouse selection
                GraphicsPath       areaPath1 = new GraphicsPath();
                System.Drawing.Pen AreaPen1  = new System.Drawing.Pen(System.Drawing.Color.Black, 2);
                areaPath1.AddLine(points[i].X, points[i].Y, points[i + 1].X, points[i + 1].Y);
                areaPath1.Widen(AreaPen1);

                // Create region from the path
                System.Drawing.Region areaRegion = new System.Drawing.Region(areaPath1);
                System.Drawing.Point  hPoint     = new System.Drawing.Point(hitPoint.X, hitPoint.Y);
                retVal = areaRegion.IsVisible(hPoint);

                InsertAt       = i + 1;
                _pointToInsert = new Point(hitPoint.X, hitPoint.Y);

                if (retVal)
                {
                    break;
                }
            }

            return(retVal);
        }
        /// <summary>
        /// 点在区域中是否可见(现已废弃,替代方法 PointInPolygon)
        /// </summary>
        /// <param name="point"></param>
        /// <param name="pointColl"></param>
        /// <returns></returns>
        public static bool IsVisible_Region(Point point, List <Point> pointColl)
        {
            System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
            System.Drawing.Region       region         = new System.Drawing.Region();
            List <System.Drawing.Point> pathPoints     = new List <System.Drawing.Point>();

            foreach (var pathPoint in pointColl)
            {
                pathPoints.Add(new System.Drawing.Point((int)Math.Round(pathPoint.X), (int)Math.Round(pathPoint.Y)));
            }
            path.AddPolygon(pathPoints.ToArray());
            path.CloseFigure();
            region.MakeEmpty();
            region.Union(path);
            return(region.IsVisible(new System.Drawing.Point((int)Math.Round(point.X), (int)Math.Round(point.Y))));
        }