OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libjava/] [classpath/] [gnu/] [java/] [awt/] [java2d/] [PolyEdge.java] - Blame information for rev 791

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 769 jeremybenn
/* PolyEdge.java -- An edge in a polygon, used for polygon filling
2
   Copyright (C) 2006 Free Software Foundation, Inc.
3
 
4
This file is part of GNU Classpath.
5
 
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.
10
 
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.
15
 
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.
20
 
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.
25
 
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. */
37
 
38
 
39
package gnu.java.awt.java2d;
40
 
41
import gnu.java.math.Fixed;
42
 
43
/**
44
 * An edge in a polygon.
45
 *
46
 * @author Roman Kennke (kennke@aicas.com)
47
 */
48
final class PolyEdge
49
  implements Comparable
50
{
51
 
52
  /**
53
   * The start and end coordinates of the edge. y0 is always smaller or equal
54
   * than y1.
55
   *
56
   * These values are stored as fixed-point decimals.
57
   */
58
  public int x0, y0, x1, y1;
59
 
60
  /**
61
   * The slope of the edge. This is dx / dy.
62
   *
63
   * This is a fixed point decimal.
64
   */
65
  private int slope;
66
 
67
  /**
68
   * The intersection of this edge with the current scanline.
69
   *
70
   * This is a fixed point decimal.
71
   */
72
  int xIntersection;
73
 
74
  /**
75
   * Indicates whether this edge is from the clip or from the target shape.
76
   */
77
  boolean isClip;
78
 
79
  /**
80
   * Implements a linked list for the edge pool.
81
   */
82
  PolyEdge poolNext;
83
 
84
  /**
85
   * Implements a linked list for the scanline edge lists.
86
   */
87
  PolyEdge scanlineNext;
88
 
89
  /**
90
   * Create an uninitialized edge.
91
   */
92
  PolyEdge()
93
  {
94
    // Nothing to do here.
95
  }
96
 
97
  /**
98
   * Creates a new PolyEdge with the specified coordinates.
99
   *
100
   * @param x0 the starting point, x coordinate
101
   * @param y0 the starting point, y coordinate
102
   * @param x1 the end point, x coordinate
103
   * @param y1 the end point, y coordinate
104
   */
105
  PolyEdge(int n, int x0, int y0, int x1, int y1, boolean clip)
106
  {
107
    init(n, x0, y0, x1, y1, clip);
108
  }
109
 
110
  /**
111
   * (Re-) Initializes this edge.
112
   *
113
   * @param x0
114
   * @param y0
115
   * @param x1
116
   * @param y1
117
   */
118
  void init(int n, int x0, int y0, int x1, int y1, boolean clip)
119
  {
120
    isClip = clip;
121
    if (y0 < y1)
122
      {
123
        this.x0 = x0;
124
        this.y0 = y0;
125
        this.x1 = x1;
126
        this.y1 = y1;
127
      }
128
    else
129
      {
130
        this.x0 = x1;
131
        this.y0 = y1;
132
        this.x1 = x0;
133
        this.y1 = y0;
134
      }
135
    slope = Fixed.div(n, this.x1 - this.x0, this.y1 - this.y0);
136
  }
137
 
138
  /**
139
   * Sorts PolyEdges by the x coordinate from the minimum x value.
140
   */
141
  public int compareTo(Object o)
142
  {
143
    PolyEdge other = (PolyEdge) o;
144
    int comp = 0;
145
    if (x0 < other.x0)
146
      comp = -1;
147
    else if (x0 > other.x0)
148
      comp = 1;
149
    return comp;
150
  }
151
 
152
  /**
153
   * Intersects this edge with the scanline at height y. The result is
154
   * stored in {@link #xIntersection}.
155
   *
156
   * @param y the scanline
157
   */
158
  void intersect(int n, int y)
159
  {
160
    int dy = y - y0;
161
    int dx = Fixed.mul(n, slope, dy);
162
    xIntersection = x0 + dx;
163
  }
164
 
165
  public String toString()
166
  {
167
    return "Edge: " + x0 + ", " + y0 + ", " + x1 + ", " + y1 + ", slope: "
168
           + slope + ", xIntersection: " + xIntersection
169
           + ", isClip: " + isClip;
170
  }
171
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.