jdk/test/sun/java2d/pipe/RegionOps.java
author ohair
Wed, 06 Apr 2011 22:06:11 -0700
changeset 9035 1255eb81cc2f
parent 8368 e05f09b8db21
child 31448 1066345d2a8a
permissions -rw-r--r--
7033660: Update copyright year to 2011 on any files changed in 2011 Reviewed-by: dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8368
e05f09b8db21 7017581: missing copyright header in test/sun/java2d/pipe/RegionOps.java
andrew
parents: 2451
diff changeset
     1
/*
9035
1255eb81cc2f 7033660: Update copyright year to 2011 on any files changed in 2011
ohair
parents: 8368
diff changeset
     2
 * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
8368
e05f09b8db21 7017581: missing copyright header in test/sun/java2d/pipe/RegionOps.java
andrew
parents: 2451
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e05f09b8db21 7017581: missing copyright header in test/sun/java2d/pipe/RegionOps.java
andrew
parents: 2451
diff changeset
     4
 *
e05f09b8db21 7017581: missing copyright header in test/sun/java2d/pipe/RegionOps.java
andrew
parents: 2451
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
e05f09b8db21 7017581: missing copyright header in test/sun/java2d/pipe/RegionOps.java
andrew
parents: 2451
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
e05f09b8db21 7017581: missing copyright header in test/sun/java2d/pipe/RegionOps.java
andrew
parents: 2451
diff changeset
     7
 * published by the Free Software Foundation.
e05f09b8db21 7017581: missing copyright header in test/sun/java2d/pipe/RegionOps.java
andrew
parents: 2451
diff changeset
     8
 *
e05f09b8db21 7017581: missing copyright header in test/sun/java2d/pipe/RegionOps.java
andrew
parents: 2451
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
e05f09b8db21 7017581: missing copyright header in test/sun/java2d/pipe/RegionOps.java
andrew
parents: 2451
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e05f09b8db21 7017581: missing copyright header in test/sun/java2d/pipe/RegionOps.java
andrew
parents: 2451
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
e05f09b8db21 7017581: missing copyright header in test/sun/java2d/pipe/RegionOps.java
andrew
parents: 2451
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
e05f09b8db21 7017581: missing copyright header in test/sun/java2d/pipe/RegionOps.java
andrew
parents: 2451
diff changeset
    13
 * accompanied this code).
e05f09b8db21 7017581: missing copyright header in test/sun/java2d/pipe/RegionOps.java
andrew
parents: 2451
diff changeset
    14
 *
e05f09b8db21 7017581: missing copyright header in test/sun/java2d/pipe/RegionOps.java
andrew
parents: 2451
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
e05f09b8db21 7017581: missing copyright header in test/sun/java2d/pipe/RegionOps.java
andrew
parents: 2451
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
e05f09b8db21 7017581: missing copyright header in test/sun/java2d/pipe/RegionOps.java
andrew
parents: 2451
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e05f09b8db21 7017581: missing copyright header in test/sun/java2d/pipe/RegionOps.java
andrew
parents: 2451
diff changeset
    18
 *
e05f09b8db21 7017581: missing copyright header in test/sun/java2d/pipe/RegionOps.java
andrew
parents: 2451
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e05f09b8db21 7017581: missing copyright header in test/sun/java2d/pipe/RegionOps.java
andrew
parents: 2451
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
e05f09b8db21 7017581: missing copyright header in test/sun/java2d/pipe/RegionOps.java
andrew
parents: 2451
diff changeset
    21
 * questions.
e05f09b8db21 7017581: missing copyright header in test/sun/java2d/pipe/RegionOps.java
andrew
parents: 2451
diff changeset
    22
 */
e05f09b8db21 7017581: missing copyright header in test/sun/java2d/pipe/RegionOps.java
andrew
parents: 2451
diff changeset
    23
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    24
/*
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    25
 * @test %W% %E%
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    26
 * @bug 6504874
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    27
 * @summary This test verifies the operation (and performance) of the
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    28
 *          various CAG operations on the internal Region class.
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    29
 * @run main RegionOps
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    30
 */
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
import java.awt.Rectangle;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    33
import java.awt.geom.Area;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    34
import java.awt.geom.AffineTransform;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    35
import java.awt.image.BufferedImage;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    36
import java.util.Random;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    37
import sun.java2d.pipe.Region;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    38
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    39
public class RegionOps {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    40
    public static final int DEFAULT_NUMREGIONS = 50;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    41
    public static final int DEFAULT_MINSUBRECTS = 1;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    42
    public static final int DEFAULT_MAXSUBRECTS = 10;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    43
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    44
    public static final int MINCOORD = -20;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    45
    public static final int MAXCOORD = 20;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    46
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    47
    public static boolean useArea;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    48
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    49
    static int numops;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    50
    static int numErrors;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    51
    static Random rand = new Random();
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    52
    static boolean skipCheck;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    53
    static boolean countErrors;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    54
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    55
    static {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    56
        // Instantiating BufferedImage initializes sun.java2d
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    57
        BufferedImage bimg =
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    58
            new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    59
    }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    60
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    61
    public static void usage(String error) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    62
        if (error != null) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    63
            System.err.println("Error: "+error);
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
        System.err.println("Usage: java RegionOps "+
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    66
                           "[-regions N] [-rects M] "+
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    67
                           "[-[min|max]rects M] [-area]");
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    68
        System.err.println("                      "+
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    69
                           "[-add|union] [-sub|diff] "+
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    70
                           "[-int[ersect]] [-xor]");
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    71
        System.err.println("                      "+
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    72
                           "[-seed S] [-nocheck] [-count[errors]] [-help]");
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    73
        System.exit((error != null) ? 1 : 0);
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
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    76
    public static void error(RectListImpl a, RectListImpl b, String problem) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    77
        System.err.println("Operating on:  "+a);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    78
        if (b != null) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    79
            System.err.println("and:  "+b);
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
        if (countErrors) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    82
            System.err.println(problem);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    83
            numErrors++;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    84
        } else {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    85
            throw new RuntimeException(problem);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    86
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    87
    }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    88
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    89
    public static void main(String argv[]) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    90
        int numregions = DEFAULT_NUMREGIONS;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    91
        int minsubrects = DEFAULT_MINSUBRECTS;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    92
        int maxsubrects = DEFAULT_MAXSUBRECTS;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    93
        boolean doUnion = false;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    94
        boolean doIntersect = false;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    95
        boolean doSubtract = false;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    96
        boolean doXor = false;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    97
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    98
        for (int i = 0; i < argv.length; i++) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
    99
            String arg = argv[i];
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   100
            if (arg.equalsIgnoreCase("-regions")) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   101
                if (i+1 >= argv.length) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   102
                    usage("missing arg for -regions");
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   103
                }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   104
                numregions = Integer.parseInt(argv[++i]);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   105
            } else if (arg.equalsIgnoreCase("-rects")) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   106
                if (i+1 >= argv.length) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   107
                    usage("missing arg for -rects");
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   108
                }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   109
                minsubrects = maxsubrects = Integer.parseInt(argv[++i]);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   110
            } else if (arg.equalsIgnoreCase("-minrects")) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   111
                if (i+1 >= argv.length) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   112
                    usage("missing arg for -minrects");
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   113
                }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   114
                minsubrects = Integer.parseInt(argv[++i]);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   115
            } else if (arg.equalsIgnoreCase("-maxrects")) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   116
                if (i+1 >= argv.length) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   117
                    usage("missing arg for -maxrects");
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   118
                }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   119
                maxsubrects = Integer.parseInt(argv[++i]);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   120
            } else if (arg.equalsIgnoreCase("-area")) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   121
                useArea = true;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   122
            } else if (arg.equalsIgnoreCase("-add") ||
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   123
                       arg.equalsIgnoreCase("-union"))
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   124
            {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   125
                doUnion = true;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   126
            } else if (arg.equalsIgnoreCase("-sub") ||
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   127
                       arg.equalsIgnoreCase("-diff"))
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
                doSubtract = true;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   130
            } else if (arg.equalsIgnoreCase("-int") ||
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   131
                       arg.equalsIgnoreCase("-intersect"))
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   132
            {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   133
                doIntersect = true;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   134
            } else if (arg.equalsIgnoreCase("-xor")) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   135
                doXor = true;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   136
            } else if (arg.equalsIgnoreCase("-seed")) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   137
                if (i+1 >= argv.length) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   138
                    usage("missing arg for -seed");
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   139
                }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   140
                rand.setSeed(Long.decode(argv[++i]).longValue());
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   141
            } else if (arg.equalsIgnoreCase("-nocheck")) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   142
                skipCheck = true;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   143
            } else if (arg.equalsIgnoreCase("-count") ||
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   144
                       arg.equalsIgnoreCase("-counterrors"))
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   145
            {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   146
                countErrors = true;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   147
            } else if (arg.equalsIgnoreCase("-help")) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   148
                usage(null);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   149
            } else {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   150
                usage("Unknown argument: "+arg);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   151
            }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   152
        }
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
        if (maxsubrects < minsubrects) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   155
            usage("maximum number of subrectangles less than minimum");
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   156
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   157
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   158
        if (minsubrects <= 0) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   159
            usage("minimum number of subrectangles must be positive");
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
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   162
        if (!doUnion && !doSubtract && !doIntersect && !doXor) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   163
            doUnion = doSubtract = doIntersect = doXor = true;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   164
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   165
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   166
        long start = System.currentTimeMillis();
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   167
        RectListImpl rlist[] = new RectListImpl[numregions];
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   168
        int totalrects = 0;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   169
        for (int i = 0; i < rlist.length; i++) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   170
            RectListImpl rli = RectListImpl.getInstance();
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   171
            int numsubrects =
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   172
                minsubrects + rand.nextInt(maxsubrects - minsubrects + 1);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   173
            for (int j = 0; j < numsubrects; j++) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   174
                addRectTo(rli);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   175
                totalrects++;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   176
            }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   177
            rlist[i] = rli;
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
        long end = System.currentTimeMillis();
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   180
        System.out.println((end-start)+"ms to create "+
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   181
                           rlist.length+" regions containing "+
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   182
                           totalrects+" subrectangles");
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   183
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   184
        start = System.currentTimeMillis();
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   185
        for (int i = 0; i < rlist.length; i++) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   186
            RectListImpl a = rlist[i];
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   187
            testTranslate(a);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   188
            for (int j = i; j < rlist.length; j++) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   189
                RectListImpl b = rlist[j];
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   190
                if (doUnion) testUnion(a, b);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   191
                if (doSubtract) testDifference(a, b);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   192
                if (doIntersect) testIntersection(a, b);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   193
                if (doXor) testExclusiveOr(a, b);
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
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   196
        end = System.currentTimeMillis();
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   197
        System.out.println(numops+" ops took "+(end-start)+"ms");
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
        if (numErrors > 0) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   200
            throw new RuntimeException(numErrors+" errors encountered");
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   201
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   202
    }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   203
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   204
    public static void addRectTo(RectListImpl rli) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   205
        int lox = MINCOORD + rand.nextInt(MAXCOORD - MINCOORD + 1);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   206
        int hix = MINCOORD + rand.nextInt(MAXCOORD - MINCOORD + 1);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   207
        int loy = MINCOORD + rand.nextInt(MAXCOORD - MINCOORD + 1);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   208
        int hiy = MINCOORD + rand.nextInt(MAXCOORD - MINCOORD + 1);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   209
        rli.addRect(lox, loy, hix, hiy);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   210
    }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   211
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   212
    public static void checkEqual(RectListImpl a, RectListImpl b,
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   213
                                  String optype)
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
        if (a.hashCode() != b.hashCode()) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   216
            error(a, b, "hashcode failed for "+optype);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   217
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   218
        if (!a.equals(b)) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   219
            error(a, b, "equals failed for "+optype);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   220
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   221
    }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   222
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   223
    public static void testTranslate(RectListImpl a) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   224
        RectListImpl maxTrans =
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   225
            a.getTranslation(Integer.MAX_VALUE, Integer.MAX_VALUE)
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   226
            .getTranslation(Integer.MAX_VALUE, Integer.MAX_VALUE)
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   227
            .getTranslation(Integer.MAX_VALUE, Integer.MAX_VALUE);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   228
        if (!maxTrans.checkTransEmpty()) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   229
            error(maxTrans, null, "overflow translated RectList not empty");
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
        RectListImpl minTrans =
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   232
            a.getTranslation(Integer.MIN_VALUE, Integer.MIN_VALUE)
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   233
            .getTranslation(Integer.MIN_VALUE, Integer.MIN_VALUE)
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   234
            .getTranslation(Integer.MIN_VALUE, Integer.MIN_VALUE);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   235
        if (!minTrans.checkTransEmpty()) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   236
            error(minTrans, null, "overflow translated RectList not empty");
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   237
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   238
        testTranslate(a, Integer.MAX_VALUE, Integer.MAX_VALUE, false,
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   239
                      MINCOORD, 0, MINCOORD, 0);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   240
        testTranslate(a, Integer.MAX_VALUE, Integer.MIN_VALUE, false,
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   241
                      MINCOORD, 0, 0, MAXCOORD);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   242
        testTranslate(a, Integer.MIN_VALUE, Integer.MAX_VALUE, false,
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   243
                      0, MAXCOORD, MINCOORD, 0);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   244
        testTranslate(a, Integer.MIN_VALUE, Integer.MIN_VALUE, false,
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   245
                      0, MAXCOORD, 0, MAXCOORD);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   246
        for (int dy = -100; dy <= 100; dy += 50) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   247
            for (int dx = -100; dx <= 100; dx += 50) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   248
                testTranslate(a, dx, dy, true,
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   249
                              MINCOORD, MAXCOORD,
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   250
                              MINCOORD, MAXCOORD);
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
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   253
    }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   254
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   255
    public static void testTranslate(RectListImpl a, int dx, int dy,
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   256
                                     boolean isNonDestructive,
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   257
                                     int xmin, int xmax,
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   258
                                     int ymin, int ymax)
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
        RectListImpl theTrans = a.getTranslation(dx, dy); numops++;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   261
        if (skipCheck) return;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   262
        RectListImpl unTrans = theTrans.getTranslation(-dx, -dy);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   263
        if (isNonDestructive) checkEqual(a, unTrans, "Translate");
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   264
        for (int x = xmin; x < xmax; x++) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   265
            for (int y = ymin; y < ymax; y++) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   266
                boolean inside = a.contains(x, y);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   267
                if (theTrans.contains(x+dx, y+dy) != inside) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   268
                    error(a, null, "translation failed for "+
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   269
                          dx+", "+dy+" at "+x+", "+y);
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
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   275
    public static void testUnion(RectListImpl a, RectListImpl b) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   276
        RectListImpl aUb = a.getUnion(b); numops++;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   277
        RectListImpl bUa = b.getUnion(a); numops++;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   278
        if (skipCheck) return;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   279
        checkEqual(aUb, bUa, "Union");
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   280
        testUnion(a, b, aUb);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   281
        testUnion(a, b, bUa);
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 testUnion(RectListImpl a, RectListImpl b,
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   285
                                 RectListImpl theUnion)
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 (theUnion.contains(x, y) != inside) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   291
                    error(a, b, "union 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 testDifference(RectListImpl a, RectListImpl b) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   298
        RectListImpl aDb = a.getDifference(b); numops++;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   299
        RectListImpl bDa = b.getDifference(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
        // Note that difference is not commutative so we cannot check equals
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   302
        // checkEqual(a, b, "Difference");
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   303
        testDifference(a, b, aDb);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   304
        testDifference(b, a, bDa);
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
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   307
    public static void testDifference(RectListImpl a, RectListImpl b,
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   308
                                      RectListImpl theDifference)
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   309
    {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   310
        for (int x = MINCOORD; x < MAXCOORD; x++) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   311
            for (int y = MINCOORD; y < MAXCOORD; y++) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   312
                boolean inside = (a.contains(x, y) && !b.contains(x, y));
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   313
                if (theDifference.contains(x, y) != inside) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   314
                    error(a, b, "difference failed at "+x+", "+y);
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
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   320
    public static void testIntersection(RectListImpl a, RectListImpl b) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   321
        RectListImpl aIb = a.getIntersection(b); numops++;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   322
        RectListImpl bIa = b.getIntersection(a); numops++;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   323
        if (skipCheck) return;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   324
        checkEqual(aIb, bIa, "Intersection");
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   325
        testIntersection(a, b, aIb);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   326
        testIntersection(a, b, bIa);
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
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   329
    public static void testIntersection(RectListImpl a, RectListImpl b,
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   330
                                        RectListImpl theIntersection)
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   331
    {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   332
        for (int x = MINCOORD; x < MAXCOORD; x++) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   333
            for (int y = MINCOORD; y < MAXCOORD; y++) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   334
                boolean inside = (a.contains(x, y) && b.contains(x, y));
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   335
                if (theIntersection.contains(x, y) != inside) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   336
                    error(a, b, "intersection failed at "+x+", "+y);
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
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   342
    public static void testExclusiveOr(RectListImpl a, RectListImpl b) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   343
        RectListImpl aXb = a.getExclusiveOr(b); numops++;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   344
        RectListImpl bXa = b.getExclusiveOr(a); numops++;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   345
        if (skipCheck) return;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   346
        checkEqual(aXb, bXa, "ExclusiveOr");
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   347
        testExclusiveOr(a, b, aXb);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   348
        testExclusiveOr(a, b, bXa);
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
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   351
    public static void testExclusiveOr(RectListImpl a, RectListImpl b,
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   352
                                       RectListImpl theExclusiveOr)
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
        for (int x = MINCOORD; x < MAXCOORD; x++) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   355
            for (int y = MINCOORD; y < MAXCOORD; y++) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   356
                boolean inside = (a.contains(x, y) != b.contains(x, y));
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   357
                if (theExclusiveOr.contains(x, y) != inside) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   358
                    error(a, b, "xor failed at "+x+", "+y);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   359
                }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   360
            }
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
    }
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 static class RectListImpl {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   365
        public static RectListImpl getInstance() {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   366
            if (useArea) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   367
                return new AreaImpl();
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   368
            } else {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   369
                return new RegionImpl();
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
        }
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
        public abstract void addRect(int lox, int loy, int hix, int hiy);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   374
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   375
        public abstract RectListImpl getTranslation(int dx, int dy);
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
        public abstract RectListImpl getIntersection(RectListImpl rli);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   378
        public abstract RectListImpl getExclusiveOr(RectListImpl rli);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   379
        public abstract RectListImpl getDifference(RectListImpl rli);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   380
        public abstract RectListImpl getUnion(RectListImpl rli);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   381
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   382
        // Used for making sure that 3xMAX translates yields an empty region
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   383
        public abstract boolean checkTransEmpty();
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
        public abstract boolean contains(int x, int y);
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 abstract int hashCode();
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   388
        public abstract boolean equals(RectListImpl other);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   389
    }
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
    public static class AreaImpl extends RectListImpl {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   392
        Area theArea;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   393
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   394
        public AreaImpl() {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   395
        }
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
        public AreaImpl(Area a) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   398
            theArea = a;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   399
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   400
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   401
        public void addRect(int lox, int loy, int hix, int hiy) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   402
            Area a2 = new Area(new Rectangle(lox, loy, hix-lox, hiy-loy));
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   403
            if (theArea == null) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   404
                theArea = a2;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   405
            } else {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   406
                theArea.add(a2);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   407
            }
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 getTranslation(int dx, int dy) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   411
            AffineTransform at = AffineTransform.getTranslateInstance(dx, dy);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   412
            return new AreaImpl(theArea.createTransformedArea(at));
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   413
        }
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
        public RectListImpl getIntersection(RectListImpl rli) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   416
            Area a2 = new Area(theArea);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   417
            a2.intersect(((AreaImpl) rli).theArea);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   418
            return new AreaImpl(a2);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   419
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   420
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   421
        public RectListImpl getExclusiveOr(RectListImpl rli) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   422
            Area a2 = new Area(theArea);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   423
            a2.exclusiveOr(((AreaImpl) rli).theArea);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   424
            return new AreaImpl(a2);
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 RectListImpl getDifference(RectListImpl rli) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   428
            Area a2 = new Area(theArea);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   429
            a2.subtract(((AreaImpl) rli).theArea);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   430
            return new AreaImpl(a2);
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
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   433
        public RectListImpl getUnion(RectListImpl rli) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   434
            Area a2 = new Area(theArea);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   435
            a2.add(((AreaImpl) rli).theArea);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   436
            return new AreaImpl(a2);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   437
        }
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
        // Used for making sure that 3xMAX translates yields an empty region
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   440
        public boolean checkTransEmpty() {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   441
            // Area objects will actually survive 3 MAX translates so just
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   442
            // pretend that it had the intended effect...
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   443
            return true;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   444
        }
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
        public boolean contains(int x, int y) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   447
            return theArea.contains(x, y);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   448
        }
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
        public int hashCode() {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   451
            // Area does not override hashCode...
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   452
            return 0;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   453
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   454
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   455
        public boolean equals(RectListImpl other) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   456
            return theArea.equals(((AreaImpl) other).theArea);
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
        public String toString() {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   460
            return theArea.toString();
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   461
        }
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 static class RegionImpl extends RectListImpl {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   465
        Region theRegion;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   466
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   467
        public RegionImpl() {
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 RegionImpl(Region r) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   471
            theRegion = r;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   472
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   473
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   474
        public void addRect(int lox, int loy, int hix, int hiy) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   475
            Region r2 = Region.getInstanceXYXY(lox, loy, hix, hiy);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   476
            if (theRegion == null) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   477
                theRegion = r2;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   478
            } else {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   479
                theRegion = theRegion.getUnion(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
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   483
        public RectListImpl getTranslation(int dx, int dy) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   484
            return new RegionImpl(theRegion.getTranslatedRegion(dx, dy));
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   485
        }
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
        public RectListImpl getIntersection(RectListImpl rli) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   488
            Region r2 = ((RegionImpl) rli).theRegion;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   489
            r2 = theRegion.getIntersection(r2);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   490
            return new RegionImpl(r2);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   491
        }
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
        public RectListImpl getExclusiveOr(RectListImpl rli) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   494
            Region r2 = ((RegionImpl) rli).theRegion;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   495
            r2 = theRegion.getExclusiveOr(r2);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   496
            return new RegionImpl(r2);
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
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   499
        public RectListImpl getDifference(RectListImpl rli) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   500
            Region r2 = ((RegionImpl) rli).theRegion;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   501
            r2 = theRegion.getDifference(r2);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   502
            return new RegionImpl(r2);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   503
        }
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
        public RectListImpl getUnion(RectListImpl rli) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   506
            Region r2 = ((RegionImpl) rli).theRegion;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   507
            r2 = theRegion.getUnion(r2);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   508
            return new RegionImpl(r2);
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
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   511
        // Used for making sure that 3xMAX translates yields an empty region
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   512
        public boolean checkTransEmpty() {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   513
            // Region objects should be empty after 3 MAX translates...
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   514
            return theRegion.isEmpty();
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   515
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   516
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   517
        public boolean contains(int x, int y) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   518
            return theRegion.contains(x, y);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   519
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   520
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   521
        public int hashCode() {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   522
            return theRegion.hashCode();
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   523
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   524
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   525
        public boolean equals(RectListImpl other) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   526
            return theRegion.equals(((RegionImpl) other).theRegion);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   527
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   528
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   529
        public String toString() {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   530
            return theRegion.toString();
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   531
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   532
    }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents:
diff changeset
   533
}