Imported GNU Classpath 0.90
[official-gcc.git] / libjava / classpath / gnu / java / awt / java2d / PolyEdge.java
blob621bd3ad8200141a4f64853e799b585281e68a67
1 /* PolyEdge.java -- An edge in a polygon, used for polygon filling
2 Copyright (C) 2006 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 package gnu.java.awt.java2d;
41 /**
42 * An edge in a polygon. This is used by the scanline conversion algorithm
43 * implemented in {@link AbstractGraphics2D#rawFillShape}.
45 * @author Roman Kennke (kennke@aicas.com)
47 public class PolyEdge
48 implements Comparable
51 /**
52 * The start and end coordinates of the edge. y0 is always smaller or equal
53 * than y1.
55 public double x0, y0, x1, y1;
57 /**
58 * The slope of the edge. This is dx / dy.
60 double slope;
62 /**
63 * The intersection of this edge with the current scanline.
65 double xIntersection;
67 /**
68 * Creates a new PolyEdge with the specified coordinates.
70 * @param x0 the starting point, x coordinate
71 * @param y0 the starting point, y coordinate
72 * @param x1 the end point, x coordinate
73 * @param y1 the end point, y coordinate
75 PolyEdge(double x0, double y0, double x1, double y1)
77 if (y0 < y1)
79 this.x0 = x0;
80 this.y0 = y0;
81 this.x1 = x1;
82 this.y1 = y1;
84 else
86 this.x0 = x1;
87 this.y0 = y1;
88 this.x1 = x0;
89 this.y1 = y0;
91 slope = (this.x1 - this.x0) / (this.y1 - this.y0);
92 if (this.y0 == this.y1) // Horizontal edge.
93 xIntersection = Math.min(this.x0, this.x1);
94 else
95 xIntersection = this.x0 + slope * (Math.ceil(this.y0) - this.y0);
98 /**
99 * Sorts PolyEdges by the x coordinate from the minimum x value.
101 public int compareTo(Object o)
103 PolyEdge other = (PolyEdge) o;
104 int comp = 0;
105 if (x0 < other.x0)
106 comp = -1;
107 else if (x0 > other.x0)
108 comp = 1;
109 return comp;
112 public String toString()
114 return "Edge: " + x0 + ", " + y0 + ", " + x1 + ", " + y1 + ", slope: "
115 + slope + ", xIntersection: " + xIntersection;