Exemple #1
0
            public static MultiRectArea getResult(MultiRectArea src1, MultiRectArea src2)
            {
                if (src1 == null || src2 == null || src1.isEmpty() || src2.isEmpty())
                {
                    return(new MultiRectArea());
                }

                MultiRectArea.RectCash dst = new MultiRectArea.RectCash();

                if (!src1.sorted || !src2.sorted ||
                    src1.getRectCount() <= MAX_SIMPLE || src2.getRectCount() <= MAX_SIMPLE)
                {
                    dst.setRect(simpleIntersect(src1, src2), false);
                }
                else
                {
                    java.awt.Rectangle bounds1 = src1.getBounds();
                    java.awt.Rectangle bounds2 = src2.getBounds();
                    java.awt.Rectangle bounds3 = bounds1.intersection(bounds2);
                    if (bounds3.width > 0 && bounds3.height > 0)
                    {
                        intersectRegions(src1.rect, src2.rect, dst, bounds1.height + 2, bounds2.height + 2);
                    }
                }

                return(dst);
            }
Exemple #2
0
            internal MultiRectArea getResult(MultiRectArea src1, MultiRectArea src2)
            {
                if (src1 == null || src1.isEmpty())
                {
                    return(new MultiRectArea(src2));
                }

                if (src2 == null || src2.isEmpty())
                {
                    return(new MultiRectArea(src1));
                }

                dst = new MultiRectArea.RectCash();

                if (!src1.sorted || !src2.sorted ||
                    src1.getRectCount() <= MAX_SIMPLE || src2.getRectCount() <= MAX_SIMPLE)
                {
                    simpleUnion(src1, src2, dst);
                }
                else
                {
                    java.awt.Rectangle bounds1 = src1.getBounds();
                    java.awt.Rectangle bounds2 = src2.getBounds();
                    java.awt.Rectangle bounds3 = bounds1.intersection(bounds2);

                    if (bounds3.width < 0 || bounds3.height < 0)
                    {
                        if (bounds1.y + bounds1.height < bounds2.y)
                        {
                            dst.setRect(addVerRegion(src1.rect, src2.rect), false);
                        }
                        else
                        if (bounds2.y + bounds2.height < bounds1.y)
                        {
                            dst.setRect(addVerRegion(src2.rect, src1.rect), false);
                        }
                        else
                        if (bounds1.x < bounds2.x)
                        {
                            dst.setRect(addHorRegion(src1.rect, src2.rect), false);
                        }
                        else
                        {
                            dst.setRect(addHorRegion(src2.rect, src1.rect), false);
                        }
                    }
                    else
                    {
                        unionRegions(src1.rect, src2.rect, bounds1.height + 2, bounds2.height + 2);
                    }
                }

                return(dst);
            }
Exemple #3
0
 /**
  * Checks validation of MultiRectArea object
  */
 static MultiRectArea check(MultiRectArea mra, String msg)
 {
     if (CHECK && mra != null)
     {
         if (MultiRectArea.checkValidation(mra.getRectangles(), mra.sorted) != -1)
         {
             // awt.4C=Invalid MultiRectArea in method {0}
             new java.lang.RuntimeException("Invalid MultiRectArea in method " + msg); //$NON-NLS-1$
         }
     }
     return(mra);
 }
Exemple #4
0
 /**
  * Constructs a new MultiRectArea as a copy of another one
  */
 public MultiRectArea(MultiRectArea mra)
 {
     if (mra == null)
     {
         rect = MultiRectAreaOp.createBuf(0);
     }
     else
     {
         rect = new int[mra.rect.Length];
         java.lang.SystemJ.arraycopy(mra.rect, 0, rect, 0, mra.rect.Length);
         check(this, "MultiRectArea(MRA)"); //$NON-NLS-1$
     }
 }
Exemple #5
0
 /**
  * Constructs a new MultiRectArea as a copy of another one
  */
 public MultiRectArea(MultiRectArea mra)
 {
     if (mra == null)
     {
         rect = MultiRectAreaOp.createBuf(0);
     }
     else
     {
         rect = new int[mra.rect.Length];
         java.lang.SystemJ.arraycopy(mra.rect, 0, rect, 0, mra.rect.Length);
         check(this, "MultiRectArea(MRA)"); //$NON-NLS-1$
     }
 }
Exemple #6
0
 internal static void simpleSubtract(MultiRectArea src1, MultiRectArea src2, MultiRectArea dst)
 {
     for (int i = 1; i < src1.rect[0]; i += 4)
     {
         subtractRect(
             src1.rect[i + 0],
             src1.rect[i + 1],
             src1.rect[i + 2],
             src1.rect[i + 3],
             src2.rect,
             1,
             dst);
     }
     dst.resort();
 }
Exemple #7
0
 static void simpleUnion(MultiRectArea src1, MultiRectArea src2, MultiRectArea dst)
 {
     if (src1.getRectCount() < src2.getRectCount())
     {
         simpleUnion(src2, src1, dst);
     }
     else
     {
         Subtraction.simpleSubtract(src1, src2, dst);
         int pos  = dst.rect[0];
         int size = src2.rect[0] - 1;
         dst.rect = checkBufSize(dst.rect, size);
         java.lang.SystemJ.arraycopy(src2.rect, 1, dst.rect, pos, size);
         dst.resort();
     }
 }
Exemple #8
0
 /**
  * Print MultiRectArea object to output stream
  */
 public static void print(MultiRectArea mra, String msg)
 {
     if (mra == null)
     {
         java.lang.SystemJ.outJ.println(msg + "=null"); //$NON-NLS-1$
     }
     else
     {
         java.awt.Rectangle[] rects = mra.getRectangles();
         java.lang.SystemJ.outJ.println(msg + "(" + rects.Length + ")"); //$NON-NLS-1$ //$NON-NLS-2$
         foreach (java.awt.Rectangle element in rects)
         {
             java.lang.SystemJ.outJ.println(
                 element.x + "," +                       //$NON-NLS-1$
                 element.y + "," +                       //$NON-NLS-1$
                 (element.x + element.width - 1) + "," + //$NON-NLS-1$
                 (element.y + element.height - 1));
         }
     }
 }
Exemple #9
0
        /**
         * Tests equals with another object
         */

        public override bool Equals(Object obj)
        {
            if (obj == this)
            {
                return(true);
            }
            if (obj is MultiRectArea)
            {
                MultiRectArea mra = (MultiRectArea)obj;
                for (int i = 0; i < rect[0]; i++)
                {
                    if (rect[i] != mra.rect[i])
                    {
                        return(false);
                    }
                }
                return(true);
            }
            return(false);
        }
Exemple #10
0
            public static MultiRectArea getResult(MultiRectArea src1, MultiRectArea src2)
            {
                if (src1 == null || src2 == null || src1.isEmpty() || src2.isEmpty()) {
                return new MultiRectArea();
                }

                MultiRectArea.RectCash dst = new MultiRectArea.RectCash();

                if (!src1.sorted || !src2.sorted ||
                   src1.getRectCount() <= MAX_SIMPLE || src2.getRectCount() <= MAX_SIMPLE)
                {
                dst.setRect(simpleIntersect(src1, src2), false);
                } else {
                java.awt.Rectangle bounds1 = src1.getBounds();
                java.awt.Rectangle bounds2 = src2.getBounds();
                java.awt.Rectangle bounds3 = bounds1.intersection(bounds2);
                if (bounds3.width > 0 && bounds3.height > 0) {
                    intersectRegions(src1.rect, src2.rect, dst, bounds1.height + 2, bounds2.height + 2);
                }
                }

                return dst;
            }
Exemple #11
0
            static int[] simpleIntersect(MultiRectArea src1, MultiRectArea src2)
            {
                int[] rect1 = src1.rect;
                int[] rect2 = src2.rect;
                int[] rect  = createBuf(0);

                int k = 1;

                for (int i = 1; i < rect1[0];)
                {
                    int x11 = rect1[i++];
                    int y11 = rect1[i++];
                    int x12 = rect1[i++];
                    int y12 = rect1[i++];

                    for (int j = 1; j < rect2[0];)
                    {
                        int x21 = rect2[j++];
                        int y21 = rect2[j++];
                        int x22 = rect2[j++];
                        int y22 = rect2[j++];

                        if (x11 <= x22 && x12 >= x21 &&
                            y11 <= y22 && y12 >= y21)
                        {
                            rect      = checkBufSize(rect, 4);
                            rect[k++] = x11 > x21 ? x11 : x21;
                            rect[k++] = y11 > y21 ? y11 : y21;
                            rect[k++] = x12 > x22 ? x22 : x12;
                            rect[k++] = y12 > y22 ? y22 : y12;
                        }
                    }
                }

                rect[0] = k;
                return(rect);
            }
Exemple #12
0
 internal Iterator(MultiRectArea mra, java.awt.geom.AffineTransform t)
 {
     rect = new int[mra.rect[0] - 1];
     java.lang.SystemJ.arraycopy(mra.rect, 1, rect, 0, rect.Length);
     this.t = t;
 }
Exemple #13
0
 /**
  * Checks validation of MultiRectArea object
  */
 static MultiRectArea check(MultiRectArea mra, String msg)
 {
     if (CHECK && mra != null)
     {
         if (MultiRectArea.checkValidation(mra.getRectangles(), mra.sorted) != -1)
         {
             // awt.4C=Invalid MultiRectArea in method {0}
             new java.lang.RuntimeException("Invalid MultiRectArea in method " + msg); //$NON-NLS-1$
         }
     }
     return mra;
 }
Exemple #14
0
            static void subtractRect(int x11, int y11, int x12, int y12, int[] rect, int index, MultiRectArea dst)
            {
                for(int i = index; i < rect[0]; i += 4) {
                int x21 = rect[i + 0];
                int y21 = rect[i + 1];
                int x22 = rect[i + 2];
                int y22 = rect[i + 3];

                if (x11 <= x22 && x12 >= x21 && y11 <= y22 && y12 >= y21) {
                    int top, bottom;
                    if (y11 < y21) {
                        subtractRect(x11, y11, x12, y21 - 1, rect, i + 4, dst);
                        top = y21;
                    } else {
                        top = y11;
                    }
                    if (y12 > y22) {
                        subtractRect(x11, y22 + 1, x12, y12, rect, i + 4, dst);
                        bottom = y22;
                    } else {
                        bottom = y12;
                    }
                    if (x11 < x21) {
                        subtractRect(x11, top, x21 - 1, bottom, rect, i + 4, dst);
                    }
                    if (x12 > x22) {
                        subtractRect(x22 + 1, top, x12, bottom, rect, i + 4, dst);
                    }
                    return;
                }
                }
                dst.addRect(x11, y11, x12, y12);
            }
Exemple #15
0
 /**
  * Intersect with another MultiRectArea object
  */
 public void intersect(MultiRectArea mra)
 {
     setRect(intersect(this, mra).rect, false);
     invalidate();
 }
Exemple #16
0
 /**
  * Subtract another MultiRectArea object
  */
 public void substract(MultiRectArea mra)
 {
     setRect(subtract(this, mra).rect, false);
     invalidate();
 }
Exemple #17
0
 /**
  * Union with another MultiRectArea object
  */
 public void add(MultiRectArea mra)
 {
     setRect(union(this, mra).rect, false);
     invalidate();
 }
Exemple #18
0
 /**
  * Union with another MultiRectArea object
  */
 public void add(MultiRectArea mra)
 {
     setRect(union(this, mra).rect, false);
     invalidate();
 }
Exemple #19
0
 /**
  * Print MultiRectArea object to output stream
  */
 public static void print(MultiRectArea mra, String msg)
 {
     if (mra == null)
     {
         java.lang.SystemJ.outJ.println(msg + "=null"); //$NON-NLS-1$
     }
     else
     {
         java.awt.Rectangle[] rects = mra.getRectangles();
         java.lang.SystemJ.outJ.println(msg + "(" + rects.Length + ")"); //$NON-NLS-1$ //$NON-NLS-2$
         foreach (java.awt.Rectangle element in rects)
         {
             java.lang.SystemJ.outJ.println(
                     element.x + "," + //$NON-NLS-1$
                     element.y + "," + //$NON-NLS-1$
                     (element.x + element.width - 1) + "," + //$NON-NLS-1$
                     (element.y + element.height - 1));
         }
     }
 }
Exemple #20
0
 /**
  * Subtract two MultiRectArea objects
  */
 public static MultiRectArea subtract(MultiRectArea src1, MultiRectArea src2)
 {
     MultiRectArea res = check(MultiRectAreaOp.Subtraction.getResult(src1, src2), "subtract(MRA,MRA)"); //$NON-NLS-1$
     return res;
 }
Exemple #21
0
            static int[] simpleIntersect(MultiRectArea src1, MultiRectArea src2)
            {
                int[] rect1 = src1.rect;
                int[] rect2 = src2.rect;
                int[] rect = createBuf(0);

                int k = 1;
                for(int i = 1; i < rect1[0];) {

                int x11 = rect1[i++];
                int y11 = rect1[i++];
                int x12 = rect1[i++];
                int y12 = rect1[i++];

                for(int j = 1; j < rect2[0];) {

                    int x21 = rect2[j++];
                    int y21 = rect2[j++];
                    int x22 = rect2[j++];
                    int y22 = rect2[j++];

                    if (x11 <= x22 && x12 >= x21 &&
                        y11 <= y22 && y12 >= y21)
                    {
                        rect = checkBufSize(rect, 4);
                        rect[k++] = x11 > x21 ? x11 : x21;
                        rect[k++] = y11 > y21 ? y11 : y21;
                        rect[k++] = x12 > x22 ? x22 : x12;
                        rect[k++] = y12 > y22 ? y22 : y12;
                    }
                }
                }

                rect[0] = k;
                return rect;
            }
Exemple #22
0
            static void subtractRegions(int[] reg1, int[] reg2, MultiRectArea.RectCash dst, int height1, int height2)
            {
                Region d1 = new Region(reg1);
                Region d2 = new Region(reg2);

                int[] level = new int[height1 + height2];
                int[] level1 = new int[height1];
                int[] level2 = new int[height2];
                d1.createLevel(level1);
                d2.createLevel(level2);
                Region.sortOrdered(level1, level2, level);

                int top;
                int bottom = level[1] - 1;
                for(int i = 2; i < level[0]; i++) {

                top = bottom + 1;
                bottom = level[i] - 1;

                d1.findActive(top, bottom);
                if (d1.active[0] == 1) {
                    d2.deleteActive(bottom);
                    continue;
                }

                d2.findActive(top, bottom);

                int i1 = 1;
                int i2 = 1;

                int rx1 = 0;
                int rx2 = 0;

                bool next = true;

                while(true) {

                    if (next) {
                        next = false;
                        if (i1 >= d1.active[0]) {
                            break;
                        }
                        // Bottom
                        d1.active[i1 + 1] = bottom + 1;
                        rx1 = d1.active[i1];
                        rx2 = d1.active[i1 + 2];
                        i1 += 4;
                    }

                    if (i2 >= d2.active[0]) {
                        dst.addRectCashed(rx1, top, rx2, bottom);
                        for(int j = i1; j < d1.active[0]; j += 4) {
                            dst.addRectCashed(d1.active[j], top, d1.active[j + 2], bottom);
                            d1.active[j + 1] = bottom + 1;
                        }
                        break;
                    }

                    int x1 = d2.active[i2];
                    int x2 = d2.active[i2 + 2];

                    if (rx1 < x1) {
                        if (rx2 >= x1) {
                            if (rx2 <= x2) {
                                //  [-----------]
                                //       [-------------]
                                dst.addRectCashed(rx1, top, x1 - 1, bottom);
                                next = true;
                            } else {
                                // [-----------------]
                                //      [------]
                                dst.addRectCashed(rx1, top, x1 - 1, bottom);
                                rx1 = x2 + 1;
                                i2 += 4;
                            }
                        } else {
                            // [-----]
                            //         [----]
                            dst.addRectCashed(rx1, top, rx2, bottom);
                            next = true;
                        }
                    } else {
                        if (rx1 <= x2) {
                            if (rx2 <= x2) {
                                //    [------]
                                //  [-----------]
                                next = true;
                            } else {
                                //     [------------]
                                // [---------]
                                rx1 = x2 + 1;
                                i2 += 4;
                            }
                        } else {
                            //         [----]
                            // [-----]
                            i2 += 4;
                        }
                    }

                }
                d1.deleteActive();
                d2.deleteActive(bottom);
                }
            }
Exemple #23
0
            internal MultiRectArea getResult(MultiRectArea src1, MultiRectArea src2)
            {
                if (src1 == null || src1.isEmpty()) {
                return new MultiRectArea(src2);
                }

                if (src2 == null || src2.isEmpty()) {
                return new MultiRectArea(src1);
                }

                dst = new MultiRectArea.RectCash();

                if (!src1.sorted || !src2.sorted ||
                   src1.getRectCount() <= MAX_SIMPLE || src2.getRectCount() <= MAX_SIMPLE)
                {
                simpleUnion(src1, src2, dst);
                } else {
                java.awt.Rectangle bounds1 = src1.getBounds();
                java.awt.Rectangle bounds2 = src2.getBounds();
                java.awt.Rectangle bounds3 = bounds1.intersection(bounds2);

                if (bounds3.width < 0 || bounds3.height < 0) {
                    if (bounds1.y + bounds1.height < bounds2.y) {
                        dst.setRect(addVerRegion(src1.rect, src2.rect), false);
                    } else
                        if (bounds2.y + bounds2.height < bounds1.y) {
                            dst.setRect(addVerRegion(src2.rect, src1.rect), false);
                        } else
                            if (bounds1.x < bounds2.x) {
                                dst.setRect(addHorRegion(src1.rect, src2.rect), false);
                            } else {
                                dst.setRect(addHorRegion(src2.rect, src1.rect), false);
                            }
                } else {
                    unionRegions(src1.rect, src2.rect, bounds1.height + 2, bounds2.height + 2);
                }
                }

                return dst;
            }
Exemple #24
0
 static void simpleUnion(MultiRectArea src1, MultiRectArea src2, MultiRectArea dst)
 {
     if (src1.getRectCount() < src2.getRectCount()) {
     simpleUnion(src2, src1, dst);
     } else {
     Subtraction.simpleSubtract(src1, src2, dst);
     int pos = dst.rect[0];
     int size = src2.rect[0] - 1;
     dst.rect = checkBufSize(dst.rect, size);
     java.lang.SystemJ.arraycopy(src2.rect,1, dst.rect, pos, size);
     dst.resort();
     }
 }
Exemple #25
0
 /**
  * Intersect with another MultiRectArea object
  */
 public void intersect(MultiRectArea mra)
 {
     setRect(intersect(this, mra).rect, false);
     invalidate();
 }
Exemple #26
0
 internal static void simpleSubtract(MultiRectArea src1, MultiRectArea src2, MultiRectArea dst)
 {
     for(int i = 1; i < src1.rect[0]; i += 4) {
     subtractRect(
             src1.rect[i + 0],
             src1.rect[i + 1],
             src1.rect[i + 2],
             src1.rect[i + 3],
             src2.rect,
             1,
             dst);
     }
     dst.resort();
 }
Exemple #27
0
 /**
  * Intersect two MultiRectArea objects
  */
 public static MultiRectArea union(MultiRectArea src1, MultiRectArea src2)
 {
     MultiRectArea res = check(new MultiRectAreaOp.Union().getResult(src1, src2), "union(MRA,MRA)"); //$NON-NLS-1$
     return res;
 }
Exemple #28
0
 /**
  * Subtract another MultiRectArea object
  */
 public void substract(MultiRectArea mra)
 {
     setRect(subtract(this, mra).rect, false);
     invalidate();
 }
Exemple #29
0
 internal Iterator(MultiRectArea mra, java.awt.geom.AffineTransform t)
 {
     rect = new int[mra.rect[0] - 1];
     java.lang.SystemJ.arraycopy(mra.rect, 1, rect, 0, rect.Length);
     this.t = t;
 }
Exemple #30
0
        /**
         * Intersect two MultiRectArea objects
         */
        public static MultiRectArea union(MultiRectArea src1, MultiRectArea src2)
        {
            MultiRectArea res = check(new MultiRectAreaOp.Union().getResult(src1, src2), "union(MRA,MRA)"); //$NON-NLS-1$

            return(res);
        }
Exemple #31
0
        /**
         * Subtract two MultiRectArea objects
         */
        public static MultiRectArea subtract(MultiRectArea src1, MultiRectArea src2)
        {
            MultiRectArea res = check(MultiRectAreaOp.Subtraction.getResult(src1, src2), "subtract(MRA,MRA)"); //$NON-NLS-1$

            return(res);
        }
Exemple #32
0
            static void subtractRect(int x11, int y11, int x12, int y12, int[] rect, int index, MultiRectArea dst)
            {
                for (int i = index; i < rect[0]; i += 4)
                {
                    int x21 = rect[i + 0];
                    int y21 = rect[i + 1];
                    int x22 = rect[i + 2];
                    int y22 = rect[i + 3];

                    if (x11 <= x22 && x12 >= x21 && y11 <= y22 && y12 >= y21)
                    {
                        int top, bottom;
                        if (y11 < y21)
                        {
                            subtractRect(x11, y11, x12, y21 - 1, rect, i + 4, dst);
                            top = y21;
                        }
                        else
                        {
                            top = y11;
                        }
                        if (y12 > y22)
                        {
                            subtractRect(x11, y22 + 1, x12, y12, rect, i + 4, dst);
                            bottom = y22;
                        }
                        else
                        {
                            bottom = y12;
                        }
                        if (x11 < x21)
                        {
                            subtractRect(x11, top, x21 - 1, bottom, rect, i + 4, dst);
                        }
                        if (x12 > x22)
                        {
                            subtractRect(x22 + 1, top, x12, bottom, rect, i + 4, dst);
                        }
                        return;
                    }
                }
                dst.addRect(x11, y11, x12, y12);
            }
Exemple #33
0
            static void intersectRegions(int[] reg1, int[] reg2, MultiRectArea.RectCash dst, int height1, int height2)
            {
                Region d1 = new Region(reg1);
                Region d2 = new Region(reg2);

                int[] level = new int[height1 + height2];
                int[] level1 = new int[height1];
                int[] level2 = new int[height2];
                d1.createLevel(level1);
                d2.createLevel(level2);
                Region.sortOrdered(level1, level2, level);

                int top;
                int bottom = level[1] - 1;
                for(int i = 2; i < level[0]; i++) {

                top = bottom + 1;
                bottom = level[i] - 1;

                d1.findActive(top, bottom);
                d2.findActive(top, bottom);

                int i1 = 1;
                int i2 = 1;

                while(i1 < d1.active[0] && i2 < d2.active[0]) {

                    int x11 = d1.active[i1];
                    int x12 = d1.active[i1 + 2];
                    int x21 = d2.active[i2];
                    int x22 = d2.active[i2 + 2];

                    if (x11 <= x21) {
                        if (x12 >= x21) {
                            if (x12 <= x22) {
                                dst.addRectCashed(x21, top, x12, bottom);
                                i1 += 4;
                            } else {
                                dst.addRectCashed(x21, top, x22, bottom);
                                i2 += 4;
                            }
                        } else {
                            i1 += 4;
                        }
                    } else {
                        if (x22 >= x11) {
                            if (x22 <= x12) {
                                dst.addRectCashed(x11, top, x22, bottom);
                                i2 += 4;
                            } else {
                                dst.addRectCashed(x11, top, x12, bottom);
                                i1 += 4;
                            }
                        } else {
                            i2 += 4;
                        }
                    }
                }

                d1.deleteActive(bottom);
                d2.deleteActive(bottom);
                }
            }