uk.me.parabola.mkgmap.general
Class LineClipper

java.lang.Object
  extended by uk.me.parabola.mkgmap.general.LineClipper

public class LineClipper
extends java.lang.Object

Routine to clip a polyline to a given bounding box.

Author:
Steve Ratcliffe
See Also:
A very clear explaination of the Liang-Barsky algorithm

Constructor Summary
LineClipper()
           
 
Method Summary
static Coord[] clip(Area a, Coord[] ends)
          A straight forward implementation of the Liang-Barsky algorithm as described in the referenced web page.
static java.util.List<java.util.List<Coord>> clip(Area a, java.util.List<Coord> coords)
          Clips a polyline by the given bounding box.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LineClipper

public LineClipper()
Method Detail

clip

public static java.util.List<java.util.List<Coord>> clip(Area a,
                                                         java.util.List<Coord> coords)
Clips a polyline by the given bounding box. This may produce several separate lines if the line meanders in and out of the box. This will work even if no point is actually inside the box.

Parameters:
a - The bounding area.
coords - A list of the points in the line.
Returns:
Returns null if the line is completely in the bounding box and this is expected to be the normal case. If clipping is needed then an array of point lists is returned.

clip

public static Coord[] clip(Area a,
                           Coord[] ends)
A straight forward implementation of the Liang-Barsky algorithm as described in the referenced web page.

Parameters:
a - The clipping area.
ends - The start and end of the line the contents of this will be changed if the line is clipped to contain the new start and end points. A point that was inside the box will not be changed.
Returns:
An array of the new start and end points if any of the line is within the box. If the line is wholly outside then null is returned. If a point is within the box then the same coordinate object will be returned as was passed in.
See Also:
Liang-Barsky algorithm