public bool Contains(RectangleD rect)
 {
     return(Contains(rect.Left, rect.Top) && Contains(rect.Right, rect.Top) && Contains(rect.Right, rect.Bottom) && Contains(rect.Left, rect.Bottom));
 }
Esempio n. 2
0
 public PointDArray(PointD[] points, RectangleD bounds)
 {
     Points = points;
     Bounds = bounds;
 }
 public bool IntersectsWith(RectangleD rect)
 {
     return(!RectangleD.Intersect(this, rect).IsEmpty);
 }
Esempio n. 4
0
        public static bool PtInRgn(double x, double y, PointD[] region)
        {
            if (region.Length == 0)
            {
                return(false);
            }

            double l = region[0].X;
            double r = l;
            double t = region[0].Y;
            double b = t;

            for (int i = 1; i < region.Length; i++)
            {
                if (region[i].X > r)
                {
                    r = region[i].X;
                }
                else
                {
                    if (region[i].X < l)
                    {
                        l = region[i].X;
                    }
                }
                if (region[i].Y > b)
                {
                    b = region[i].Y;
                }
                else
                {
                    if (region[i].Y < t)
                    {
                        t = region[i].Y;
                    }
                }
            }
            //RectangleD rd = new RectangleD(l, t, r - l, b - t);
            RectangleD rd = RectangleD.FromLTRB(l, t, r, b);

            if (!rd.Contains(x, y))
            {
                return(false);
            }

            int    count = 0;
            PointD start, end;

            for (int i = 0; i < region.Length; i++)
            {
                start = region[i];
                end   = (i == region.Length - 1) ? region[0] : region[i + 1];
                if (start.X == x && start.Y == y) //是顶点
                {
                    return(true);
                }
                else
                {
                    if (start.Y == y)          //在X轴上
                    {
                        if (start.X > x)       //在正半轴
                        {
                            if (end.Y == y)    //边终点也在X轴上
                            {
                                if (end.X < x) //点在边上
                                {
                                    return(true);
                                }
                                //否则该边可以当作一个顶点,忽略
                            }
                            else
                            {
                                if (end.Y < y)
                                {
                                    count++;
                                }
                                //左算又不算
                            }
                        }
                        else//在负半轴上
                        {
                            if (end.Y == y && end.X > x)  //点在边上
                            {
                                return(true);
                            }
                        }
                    }
                    else
                    {
                        if (end.Y == y)    //边终点在X轴上
                        {
                            if (end.X > x && start.Y < y)
                            {
                                count++;
                            }
                        }
                        else
                        {
                            if (start.Y < y && end.Y < y)
                            {
                                continue;
                            }
                            if (start.Y > y && end.Y > y)
                            {
                                continue;
                            }
                            if (start.X == end.X)
                            {
                                if (start.X > x)
                                {
                                    count++;
                                }
                            }
                            else
                            {
                                double x1 = (end.X * (start.Y - y) + start.X * (y - end.Y)) / (start.Y - end.Y);
                                if (x1 == x)
                                {
                                    return(true);
                                }
                                else if (x1 > x)
                                {
                                    count++;
                                }
                            }
                        }
                    }
                }
            }
            return((count & 1) != 0);
        }