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);
            }
        }