net.talvi.puffinplot
Class Util

java.lang.Object
  extended by net.talvi.puffinplot.Util

public class Util
extends java.lang.Object

This class collects miscellaneous, general-purpose utility functions which are useful to PuffinPlot.


Constructor Summary
Util()
           
 
Method Summary
static java.awt.geom.Line2D clipLineToRectangle(java.awt.geom.Line2D line, java.awt.geom.Rectangle2D r)
          Clips a line to a supplied rectangle.
static java.awt.geom.Rectangle2D envelope(java.util.Collection<java.awt.geom.Point2D> points)
          Returns the rectangular envelope for the supplied points.
static java.util.BitSet numberRangeStringToBitSet(java.lang.String input, int limit)
          Converts a string specification of number ranges to a corresponding BitSet.
static java.awt.geom.Line2D scaleLine(java.awt.geom.Line2D line, double scale)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Util

public Util()
Method Detail

numberRangeStringToBitSet

public static java.util.BitSet numberRangeStringToBitSet(java.lang.String input,
                                                         int limit)

Converts a string specification of number ranges to a corresponding BitSet. The specification is of the form commonly encountered in Print dialog boxes: a sequence of comma-separated units. Each unit can be either an integer (meaning that the corresponding item should be selected) or two integers separated by a hyphen (-) character (meaning that all items in the corresponding range should be selected). Example inputs and outputs are shown below.

1 1
1,3 101
4-6 000111
4-6,8-10,10,11,15-16 0001110111100011
1-4,3-5,10,12-14,17 11111000010111001

Note that the range specifications are one-based (the first item is specified by 1, not 0) but the BitSet output is zero-based.

Since an error in the specification string might result in an impractically large bitset, this method also takes a limit argument; no bits will be set beyond the specified limit.

Parameters:
input - a specification string
limit - upper limit for bits to set; limit-1 will be the highest possible set bit
Returns:
a bit-set representation of the specified range

clipLineToRectangle

public static java.awt.geom.Line2D clipLineToRectangle(java.awt.geom.Line2D line,
                                                       java.awt.geom.Rectangle2D r)
Clips a line to a supplied rectangle.

Parameters:
line - a line
r - a clipping rectangle
Returns:
the line, as clipped to the supplied rectangle

envelope

public static java.awt.geom.Rectangle2D envelope(java.util.Collection<java.awt.geom.Point2D> points)
Returns the rectangular envelope for the supplied points. This is the smallest rectangle which contains all the points.

Parameters:
points - a set of points
Returns:
the smallest rectangle which contains all the points

scaleLine

public static java.awt.geom.Line2D scaleLine(java.awt.geom.Line2D line,
                                             double scale)