コード例 #1
0
ファイル: MultiRectAreaOp.cs プロジェクト: bastie/NetVampire
            bool next(Region d, int index)
            {
                int  x1  = d.active[index];
                int  x2  = d.active[index + 2];
                bool res = false;

                if (x2 < rx1 - 1)
                {
                    res = true;
                    dst.addRectCashed(x1, top, x2, bottom);
                }
                else
                if (x1 > rx2 + 1)
                {
                    res = false;
                    dst.addRectCashed(rx1, top, rx2, bottom);
                    rx1 = x1;
                    rx2 = x2;
                }
                else
                {
                    res = x2 <= rx2;
                    rx1 = java.lang.Math.min(x1, rx1);
                    rx2 = java.lang.Math.max(x2, rx2);
                }

                // Top
                if (d.active[index + 1] < top)
                {
                    dst.addRectCashed(x1, d.active[index + 1], x2, top - 1);
                }
                // Bottom
                if (d.active[index + 3] > bottom)
                {
                    d.active[index + 1] = bottom + 1;
                }
                return(res);
            }
コード例 #2
0
ファイル: MultiRectAreaOp.cs プロジェクト: bastie/NetVampire
            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);
                }
            }
コード例 #3
0
ファイル: MultiRectAreaOp.cs プロジェクト: bastie/NetVampire
            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);
                }
            }