com.threerings.puzzle.util
Class PointSet

java.lang.Object
  extended by com.threerings.puzzle.util.PointSet

public class PointSet
extends Object

The point set class provides an efficient implementation of a set containing two-dimensional point values as (x, y).


Nested Class Summary
protected  class PointSet.PointIterator
           
 
Field Summary
protected  int _count
          The number of points in the set.
protected  boolean[][] _points
          The points in the set.
protected  int _rangeX
          The dimensions of the point array.
protected  int _rangeY
          The dimensions of the point array.
 
Constructor Summary
PointSet(int rangeX, int rangeY)
          Creates a point set that can contain points within the given range of values.
 
Method Summary
 boolean add(int x, int y)
          Adds a point to the set and returns whether the point was already present in the set.
 void addAll(PointSet set)
          Adds all points in the given set to this set.
 void clear()
          Clears all points from this set.
 boolean contains(int x, int y)
          Returns whether this set contains the given point.
 boolean isEmpty()
          Returns whether this set is empty.
 Iterator<Point> iterator()
          Returns an iterator that iterates over the points in this set, returning them as Point objects.
 boolean remove(int x, int y)
          Removes the given point from the set and returns whether the point was present in the set.
 int size()
          Returns the number of points in the set.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_rangeX

protected int _rangeX
The dimensions of the point array.


_rangeY

protected int _rangeY
The dimensions of the point array.


_points

protected boolean[][] _points
The points in the set.


_count

protected int _count
The number of points in the set.

Constructor Detail

PointSet

public PointSet(int rangeX,
                int rangeY)
Creates a point set that can contain points within the given range of values.

Parameters:
rangeX - the maximum x-axis range.
rangeY - the maximum y-axis range.
Method Detail

add

public boolean add(int x,
                   int y)
Adds a point to the set and returns whether the point was already present in the set.

Parameters:
x - the point x-coordinate.
y - the point y-coordinate.
Returns:
true if the point was already present, false if not.

addAll

public void addAll(PointSet set)
Adds all points in the given set to this set.

Parameters:
set - the set containing points to add.

clear

public void clear()
Clears all points from this set.


contains

public boolean contains(int x,
                        int y)
Returns whether this set contains the given point.

Parameters:
x - the point x-coordinate.
y - the point y-coordinate.
Returns:
true if the set contains the point, false if not.

isEmpty

public boolean isEmpty()
Returns whether this set is empty.

Returns:
true if the set is empty, false if not.

iterator

public Iterator<Point> iterator()
Returns an iterator that iterates over the points in this set, returning them as Point objects. Note that the iterator uses a single point object internally, and so callers should create their own copy of the point if they plan to do something fancy with it.

Returns:
the iterator over the set's points.

remove

public boolean remove(int x,
                      int y)
Removes the given point from the set and returns whether the point was present in the set.

Parameters:
x - the point x-coordinate.
y - the point y-coordinate.
Returns:
true if the point was present, false if not.

size

public int size()
Returns the number of points in the set.

Returns:
the number of points.

toString

public String toString()
Overrides:
toString in class Object