blob: a76674548dac1eeb0f75ed4a1f6c8e6b7a0c8372 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 1998 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25
26package sun.awt.geom;
27
28final class ChainEnd {
29 CurveLink head;
30 CurveLink tail;
31 ChainEnd partner;
32 int etag;
33
34 public ChainEnd(CurveLink first, ChainEnd partner) {
35 this.head = first;
36 this.tail = first;
37 this.partner = partner;
38 this.etag = first.getEdgeTag();
39 }
40
41 public CurveLink getChain() {
42 return head;
43 }
44
45 public void setOtherEnd(ChainEnd partner) {
46 this.partner = partner;
47 }
48
49 public ChainEnd getPartner() {
50 return partner;
51 }
52
53 /*
54 * Returns head of a complete chain to be added to subcurves
55 * or null if the links did not complete such a chain.
56 */
57 public CurveLink linkTo(ChainEnd that) {
58 if (etag == AreaOp.ETAG_IGNORE ||
59 that.etag == AreaOp.ETAG_IGNORE)
60 {
61 throw new InternalError("ChainEnd linked more than once!");
62 }
63 if (etag == that.etag) {
64 throw new InternalError("Linking chains of the same type!");
65 }
66 ChainEnd enter, exit;
67 // assert(partner.etag != that.partner.etag);
68 if (etag == AreaOp.ETAG_ENTER) {
69 enter = this;
70 exit = that;
71 } else {
72 enter = that;
73 exit = this;
74 }
75 // Now make sure these ChainEnds are not linked to any others...
76 etag = AreaOp.ETAG_IGNORE;
77 that.etag = AreaOp.ETAG_IGNORE;
78 // Now link everything up...
79 enter.tail.setNext(exit.head);
80 enter.tail = exit.tail;
81 if (partner == that) {
82 // Curve has closed on itself...
83 return enter.head;
84 }
85 // Link this chain into one end of the chain formed by the partners
86 ChainEnd otherenter = exit.partner;
87 ChainEnd otherexit = enter.partner;
88 otherenter.partner = otherexit;
89 otherexit.partner = otherenter;
90 if (enter.head.getYTop() < otherenter.head.getYTop()) {
91 enter.tail.setNext(otherenter.head);
92 otherenter.head = enter.head;
93 } else {
94 otherexit.tail.setNext(enter.head);
95 otherexit.tail = enter.tail;
96 }
97 return null;
98 }
99
100 public void addLink(CurveLink newlink) {
101 if (etag == AreaOp.ETAG_ENTER) {
102 tail.setNext(newlink);
103 tail = newlink;
104 } else {
105 newlink.setNext(head);
106 head = newlink;
107 }
108 }
109
110 public double getX() {
111 if (etag == AreaOp.ETAG_ENTER) {
112 return tail.getXBot();
113 } else {
114 return head.getXBot();
115 }
116 }
117}