jdk/test/sun/java2d/pipe/RegionOps.java
author art
Wed, 11 Feb 2009 17:07:06 +0300
changeset 2451 597df8e1d786
child 8368 e05f09b8db21
permissions -rw-r--r--
6633275: Need to support shaped/translucent windows Summary: forward-port from 6u14, no public API is introduced Reviewed-by: anthony, dcherepanov
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
     1
/*
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
     2
 * @test %W% %E%
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
     3
 * @bug 6504874
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
     4
 * @summary This test verifies the operation (and performance) of the
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
     5
 *          various CAG operations on the internal Region class.
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
     6
 * @run main RegionOps
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
     7
 */
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
     8
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
     9
import java.awt.Rectangle;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    10
import java.awt.geom.Area;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    11
import java.awt.geom.AffineTransform;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    12
import java.awt.image.BufferedImage;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    13
import java.util.Random;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    14
import sun.java2d.pipe.Region;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    15
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    16
public class RegionOps {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    17
    public static final int DEFAULT_NUMREGIONS = 50;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    18
    public static final int DEFAULT_MINSUBRECTS = 1;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    19
    public static final int DEFAULT_MAXSUBRECTS = 10;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    20
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    21
    public static final int MINCOORD = -20;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    22
    public static final int MAXCOORD = 20;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    23
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    24
    public static boolean useArea;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    25
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    26
    static int numops;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    27
    static int numErrors;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    28
    static Random rand = new Random();
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    29
    static boolean skipCheck;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    30
    static boolean countErrors;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    31
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    32
    static {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    33
        // Instantiating BufferedImage initializes sun.java2d
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    34
        BufferedImage bimg =
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    35
            new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    36
    }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    37
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    38
    public static void usage(String error) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    39
        if (error != null) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    40
            System.err.println("Error: "+error);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    41
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    42
        System.err.println("Usage: java RegionOps "+
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    43
                           "[-regions N] [-rects M] "+
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    44
                           "[-[min|max]rects M] [-area]");
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    45
        System.err.println("                      "+
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    46
                           "[-add|union] [-sub|diff] "+
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    47
                           "[-int[ersect]] [-xor]");
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    48
        System.err.println("                      "+
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    49
                           "[-seed S] [-nocheck] [-count[errors]] [-help]");
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    50
        System.exit((error != null) ? 1 : 0);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    51
    }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    52
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    53
    public static void error(RectListImpl a, RectListImpl b, String problem) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    54
        System.err.println("Operating on:  "+a);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    55
        if (b != null) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    56
            System.err.println("and:  "+b);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    57
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    58
        if (countErrors) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    59
            System.err.println(problem);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    60
            numErrors++;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    61
        } else {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    62
            throw new RuntimeException(problem);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    63
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    64
    }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    65
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    66
    public static void main(String argv[]) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    67
        int numregions = DEFAULT_NUMREGIONS;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    68
        int minsubrects = DEFAULT_MINSUBRECTS;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    69
        int maxsubrects = DEFAULT_MAXSUBRECTS;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    70
        boolean doUnion = false;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    71
        boolean doIntersect = false;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    72
        boolean doSubtract = false;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    73
        boolean doXor = false;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    74
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    75
        for (int i = 0; i < argv.length; i++) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    76
            String arg = argv[i];
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    77
            if (arg.equalsIgnoreCase("-regions")) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    78
                if (i+1 >= argv.length) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    79
                    usage("missing arg for -regions");
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    80
                }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    81
                numregions = Integer.parseInt(argv[++i]);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    82
            } else if (arg.equalsIgnoreCase("-rects")) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    83
                if (i+1 >= argv.length) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    84
                    usage("missing arg for -rects");
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    85
                }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    86
                minsubrects = maxsubrects = Integer.parseInt(argv[++i]);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    87
            } else if (arg.equalsIgnoreCase("-minrects")) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    88
                if (i+1 >= argv.length) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    89
                    usage("missing arg for -minrects");
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    90
                }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    91
                minsubrects = Integer.parseInt(argv[++i]);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    92
            } else if (arg.equalsIgnoreCase("-maxrects")) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    93
                if (i+1 >= argv.length) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    94
                    usage("missing arg for -maxrects");
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    95
                }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    96
                maxsubrects = Integer.parseInt(argv[++i]);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    97
            } else if (arg.equalsIgnoreCase("-area")) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    98
                useArea = true;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    99
            } else if (arg.equalsIgnoreCase("-add") ||
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   100
                       arg.equalsIgnoreCase("-union"))
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   101
            {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   102
                doUnion = true;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   103
            } else if (arg.equalsIgnoreCase("-sub") ||
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   104
                       arg.equalsIgnoreCase("-diff"))
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   105
            {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   106
                doSubtract = true;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   107
            } else if (arg.equalsIgnoreCase("-int") ||
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   108
                       arg.equalsIgnoreCase("-intersect"))
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   109
            {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   110
                doIntersect = true;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   111
            } else if (arg.equalsIgnoreCase("-xor")) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   112
                doXor = true;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   113
            } else if (arg.equalsIgnoreCase("-seed")) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   114
                if (i+1 >= argv.length) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   115
                    usage("missing arg for -seed");
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   116
                }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   117
                rand.setSeed(Long.decode(argv[++i]).longValue());
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   118
            } else if (arg.equalsIgnoreCase("-nocheck")) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   119
                skipCheck = true;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   120
            } else if (arg.equalsIgnoreCase("-count") ||
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   121
                       arg.equalsIgnoreCase("-counterrors"))
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   122
            {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   123
                countErrors = true;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   124
            } else if (arg.equalsIgnoreCase("-help")) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   125
                usage(null);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   126
            } else {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   127
                usage("Unknown argument: "+arg);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   128
            }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   129
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   130
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   131
        if (maxsubrects < minsubrects) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   132
            usage("maximum number of subrectangles less than minimum");
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   133
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   134
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   135
        if (minsubrects <= 0) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   136
            usage("minimum number of subrectangles must be positive");
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   137
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   138
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   139
        if (!doUnion && !doSubtract && !doIntersect && !doXor) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   140
            doUnion = doSubtract = doIntersect = doXor = true;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   141
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   142
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   143
        long start = System.currentTimeMillis();
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   144
        RectListImpl rlist[] = new RectListImpl[numregions];
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   145
        int totalrects = 0;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   146
        for (int i = 0; i < rlist.length; i++) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   147
            RectListImpl rli = RectListImpl.getInstance();
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   148
            int numsubrects =
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   149
                minsubrects + rand.nextInt(maxsubrects - minsubrects + 1);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   150
            for (int j = 0; j < numsubrects; j++) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   151
                addRectTo(rli);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   152
                totalrects++;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   153
            }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   154
            rlist[i] = rli;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   155
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   156
        long end = System.currentTimeMillis();
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   157
        System.out.println((end-start)+"ms to create "+
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   158
                           rlist.length+" regions containing "+
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   159
                           totalrects+" subrectangles");
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   160
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   161
        start = System.currentTimeMillis();
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   162
        for (int i = 0; i < rlist.length; i++) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   163
            RectListImpl a = rlist[i];
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   164
            testTranslate(a);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   165
            for (int j = i; j < rlist.length; j++) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   166
                RectListImpl b = rlist[j];
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   167
                if (doUnion) testUnion(a, b);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   168
                if (doSubtract) testDifference(a, b);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   169
                if (doIntersect) testIntersection(a, b);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   170
                if (doXor) testExclusiveOr(a, b);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   171
            }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   172
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   173
        end = System.currentTimeMillis();
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   174
        System.out.println(numops+" ops took "+(end-start)+"ms");
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   175
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   176
        if (numErrors > 0) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   177
            throw new RuntimeException(numErrors+" errors encountered");
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   178
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   179
    }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   180
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   181
    public static void addRectTo(RectListImpl rli) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   182
        int lox = MINCOORD + rand.nextInt(MAXCOORD - MINCOORD + 1);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   183
        int hix = MINCOORD + rand.nextInt(MAXCOORD - MINCOORD + 1);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   184
        int loy = MINCOORD + rand.nextInt(MAXCOORD - MINCOORD + 1);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   185
        int hiy = MINCOORD + rand.nextInt(MAXCOORD - MINCOORD + 1);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   186
        rli.addRect(lox, loy, hix, hiy);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   187
    }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   188
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   189
    public static void checkEqual(RectListImpl a, RectListImpl b,
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   190
                                  String optype)
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   191
    {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   192
        if (a.hashCode() != b.hashCode()) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   193
            error(a, b, "hashcode failed for "+optype);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   194
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   195
        if (!a.equals(b)) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   196
            error(a, b, "equals failed for "+optype);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   197
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   198
    }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   199
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   200
    public static void testTranslate(RectListImpl a) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   201
        RectListImpl maxTrans =
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   202
            a.getTranslation(Integer.MAX_VALUE, Integer.MAX_VALUE)
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   203
            .getTranslation(Integer.MAX_VALUE, Integer.MAX_VALUE)
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   204
            .getTranslation(Integer.MAX_VALUE, Integer.MAX_VALUE);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   205
        if (!maxTrans.checkTransEmpty()) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   206
            error(maxTrans, null, "overflow translated RectList not empty");
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   207
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   208
        RectListImpl minTrans =
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   209
            a.getTranslation(Integer.MIN_VALUE, Integer.MIN_VALUE)
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   210
            .getTranslation(Integer.MIN_VALUE, Integer.MIN_VALUE)
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   211
            .getTranslation(Integer.MIN_VALUE, Integer.MIN_VALUE);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   212
        if (!minTrans.checkTransEmpty()) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   213
            error(minTrans, null, "overflow translated RectList not empty");
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   214
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   215
        testTranslate(a, Integer.MAX_VALUE, Integer.MAX_VALUE, false,
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   216
                      MINCOORD, 0, MINCOORD, 0);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   217
        testTranslate(a, Integer.MAX_VALUE, Integer.MIN_VALUE, false,
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   218
                      MINCOORD, 0, 0, MAXCOORD);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   219
        testTranslate(a, Integer.MIN_VALUE, Integer.MAX_VALUE, false,
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   220
                      0, MAXCOORD, MINCOORD, 0);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   221
        testTranslate(a, Integer.MIN_VALUE, Integer.MIN_VALUE, false,
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   222
                      0, MAXCOORD, 0, MAXCOORD);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   223
        for (int dy = -100; dy <= 100; dy += 50) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   224
            for (int dx = -100; dx <= 100; dx += 50) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   225
                testTranslate(a, dx, dy, true,
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   226
                              MINCOORD, MAXCOORD,
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   227
                              MINCOORD, MAXCOORD);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   228
            }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   229
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   230
    }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   231
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   232
    public static void testTranslate(RectListImpl a, int dx, int dy,
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   233
                                     boolean isNonDestructive,
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   234
                                     int xmin, int xmax,
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   235
                                     int ymin, int ymax)
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   236
    {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   237
        RectListImpl theTrans = a.getTranslation(dx, dy); numops++;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   238
        if (skipCheck) return;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   239
        RectListImpl unTrans = theTrans.getTranslation(-dx, -dy);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   240
        if (isNonDestructive) checkEqual(a, unTrans, "Translate");
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   241
        for (int x = xmin; x < xmax; x++) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   242
            for (int y = ymin; y < ymax; y++) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   243
                boolean inside = a.contains(x, y);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   244
                if (theTrans.contains(x+dx, y+dy) != inside) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   245
                    error(a, null, "translation failed for "+
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   246
                          dx+", "+dy+" at "+x+", "+y);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   247
                }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   248
            }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   249
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   250
    }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   251
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   252
    public static void testUnion(RectListImpl a, RectListImpl b) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   253
        RectListImpl aUb = a.getUnion(b); numops++;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   254
        RectListImpl bUa = b.getUnion(a); numops++;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   255
        if (skipCheck) return;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   256
        checkEqual(aUb, bUa, "Union");
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   257
        testUnion(a, b, aUb);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   258
        testUnion(a, b, bUa);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   259
    }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   260
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   261
    public static void testUnion(RectListImpl a, RectListImpl b,
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   262
                                 RectListImpl theUnion)
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   263
    {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   264
        for (int x = MINCOORD; x < MAXCOORD; x++) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   265
            for (int y = MINCOORD; y < MAXCOORD; y++) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   266
                boolean inside = (a.contains(x, y) || b.contains(x, y));
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   267
                if (theUnion.contains(x, y) != inside) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   268
                    error(a, b, "union failed at "+x+", "+y);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   269
                }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   270
            }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   271
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   272
    }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   273
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   274
    public static void testDifference(RectListImpl a, RectListImpl b) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   275
        RectListImpl aDb = a.getDifference(b); numops++;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   276
        RectListImpl bDa = b.getDifference(a); numops++;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   277
        if (skipCheck) return;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   278
        // Note that difference is not commutative so we cannot check equals
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   279
        // checkEqual(a, b, "Difference");
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   280
        testDifference(a, b, aDb);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   281
        testDifference(b, a, bDa);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   282
    }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   283
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   284
    public static void testDifference(RectListImpl a, RectListImpl b,
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   285
                                      RectListImpl theDifference)
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   286
    {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   287
        for (int x = MINCOORD; x < MAXCOORD; x++) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   288
            for (int y = MINCOORD; y < MAXCOORD; y++) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   289
                boolean inside = (a.contains(x, y) && !b.contains(x, y));
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   290
                if (theDifference.contains(x, y) != inside) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   291
                    error(a, b, "difference failed at "+x+", "+y);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   292
                }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   293
            }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   294
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   295
    }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   296
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   297
    public static void testIntersection(RectListImpl a, RectListImpl b) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   298
        RectListImpl aIb = a.getIntersection(b); numops++;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   299
        RectListImpl bIa = b.getIntersection(a); numops++;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   300
        if (skipCheck) return;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   301
        checkEqual(aIb, bIa, "Intersection");
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   302
        testIntersection(a, b, aIb);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   303
        testIntersection(a, b, bIa);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   304
    }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   305
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   306
    public static void testIntersection(RectListImpl a, RectListImpl b,
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   307
                                        RectListImpl theIntersection)
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   308
    {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   309
        for (int x = MINCOORD; x < MAXCOORD; x++) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   310
            for (int y = MINCOORD; y < MAXCOORD; y++) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   311
                boolean inside = (a.contains(x, y) && b.contains(x, y));
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   312
                if (theIntersection.contains(x, y) != inside) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   313
                    error(a, b, "intersection failed at "+x+", "+y);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   314
                }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   315
            }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   316
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   317
    }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   318
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   319
    public static void testExclusiveOr(RectListImpl a, RectListImpl b) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   320
        RectListImpl aXb = a.getExclusiveOr(b); numops++;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   321
        RectListImpl bXa = b.getExclusiveOr(a); numops++;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   322
        if (skipCheck) return;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   323
        checkEqual(aXb, bXa, "ExclusiveOr");
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   324
        testExclusiveOr(a, b, aXb);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   325
        testExclusiveOr(a, b, bXa);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   326
    }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   327
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   328
    public static void testExclusiveOr(RectListImpl a, RectListImpl b,
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   329
                                       RectListImpl theExclusiveOr)
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   330
    {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   331
        for (int x = MINCOORD; x < MAXCOORD; x++) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   332
            for (int y = MINCOORD; y < MAXCOORD; y++) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   333
                boolean inside = (a.contains(x, y) != b.contains(x, y));
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   334
                if (theExclusiveOr.contains(x, y) != inside) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   335
                    error(a, b, "xor failed at "+x+", "+y);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   336
                }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   337
            }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   338
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   339
    }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   340
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   341
    public abstract static class RectListImpl {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   342
        public static RectListImpl getInstance() {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   343
            if (useArea) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   344
                return new AreaImpl();
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   345
            } else {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   346
                return new RegionImpl();
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   347
            }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   348
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   349
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   350
        public abstract void addRect(int lox, int loy, int hix, int hiy);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   351
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   352
        public abstract RectListImpl getTranslation(int dx, int dy);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   353
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   354
        public abstract RectListImpl getIntersection(RectListImpl rli);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   355
        public abstract RectListImpl getExclusiveOr(RectListImpl rli);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   356
        public abstract RectListImpl getDifference(RectListImpl rli);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   357
        public abstract RectListImpl getUnion(RectListImpl rli);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   358
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   359
        // Used for making sure that 3xMAX translates yields an empty region
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   360
        public abstract boolean checkTransEmpty();
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   361
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   362
        public abstract boolean contains(int x, int y);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   363
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   364
        public abstract int hashCode();
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   365
        public abstract boolean equals(RectListImpl other);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   366
    }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   367
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   368
    public static class AreaImpl extends RectListImpl {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   369
        Area theArea;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   370
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   371
        public AreaImpl() {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   372
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   373
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   374
        public AreaImpl(Area a) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   375
            theArea = a;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   376
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   377
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   378
        public void addRect(int lox, int loy, int hix, int hiy) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   379
            Area a2 = new Area(new Rectangle(lox, loy, hix-lox, hiy-loy));
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   380
            if (theArea == null) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   381
                theArea = a2;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   382
            } else {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   383
                theArea.add(a2);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   384
            }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   385
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   386
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   387
        public RectListImpl getTranslation(int dx, int dy) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   388
            AffineTransform at = AffineTransform.getTranslateInstance(dx, dy);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   389
            return new AreaImpl(theArea.createTransformedArea(at));
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   390
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   391
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   392
        public RectListImpl getIntersection(RectListImpl rli) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   393
            Area a2 = new Area(theArea);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   394
            a2.intersect(((AreaImpl) rli).theArea);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   395
            return new AreaImpl(a2);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   396
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   397
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   398
        public RectListImpl getExclusiveOr(RectListImpl rli) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   399
            Area a2 = new Area(theArea);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   400
            a2.exclusiveOr(((AreaImpl) rli).theArea);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   401
            return new AreaImpl(a2);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   402
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   403
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   404
        public RectListImpl getDifference(RectListImpl rli) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   405
            Area a2 = new Area(theArea);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   406
            a2.subtract(((AreaImpl) rli).theArea);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   407
            return new AreaImpl(a2);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   408
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   409
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   410
        public RectListImpl getUnion(RectListImpl rli) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   411
            Area a2 = new Area(theArea);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   412
            a2.add(((AreaImpl) rli).theArea);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   413
            return new AreaImpl(a2);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   414
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   415
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   416
        // Used for making sure that 3xMAX translates yields an empty region
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   417
        public boolean checkTransEmpty() {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   418
            // Area objects will actually survive 3 MAX translates so just
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   419
            // pretend that it had the intended effect...
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   420
            return true;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   421
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   422
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   423
        public boolean contains(int x, int y) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   424
            return theArea.contains(x, y);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   425
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   426
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   427
        public int hashCode() {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   428
            // Area does not override hashCode...
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   429
            return 0;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   430
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   431
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   432
        public boolean equals(RectListImpl other) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   433
            return theArea.equals(((AreaImpl) other).theArea);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   434
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   435
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   436
        public String toString() {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   437
            return theArea.toString();
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   438
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   439
    }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   440
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   441
    public static class RegionImpl extends RectListImpl {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   442
        Region theRegion;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   443
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   444
        public RegionImpl() {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   445
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   446
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   447
        public RegionImpl(Region r) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   448
            theRegion = r;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   449
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   450
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   451
        public void addRect(int lox, int loy, int hix, int hiy) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   452
            Region r2 = Region.getInstanceXYXY(lox, loy, hix, hiy);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   453
            if (theRegion == null) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   454
                theRegion = r2;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   455
            } else {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   456
                theRegion = theRegion.getUnion(r2);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   457
            }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   458
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   459
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   460
        public RectListImpl getTranslation(int dx, int dy) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   461
            return new RegionImpl(theRegion.getTranslatedRegion(dx, dy));
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   462
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   463
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   464
        public RectListImpl getIntersection(RectListImpl rli) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   465
            Region r2 = ((RegionImpl) rli).theRegion;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   466
            r2 = theRegion.getIntersection(r2);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   467
            return new RegionImpl(r2);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   468
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   469
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   470
        public RectListImpl getExclusiveOr(RectListImpl rli) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   471
            Region r2 = ((RegionImpl) rli).theRegion;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   472
            r2 = theRegion.getExclusiveOr(r2);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   473
            return new RegionImpl(r2);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   474
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   475
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   476
        public RectListImpl getDifference(RectListImpl rli) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   477
            Region r2 = ((RegionImpl) rli).theRegion;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   478
            r2 = theRegion.getDifference(r2);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   479
            return new RegionImpl(r2);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   480
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   481
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   482
        public RectListImpl getUnion(RectListImpl rli) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   483
            Region r2 = ((RegionImpl) rli).theRegion;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   484
            r2 = theRegion.getUnion(r2);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   485
            return new RegionImpl(r2);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   486
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   487
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   488
        // Used for making sure that 3xMAX translates yields an empty region
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   489
        public boolean checkTransEmpty() {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   490
            // Region objects should be empty after 3 MAX translates...
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   491
            return theRegion.isEmpty();
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   492
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   493
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   494
        public boolean contains(int x, int y) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   495
            return theRegion.contains(x, y);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   496
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   497
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   498
        public int hashCode() {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   499
            return theRegion.hashCode();
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   500
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   501
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   502
        public boolean equals(RectListImpl other) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   503
            return theRegion.equals(((RegionImpl) other).theRegion);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   504
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   505
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   506
        public String toString() {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   507
            return theRegion.toString();
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   508
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   509
    }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   510
}