com.threerings.tudey.util
Class Coord

java.lang.Object
  extended by com.threerings.tudey.util.Coord
All Implemented Interfaces:
Encodable, Exportable, com.threerings.io.Streamable, Cloneable

public class Coord
extends Object
implements Encodable, com.threerings.io.Streamable, Cloneable

Represents a pair of 2D integer coordinates.


Nested Class Summary
 
Nested classes/interfaces inherited from interface com.threerings.io.Streamable
com.threerings.io.Streamable.Closure
 
Field Summary
static int EMPTY
          A value used to signify an empty coordinate.
 int x
          The coordinates.
 int y
          The coordinates.
 
Constructor Summary
Coord()
          Creates a zero coord.
Coord(Coord other)
          Copy constructor.
Coord(int pair)
          Creates a coord from the supplied encoded coordinate pair.
Coord(int[] values)
          Creates a coord from an array of values.
Coord(int x, int y)
          Creates a coord from two components.
 
Method Summary
 Coord clone()
           
 void decodeFromStream(DataInputStream in)
          Initializes this object with data read from the specified stream.
 void decodeFromString(String string)
          Initializes this object with the contents of the specified string.
static int decodeX(int pair)
          Extracts the x component from the specified encoded coordinate pair.
static int decodeY(int pair)
          Extracts the y component from the specified encoded coordinate pair.
 int encode()
          Returns an encoded version of this coord.
static int encode(int x, int y)
          Encodes the supplied coordinates (presumed to be in [-32768, +32767]) into a single integer.
 void encodeToStream(DataOutputStream out)
          Encodes this object to the specified stream.
 String encodeToString()
          Returns a string representation of this object.
 boolean equals(Object other)
           
 int hashCode()
           
 Coord set(Coord other)
          Copies the elements of another coord.
 Coord set(int pair)
          Sets the fields of the coord to those contained in the supplied encoded coordinate pair.
 Coord set(int[] values)
          Copies the elements of an array.
 Coord set(int x, int y)
          Sets the fields of the coord.
 String toString()
           
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

EMPTY

public static final int EMPTY
A value used to signify an empty coordinate.


x

public int x
The coordinates.


y

public int y
The coordinates.

Constructor Detail

Coord

public Coord(int x,
             int y)
Creates a coord from two components.


Coord

public Coord(int pair)
Creates a coord from the supplied encoded coordinate pair.


Coord

public Coord(int[] values)
Creates a coord from an array of values.


Coord

public Coord(Coord other)
Copy constructor.


Coord

public Coord()
Creates a zero coord.

Method Detail

encode

public static int encode(int x,
                         int y)
Encodes the supplied coordinates (presumed to be in [-32768, +32767]) into a single integer.


decodeX

public static int decodeX(int pair)
Extracts the x component from the specified encoded coordinate pair.


decodeY

public static int decodeY(int pair)
Extracts the y component from the specified encoded coordinate pair.


set

public Coord set(Coord other)
Copies the elements of another coord.

Returns:
a reference to this coord, for chaining.

set

public Coord set(int[] values)
Copies the elements of an array.

Returns:
a reference to this coord, for chaining.

set

public Coord set(int pair)
Sets the fields of the coord to those contained in the supplied encoded coordinate pair.

Returns:
a reference to this coord, for chaining.

set

public Coord set(int x,
                 int y)
Sets the fields of the coord.

Returns:
a reference to this coord, for chaining.

encode

public int encode()
Returns an encoded version of this coord.


encodeToString

public String encodeToString()
Description copied from interface: Encodable
Returns a string representation of this object.

Specified by:
encodeToString in interface Encodable

decodeFromString

public void decodeFromString(String string)
                      throws Exception
Description copied from interface: Encodable
Initializes this object with the contents of the specified string.

Specified by:
decodeFromString in interface Encodable
Throws:
Exception

encodeToStream

public void encodeToStream(DataOutputStream out)
                    throws IOException
Description copied from interface: Encodable
Encodes this object to the specified stream.

Specified by:
encodeToStream in interface Encodable
Throws:
IOException

decodeFromStream

public void decodeFromStream(DataInputStream in)
                      throws IOException
Description copied from interface: Encodable
Initializes this object with data read from the specified stream.

Specified by:
decodeFromStream in interface Encodable
Throws:
IOException

toString

public String toString()
Overrides:
toString in class Object

clone

public Coord clone()
Overrides:
clone in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object other)
Overrides:
equals in class Object


Copyright © 2011. All Rights Reserved.