Beispiel #1
0
 public RectI Set(RectI r)
 {
     this.x      = r.x;
     this.y      = r.y;
     this.width  = r.width;
     this.height = r.height;
     return(this);
 }
Beispiel #2
0
        public RectI GetIntersection(RectI rect)
        {
            int x1 = MathUtils.Max(x, rect.x);
            int x2 = MathUtils.Min(x + width, rect.x + rect.width);
            int y1 = MathUtils.Max(y, rect.y);
            int y2 = MathUtils.Min(y + height, rect.y + rect.height);

            return(new RectI(x1, y1, x2 - x1, y2 - y1));
        }
Beispiel #3
0
        public static bool Contains(int[] xPoints, int[] yPoints,
                                    int nPoints, RectI bounds, int x, int y)
        {
            if ((bounds != null && bounds.Inside(x, y)) ||
                (bounds == null && SetBoundingBox(tmp_rect_I, xPoints,
                                                  yPoints, nPoints).Inside(x, y)))
            {
                int hits  = 0;
                int ySave = 0;
                int i     = 0;

                while (i < nPoints && yPoints[i] == y)
                {
                    i++;
                }
                for (int n = 0; n < nPoints; n++)
                {
                    int j = (i + 1) % nPoints;

                    int dx = xPoints[j] - xPoints[i];
                    int dy = yPoints[j] - yPoints[i];

                    if (dy != 0)
                    {
                        int rx = x - xPoints[i];
                        int ry = y - yPoints[i];

                        if (yPoints[j] == y && xPoints[j] >= x)
                        {
                            ySave = yPoints[i];
                        }
                        if (yPoints[i] == y && xPoints[i] >= x)
                        {
                            if ((ySave > y) != (yPoints[j] > y))
                            {
                                hits--;
                            }
                        }
                        if (ry * dy >= 0 &&
                            (ry <= dy && ry >= 0 || ry >= dy && ry <= 0) &&
                            MathUtils.Round(dx * ry, dy) >= rx)
                        {
                            hits++;
                        }
                    }
                    i = j;
                }
                return((hits % 2) != 0);
            }

            return(false);
        }
Beispiel #4
0
        public static RectI GetIntersection(RectI a, RectI b)
        {
            int a_x = a.x;
            int a_r = a.GetRight();
            int a_y = a.y;
            int a_t = a.GetBottom();
            int b_x = b.x;
            int b_r = b.GetRight();
            int b_y = b.y;
            int b_t = b.GetBottom();
            int i_x = MathUtils.Max(a_x, b_x);
            int i_r = MathUtils.Min(a_r, b_r);
            int i_y = MathUtils.Max(a_y, b_y);
            int i_t = MathUtils.Min(a_t, b_t);

            return(i_x < i_r && i_y < i_t ? new RectI(i_x, i_y, i_r - i_x, i_t - i_y) : null);
        }
Beispiel #5
0
        public static RectI SetBoundingBox(RectI rect, int[] xpoints,
                                           int[] ypoints, int npoints)
        {
            int boundsMinX = Integer.MAX_VALUE_JAVA;
            int boundsMinY = Integer.MAX_VALUE_JAVA;
            int boundsMaxX = Integer.MIN_VALUE_JAVA;
            int boundsMaxY = Integer.MIN_VALUE_JAVA;

            for (int i = 0; i < npoints; i++)
            {
                int x = xpoints[i];
                boundsMinX = MathUtils.Min(boundsMinX, x);
                boundsMaxX = MathUtils.Max(boundsMaxX, x);
                int y = ypoints[i];
                boundsMinY = MathUtils.Min(boundsMinY, y);
                boundsMaxY = MathUtils.Max(boundsMaxY, y);
            }

            return(rect.Set(boundsMinX, boundsMinY, boundsMaxX - boundsMinX,
                            boundsMaxY - boundsMinY));
        }
Beispiel #6
0
        public static RectI GetIntersection(RectI a, RectI b, RectI result)
        {
            int a_x = a.x;
            int a_r = a.GetRight();
            int a_y = a.y;
            int a_t = a.GetBottom();
            int b_x = b.x;
            int b_r = b.GetRight();
            int b_y = b.y;
            int b_t = b.GetBottom();
            int i_x = MathUtils.Max(a_x, b_x);
            int i_r = MathUtils.Min(a_r, b_r);
            int i_y = MathUtils.Max(a_y, b_y);
            int i_t = MathUtils.Min(a_t, b_t);

            if (i_x < i_r && i_y < i_t)
            {
                result.Set(i_x, i_y, i_r - i_x, i_t - i_y);
                return(result);
            }
            return(result);
        }
Beispiel #7
0
 public static void GetDiff(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2, RectI result)
 {
     result.Set(x2 - x1 - w1, y2 - y1 - h1, w1 + w2, h1 + h2);
 }
Beispiel #8
0
 public RectI(RectI rect) : this(rect.x, rect.y, rect.width, rect.height)
 {
 }
Beispiel #9
0
 public Range(RectI rect) : this(rect.Left(), rect.Top(), rect.Right(), rect.Bottom())
 {
 }