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
            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 #4
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);
                }
            }
Exemple #5
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 #6
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;
            }