1 /*
2  * Copyright (c) 1998, Oracle and/or its affiliates. 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.  Oracle designates this
8  * particular file as subject to the "Classpath" exception as provided
9  * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22  * or visit www.oracle.com if you need additional information or have any
23  * questions.
24  */
25 
26 package sun.awt.geom;
27 
28 final class CurveLink {
29     Curve curve;
30     double ytop;
31     double ybot;
32     int etag;
33 
34     CurveLink next;
35 
CurveLink(Curve curve, double ystart, double yend, int etag)36     public CurveLink(Curve curve, double ystart, double yend, int etag) {
37         this.curve = curve;
38         this.ytop = ystart;
39         this.ybot = yend;
40         this.etag = etag;
41         if (ytop < curve.getYTop() || ybot > curve.getYBot()) {
42             throw new InternalError("bad curvelink ["+ytop+"=>"+ybot+"] for "+curve);
43         }
44     }
45 
absorb(CurveLink link)46     public boolean absorb(CurveLink link) {
47         return absorb(link.curve, link.ytop, link.ybot, link.etag);
48     }
49 
absorb(Curve curve, double ystart, double yend, int etag)50     public boolean absorb(Curve curve, double ystart, double yend, int etag) {
51         if (this.curve != curve || this.etag != etag ||
52             ybot < ystart || ytop > yend)
53         {
54             return false;
55         }
56         if (ystart < curve.getYTop() || yend > curve.getYBot()) {
57             throw new InternalError("bad curvelink ["+ystart+"=>"+yend+"] for "+curve);
58         }
59         this.ytop = Math.min(ytop, ystart);
60         this.ybot = Math.max(ybot, yend);
61         return true;
62     }
63 
isEmpty()64     public boolean isEmpty() {
65         return (ytop == ybot);
66     }
67 
getCurve()68     public Curve getCurve() {
69         return curve;
70     }
71 
getSubCurve()72     public Curve getSubCurve() {
73         if (ytop == curve.getYTop() && ybot == curve.getYBot()) {
74             return curve.getWithDirection(etag);
75         }
76         return curve.getSubCurve(ytop, ybot, etag);
77     }
78 
getMoveto()79     public Curve getMoveto() {
80         return new Order0(getXTop(), getYTop());
81     }
82 
getXTop()83     public double getXTop() {
84         return curve.XforY(ytop);
85     }
86 
getYTop()87     public double getYTop() {
88         return ytop;
89     }
90 
getXBot()91     public double getXBot() {
92         return curve.XforY(ybot);
93     }
94 
getYBot()95     public double getYBot() {
96         return ybot;
97     }
98 
getX()99     public double getX() {
100         return curve.XforY(ytop);
101     }
102 
getEdgeTag()103     public int getEdgeTag() {
104         return etag;
105     }
106 
setNext(CurveLink link)107     public void setNext(CurveLink link) {
108         this.next = link;
109     }
110 
getNext()111     public CurveLink getNext() {
112         return next;
113     }
114 }
115