Example #1
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));
        }
Example #2
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);
        }
Example #3
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);
 }