org.openstreetmap.josm.data.osm.visitor.paint
Class LineClip
java.lang.Object
org.openstreetmap.josm.data.osm.visitor.paint.LineClip
public class LineClip
- extends java.lang.Object
Computes the part of a line that is visible in a given rectangle.
Using int leads to overflow, so we need long int.
Field Summary |
private java.awt.Rectangle |
clipBounds
|
private java.awt.Point |
p1
|
private java.awt.Point |
p2
|
Constructor Summary |
LineClip(java.awt.Point p1,
java.awt.Point p2,
java.awt.Rectangle clipBounds)
|
Method Summary |
private boolean |
cohenSutherland(long x1,
long y1,
long x2,
long y2,
long xmin,
long ymin,
long xmax,
long ymax)
see http://en.wikipedia.org/wiki/Cohen-Sutherland |
private static int |
computeOutCode(long x,
long y,
long xmin,
long ymin,
long xmax,
long ymax)
The outcode of the point. |
boolean |
execute()
run the clipping algorithm |
java.awt.Point |
getP1()
|
java.awt.Point |
getP2()
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
p1
private java.awt.Point p1
p2
private java.awt.Point p2
clipBounds
private final java.awt.Rectangle clipBounds
LineClip
public LineClip(java.awt.Point p1,
java.awt.Point p2,
java.awt.Rectangle clipBounds)
execute
public boolean execute()
- run the clipping algorithm
- Returns:
- true if the some parts of the line lies within the clip bounds
getP1
public java.awt.Point getP1()
- Returns:
- start point of the clipped line
getP2
public java.awt.Point getP2()
- Returns:
- end point of the clipped line
cohenSutherland
private boolean cohenSutherland(long x1,
long y1,
long x2,
long y2,
long xmin,
long ymin,
long xmax,
long ymax)
- see http://en.wikipedia.org/wiki/Cohen-Sutherland
- Returns:
- true, if line is visible in the given clip region
computeOutCode
private static int computeOutCode(long x,
long y,
long xmin,
long ymin,
long xmax,
long ymax)
- The outcode of the point.
We cannot use Rectangle.outcode since it does not work with long ints.
JOSM