001: /*
002: * Copyright 1998 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package sun.awt.geom;
027:
028: final class Edge {
029: static final int INIT_PARTS = 4;
030: static final int GROW_PARTS = 10;
031:
032: Curve curve;
033: int ctag;
034: int etag;
035: double activey;
036: int equivalence;
037:
038: public Edge(Curve c, int ctag) {
039: this (c, ctag, AreaOp.ETAG_IGNORE);
040: }
041:
042: public Edge(Curve c, int ctag, int etag) {
043: this .curve = c;
044: this .ctag = ctag;
045: this .etag = etag;
046: }
047:
048: public Curve getCurve() {
049: return curve;
050: }
051:
052: public int getCurveTag() {
053: return ctag;
054: }
055:
056: public int getEdgeTag() {
057: return etag;
058: }
059:
060: public void setEdgeTag(int etag) {
061: this .etag = etag;
062: }
063:
064: public int getEquivalence() {
065: return equivalence;
066: }
067:
068: public void setEquivalence(int eq) {
069: equivalence = eq;
070: }
071:
072: private Edge lastEdge;
073: private int lastResult;
074: private double lastLimit;
075:
076: public int compareTo(Edge other, double yrange[]) {
077: if (other == lastEdge && yrange[0] < lastLimit) {
078: if (yrange[1] > lastLimit) {
079: yrange[1] = lastLimit;
080: }
081: return lastResult;
082: }
083: if (this == other.lastEdge && yrange[0] < other.lastLimit) {
084: if (yrange[1] > other.lastLimit) {
085: yrange[1] = other.lastLimit;
086: }
087: return 0 - other.lastResult;
088: }
089: //long start = System.currentTimeMillis();
090: int ret = curve.compareTo(other.curve, yrange);
091: //long end = System.currentTimeMillis();
092: /*
093: System.out.println("compare: "+
094: ((System.identityHashCode(this) <
095: System.identityHashCode(other))
096: ? this+" to "+other
097: : other+" to "+this)+
098: " == "+ret+" at "+yrange[1]+
099: " in "+(end-start)+"ms");
100: */
101: lastEdge = other;
102: lastLimit = yrange[1];
103: lastResult = ret;
104: return ret;
105: }
106:
107: public void record(double yend, int etag) {
108: this .activey = yend;
109: this .etag = etag;
110: }
111:
112: public boolean isActiveFor(double y, int etag) {
113: return (this .etag == etag && this .activey >= y);
114: }
115:
116: public String toString() {
117: return ("Edge["
118: + curve
119: + ", "
120: + (ctag == AreaOp.CTAG_LEFT ? "L" : "R")
121: + ", "
122: + (etag == AreaOp.ETAG_ENTER ? "I"
123: : (etag == AreaOp.ETAG_EXIT ? "O" : "N")) + "]");
124: }
125: }
|