com.threerings.tudey.util
Class CoordSet

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractSet<Coord>
          extended by com.threerings.tudey.util.CoordSet
All Implemented Interfaces:
Iterable<Coord>, Collection<Coord>, Set<Coord>

public class CoordSet
extends AbstractSet<Coord>

Contains a set of encoded coordinates.


Constructor Summary
CoordSet()
          Creates an empty coord set.
CoordSet(Collection<Coord> collection)
          Creates a coord set containing the contents of the supplied collection.
CoordSet(int x, int y, int width, int height)
          Creates a coord set containing all of the coordinates in the supplied region.
CoordSet(Rectangle region)
          Creates a coord set containing all of the coordinates in the supplied region.
 
Method Summary
 boolean add(Coord coord)
           
 boolean add(int x, int y)
          Adds the specified coordinates to the set.
 boolean addAll(int x, int y, int width, int height)
          Adds all of the coordinates in the specified region.
 boolean addAll(Rectangle region)
          Adds all of the coordinates in the specified region.
 boolean contains(int x, int y)
          Determines whether the set contains the specified coordinates.
 boolean contains(Object object)
           
 boolean containsAll(int x, int y, int width, int height)
          Determines whether the set contains all of the coordinates in the specified region.
 boolean containsAll(Rectangle region)
          Determines whether the set contains all of the coordinates in the specified region.
 CoordSet getBorder()
          Creates a new set containing the coordinates that border the coordinates in this set.
 CoordSet getBorder(CoordSet result)
          Adds the coordinates that border the coordinates in this set to the provided set.
 CoordSet getCardinalBorder()
          Creates a new set containing the coordinates that border the coordinates in this set in the cardinal directions.
 CoordSet getCardinalBorder(CoordSet result)
          Adds the coordinates that border the coordinates in this set in cardinal directions to the set provided.
 Rectangle getLargestRegion(Rectangle result)
          Finds the largest covered region of this set and stores it in the provided rectangle.
 Iterator<Coord> iterator()
           
 Coord pickRandom()
          Selects and returns a random coordinate from the set.
 Coord pickRandom(Coord result)
          Selects a random coordinate from the set and places it in the provided object.
 Coord pickRandom(int width, int height)
          Selects a random coordinate that is the origin of a region within the set with the supplied dimensions.
 Coord pickRandom(int width, int height, Coord result)
          Selects a random coordinate that is the origin of a region within the set with the supplied dimensions and places it in the provided object.
 boolean remove(int x, int y)
          Removes the specified coordinates from the set.
 boolean remove(Object object)
           
 boolean removeAll(int x, int y, int width, int height)
          Removes all of the coordinates in the specified region.
 boolean removeAll(Rectangle region)
          Removes all of the coordinates in the specified region.
 int size()
           
 
Methods inherited from class java.util.AbstractSet
equals, hashCode, removeAll
 
Methods inherited from class java.util.AbstractCollection
addAll, clear, containsAll, isEmpty, retainAll, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Set
addAll, clear, containsAll, isEmpty, retainAll, toArray, toArray
 

Constructor Detail

CoordSet

public CoordSet(Collection<Coord> collection)
Creates a coord set containing the contents of the supplied collection.


CoordSet

public CoordSet(Rectangle region)
Creates a coord set containing all of the coordinates in the supplied region.


CoordSet

public CoordSet(int x,
                int y,
                int width,
                int height)
Creates a coord set containing all of the coordinates in the supplied region.


CoordSet

public CoordSet()
Creates an empty coord set.

Method Detail

addAll

public boolean addAll(Rectangle region)
Adds all of the coordinates in the specified region.

Returns:
whether or not the set changed as a result of the addition.

addAll

public boolean addAll(int x,
                      int y,
                      int width,
                      int height)
Adds all of the coordinates in the specified region.

Returns:
whether or not the set changed as a result of the addition.

add

public boolean add(int x,
                   int y)
Adds the specified coordinates to the set.

Returns:
whether or not the set changed as a result of the addition.

removeAll

public boolean removeAll(Rectangle region)
Removes all of the coordinates in the specified region.

Returns:
whether or not the set changed as a result of the removal.

removeAll

public boolean removeAll(int x,
                         int y,
                         int width,
                         int height)
Removes all of the coordinates in the specified region.

Returns:
whether or not the set changed as a result of the removal.

remove

public boolean remove(int x,
                      int y)
Removes the specified coordinates from the set.

Returns:
whether or not the set changed as a result of the removal.

containsAll

public boolean containsAll(Rectangle region)
Determines whether the set contains all of the coordinates in the specified region.


containsAll

public boolean containsAll(int x,
                           int y,
                           int width,
                           int height)
Determines whether the set contains all of the coordinates in the specified region.


contains

public boolean contains(int x,
                        int y)
Determines whether the set contains the specified coordinates.


pickRandom

public Coord pickRandom()
Selects and returns a random coordinate from the set.

Returns:
a new object containing the result.

pickRandom

public Coord pickRandom(Coord result)
Selects a random coordinate from the set and places it in the provided object.

Returns:
a reference to the result object, for chaining.

pickRandom

public Coord pickRandom(int width,
                        int height)
Selects a random coordinate that is the origin of a region within the set with the supplied dimensions.

Returns:
a new object containing the result.

pickRandom

public Coord pickRandom(int width,
                        int height,
                        Coord result)
Selects a random coordinate that is the origin of a region within the set with the supplied dimensions and places it in the provided object.

Returns:
a reference to the result object, for chaining.

getLargestRegion

public Rectangle getLargestRegion(Rectangle result)
Finds the largest covered region of this set and stores it in the provided rectangle.


getBorder

public CoordSet getBorder()
Creates a new set containing the coordinates that border the coordinates in this set.


getBorder

public CoordSet getBorder(CoordSet result)
Adds the coordinates that border the coordinates in this set to the provided set.

Returns:
a reference to the result set, for chaining.

getCardinalBorder

public CoordSet getCardinalBorder()
Creates a new set containing the coordinates that border the coordinates in this set in the cardinal directions.


getCardinalBorder

public CoordSet getCardinalBorder(CoordSet result)
Adds the coordinates that border the coordinates in this set in cardinal directions to the set provided.

Returns:
a reference to the result set, for chaining.

add

public boolean add(Coord coord)
Specified by:
add in interface Collection<Coord>
Specified by:
add in interface Set<Coord>
Overrides:
add in class AbstractCollection<Coord>

remove

public boolean remove(Object object)
Specified by:
remove in interface Collection<Coord>
Specified by:
remove in interface Set<Coord>
Overrides:
remove in class AbstractCollection<Coord>

contains

public boolean contains(Object object)
Specified by:
contains in interface Collection<Coord>
Specified by:
contains in interface Set<Coord>
Overrides:
contains in class AbstractCollection<Coord>

size

public int size()
Specified by:
size in interface Collection<Coord>
Specified by:
size in interface Set<Coord>
Specified by:
size in class AbstractCollection<Coord>

iterator

public Iterator<Coord> iterator()
Specified by:
iterator in interface Iterable<Coord>
Specified by:
iterator in interface Collection<Coord>
Specified by:
iterator in interface Set<Coord>
Specified by:
iterator in class AbstractCollection<Coord>


Copyright © 2011. All Rights Reserved.