jdk/src/java.desktop/share/classes/sun/awt/geom/Crossings.java
author ddehaven
Tue, 19 Aug 2014 10:32:16 -0700
changeset 26037 508779ce6619
parent 26004 jdk/src/share/classes/sun/awt/geom/Crossings.java@7507a1b93f67
parent 25859 jdk/src/share/classes/sun/awt/geom/Crossings.java@3317bb8137f4
child 32865 f9cb6e427f9e
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
22567
5816a47fa4dd 8032047: Fix static lint warnings in client libraries
darcy
parents: 5506
diff changeset
     2
 * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.awt.geom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.geom.PathIterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.Vector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.Enumeration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
public abstract class Crossings {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
    public static final boolean debug = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
    int limit = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
    double yranges[] = new double[10];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
    double xlo, ylo, xhi, yhi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    public Crossings(double xlo, double ylo, double xhi, double yhi) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
        this.xlo = xlo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
        this.ylo = ylo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
        this.xhi = xhi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
        this.yhi = yhi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    public final double getXLo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        return xlo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    public final double getYLo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        return ylo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    public final double getXHi() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        return xhi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    public final double getYHi() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        return yhi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    public abstract void record(double ystart, double yend, int direction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    public void print() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        System.out.println("Crossings [");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        System.out.println("  bounds = ["+ylo+", "+yhi+"]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        for (int i = 0; i < limit; i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
            System.out.println("  ["+yranges[i]+", "+yranges[i+1]+"]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        System.out.println("]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    public final boolean isEmpty() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        return (limit == 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    public abstract boolean covers(double ystart, double yend);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 22567
diff changeset
    80
    public static Crossings findCrossings(Vector<? extends Curve> curves,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
                                          double xlo, double ylo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                                          double xhi, double yhi)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        Crossings cross = new EvenOdd(xlo, ylo, xhi, yhi);
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 22567
diff changeset
    85
        Enumeration<? extends Curve> enum_ = curves.elements();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        while (enum_.hasMoreElements()) {
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 22567
diff changeset
    87
            Curve c = enum_.nextElement();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            if (c.accumulateCrossings(cross)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        if (debug) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            cross.print();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        return cross;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    public static Crossings findCrossings(PathIterator pi,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                                          double xlo, double ylo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                                          double xhi, double yhi)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        Crossings cross;
22567
5816a47fa4dd 8032047: Fix static lint warnings in client libraries
darcy
parents: 5506
diff changeset
   103
        if (pi.getWindingRule() == PathIterator.WIND_EVEN_ODD) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            cross = new EvenOdd(xlo, ylo, xhi, yhi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            cross = new NonZero(xlo, ylo, xhi, yhi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        // coords array is big enough for holding:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        //     coordinates returned from currentSegment (6)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        //     OR
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        //         two subdivided quadratic curves (2+4+4=10)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        //         AND
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        //             0-1 horizontal splitting parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        //             OR
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        //             2 parametric equation derivative coefficients
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        //     OR
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        //         three subdivided cubic curves (2+6+6+6=20)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        //         AND
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        //             0-2 horizontal splitting parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        //             OR
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        //             3 parametric equation derivative coefficients
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        double coords[] = new double[23];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        double movx = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        double movy = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        double curx = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        double cury = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        double newx, newy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        while (!pi.isDone()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            int type = pi.currentSegment(coords);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            switch (type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            case PathIterator.SEG_MOVETO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                if (movy != cury &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                    cross.accumulateLine(curx, cury, movx, movy))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                movx = curx = coords[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                movy = cury = coords[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            case PathIterator.SEG_LINETO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                newx = coords[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                newy = coords[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                if (cross.accumulateLine(curx, cury, newx, newy)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                curx = newx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                cury = newy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            case PathIterator.SEG_QUADTO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                newx = coords[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                newy = coords[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                if (cross.accumulateQuad(curx, cury, coords)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                curx = newx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                cury = newy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            case PathIterator.SEG_CUBICTO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                newx = coords[4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                newy = coords[5];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                if (cross.accumulateCubic(curx, cury, coords)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                curx = newx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                cury = newy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            case PathIterator.SEG_CLOSE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                if (movy != cury &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                    cross.accumulateLine(curx, cury, movx, movy))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                curx = movx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                cury = movy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            pi.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        if (movy != cury) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            if (cross.accumulateLine(curx, cury, movx, movy)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        if (debug) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            cross.print();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        return cross;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    public boolean accumulateLine(double x0, double y0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                                  double x1, double y1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        if (y0 <= y1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            return accumulateLine(x0, y0, x1, y1, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            return accumulateLine(x1, y1, x0, y0, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    public boolean accumulateLine(double x0, double y0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                                  double x1, double y1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                                  int direction)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        if (yhi <= y0 || ylo >= y1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        if (x0 >= xhi && x1 >= xhi) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        if (y0 == y1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            return (x0 >= xlo || x1 >= xlo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        double xstart, ystart, xend, yend;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        double dx = (x1 - x0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        double dy = (y1 - y0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        if (y0 < ylo) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            xstart = x0 + (ylo - y0) * dx / dy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            ystart = ylo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            xstart = x0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            ystart = y0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        if (yhi < y1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            xend = x0 + (yhi - y0) * dx / dy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            yend = yhi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            xend = x1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            yend = y1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        if (xstart >= xhi && xend >= xhi) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        if (xstart > xlo || xend > xlo) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        record(ystart, yend, direction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 22567
diff changeset
   240
    private Vector<Curve> tmp = new Vector<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    public boolean accumulateQuad(double x0, double y0, double coords[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        if (y0 < ylo && coords[1] < ylo && coords[3] < ylo) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        if (y0 > yhi && coords[1] > yhi && coords[3] > yhi) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        if (x0 > xhi && coords[0] > xhi && coords[2] > xhi) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        if (x0 < xlo && coords[0] < xlo && coords[2] < xlo) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            if (y0 < coords[3]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                record(Math.max(y0, ylo), Math.min(coords[3], yhi), 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            } else if (y0 > coords[3]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                record(Math.max(coords[3], ylo), Math.min(y0, yhi), -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        Curve.insertQuad(tmp, x0, y0, coords);
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 22567
diff changeset
   261
        Enumeration<Curve> enum_ = tmp.elements();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        while (enum_.hasMoreElements()) {
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 22567
diff changeset
   263
            Curve c = enum_.nextElement();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            if (c.accumulateCrossings(this)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        tmp.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    public boolean accumulateCubic(double x0, double y0, double coords[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        if (y0 < ylo && coords[1] < ylo &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            coords[3] < ylo && coords[5] < ylo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        if (y0 > yhi && coords[1] > yhi &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            coords[3] > yhi && coords[5] > yhi)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        if (x0 > xhi && coords[0] > xhi &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            coords[2] > xhi && coords[4] > xhi)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        if (x0 < xlo && coords[0] < xlo &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            coords[2] < xlo && coords[4] < xlo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            if (y0 <= coords[5]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                record(Math.max(y0, ylo), Math.min(coords[5], yhi), 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                record(Math.max(coords[5], ylo), Math.min(y0, yhi), -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        Curve.insertCubic(tmp, x0, y0, coords);
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 22567
diff changeset
   299
        Enumeration<Curve> enum_ = tmp.elements();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        while (enum_.hasMoreElements()) {
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 22567
diff changeset
   301
            Curve c = enum_.nextElement();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            if (c.accumulateCrossings(this)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        tmp.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    public final static class EvenOdd extends Crossings {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        public EvenOdd(double xlo, double ylo, double xhi, double yhi) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            super(xlo, ylo, xhi, yhi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
26004
7507a1b93f67 6521783: Unnecessary final modifier for a method in a final class
serb
parents: 24538
diff changeset
   315
        public boolean covers(double ystart, double yend) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            return (limit == 2 && yranges[0] <= ystart && yranges[1] >= yend);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        public void record(double ystart, double yend, int direction) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            if (ystart >= yend) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
            int from = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            // Quickly jump over all pairs that are completely "above"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
            while (from < limit && ystart > yranges[from+1]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                from += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
            int to = from;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
            while (from < limit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                double yrlo = yranges[from++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                double yrhi = yranges[from++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                if (yend < yrlo) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                    // Quickly handle insertion of the new range
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                    yranges[to++] = ystart;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                    yranges[to++] = yend;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                    ystart = yrlo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                    yend = yrhi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                // The ranges overlap - sort, collapse, insert, iterate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                double yll, ylh, yhl, yhh;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                if (ystart < yrlo) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                    yll = ystart;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                    ylh = yrlo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                    yll = yrlo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                    ylh = ystart;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                if (yend < yrhi) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                    yhl = yend;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                    yhh = yrhi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                    yhl = yrhi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                    yhh = yend;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                if (ylh == yhl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                    ystart = yll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                    yend = yhh;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                    if (ylh > yhl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                        ystart = yhl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
                        yhl = ylh;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                        ylh = ystart;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                    if (yll != ylh) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                        yranges[to++] = yll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
                        yranges[to++] = ylh;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                    ystart = yhl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                    yend = yhh;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                if (ystart >= yend) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
            if (to < from && from < limit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                System.arraycopy(yranges, from, yranges, to, limit-from);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            to += (limit-from);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            if (ystart < yend) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                if (to >= yranges.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                    double newranges[] = new double[to+10];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                    System.arraycopy(yranges, 0, newranges, 0, to);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                    yranges = newranges;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
                yranges[to++] = ystart;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                yranges[to++] = yend;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
            limit = to;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    public final static class NonZero extends Crossings {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        private int crosscounts[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        public NonZero(double xlo, double ylo, double xhi, double yhi) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
            super(xlo, ylo, xhi, yhi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
            crosscounts = new int[yranges.length / 2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
26004
7507a1b93f67 6521783: Unnecessary final modifier for a method in a final class
serb
parents: 24538
diff changeset
   401
        public boolean covers(double ystart, double yend) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
            int i = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            while (i < limit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
                double ylo = yranges[i++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                double yhi = yranges[i++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                if (ystart >= yhi) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
                if (ystart < ylo) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                if (yend <= yhi) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
                ystart = yhi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
            return (ystart >= yend);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        public void remove(int cur) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
            limit -= 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
            int rem = limit - cur;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
            if (rem > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                System.arraycopy(yranges, cur+2, yranges, cur, rem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                System.arraycopy(crosscounts, cur/2+1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                                 crosscounts, cur/2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                                 rem/2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        public void insert(int cur, double lo, double hi, int dir) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
            int rem = limit - cur;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
            double oldranges[] = yranges;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
            int oldcounts[] = crosscounts;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
            if (limit >= yranges.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                yranges = new double[limit+10];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                System.arraycopy(oldranges, 0, yranges, 0, cur);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                crosscounts = new int[(limit+10)/2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                System.arraycopy(oldcounts, 0, crosscounts, 0, cur/2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
            if (rem > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                System.arraycopy(oldranges, cur, yranges, cur+2, rem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                System.arraycopy(oldcounts, cur/2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                                 crosscounts, cur/2+1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                                 rem/2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
            yranges[cur+0] = lo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
            yranges[cur+1] = hi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
            crosscounts[cur/2] = dir;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
            limit += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        public void record(double ystart, double yend, int direction) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
            if (ystart >= yend) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
            int cur = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
            // Quickly jump over all pairs that are completely "above"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            while (cur < limit && ystart > yranges[cur+1]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                cur += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
            if (cur < limit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                int rdir = crosscounts[cur/2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                double yrlo = yranges[cur+0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                double yrhi = yranges[cur+1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                if (yrhi == ystart && rdir == direction) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                    // Remove the range from the list and collapse it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                    // into the range being inserted.  Note that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                    // new combined range may overlap the following range
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                    // so we must not simply combine the ranges in place
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                    // unless we are at the last range.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                    if (cur+2 == limit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                        yranges[cur+1] = yend;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                    remove(cur);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                    ystart = yrlo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
                    rdir = crosscounts[cur/2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
                    yrlo = yranges[cur+0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
                    yrhi = yranges[cur+1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
                if (yend < yrlo) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                    // Just insert the new range at the current location
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
                    insert(cur, ystart, yend, direction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                if (yend == yrlo && rdir == direction) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
                    // Just prepend the new range to the current one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
                    yranges[cur] = ystart;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
                // The ranges must overlap - (yend > yrlo && yrhi > ystart)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
                if (ystart < yrlo) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
                    insert(cur, ystart, yrlo, direction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
                    cur += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
                    ystart = yrlo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
                } else if (yrlo < ystart) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
                    insert(cur, yrlo, ystart, rdir);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
                    cur += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
                    yrlo = ystart;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
                // assert(yrlo == ystart);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
                int newdir = rdir + direction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
                double newend = Math.min(yend, yrhi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
                if (newdir == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
                    remove(cur);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
                    crosscounts[cur/2] = newdir;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
                    yranges[cur++] = ystart;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
                    yranges[cur++] = newend;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
                ystart = yrlo = newend;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
                if (yrlo < yrhi) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
                    insert(cur, yrlo, yrhi, rdir);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
            if (ystart < yend) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
                insert(cur, ystart, yend, direction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
}