org.gjt.universe
Class Coord

java.lang.Object
  |
  +--org.gjt.universe.Coord
All Implemented Interfaces:
java.lang.Cloneable, java.io.Serializable

public final class Coord
extends java.lang.Object
implements java.io.Serializable, java.lang.Cloneable

Encapsulates a cartesian three-space coordinate. Note that this class intentionally limits the precision of coordinates to the hundreth's position in order to simplify intersection and coincidence testing.

This class is used in many other classes within Universe and should only be altered carefully.

See Also:
GalaxyBase, Serialized Form

Field Summary
static int ALPHA_QUADRANT
           
static int BETA_QUADRANT
           
static int DELTA_QUADRANT
           
static int GAMMA_QUADRANT
           
private static java.text.NumberFormat ourNumberFormat
           
private static java.util.Random ourRandGen
           
private static Coord ourZero
           
private  float x
           
private  float y
           
private  float z
           
 
Constructor Summary
Coord()
          This constructor returns a new instance of the coordinate (0, 0, 0).
Coord(Coord src)
          This constructor returns an exact copy of the supplied object.
Coord(float in_x, float in_y, float in_z)
          The designated constructor; returns a new instance with the given 3-space cartesian coordinates.
 
Method Summary
 java.lang.Object clone()
          Returns an exact copy of this object.
 float distance(Coord other)
          Computes and returns the distance between two coords.
 boolean equals(java.lang.Object obj)
          This method returns true if the given object is a coordinate equivalent to the receiver and false otherwise.
 float getComponent(int index)
          Returns a single component for the coordinate, as indicated by the supplied index (0=x, 1=y, all others=z).
 int getQuadrant()
          This method returns the quadrant of the receiving coordinate relative to 0,0,0.
 float getX()
          Returns the x component of the coordinate.
 float getY()
          Returns the y component of the coordinate.
 float getZ()
          Returns the z component of the coordinate.
 int hashCode()
          This method returns a hash code value which can be used by Hashtable objects.
 boolean isInRange(Coord other, float range)
          Checks whether this coord is within a certain range of another
 Coord randomCoordInRadius(float maxRadius)
          This method returns a new random coordinate up to the given radius from the receiver.
 Coord randomCoordInShell(float minRadius, float maxRadius)
          This method returns a new random coordinate within the shell around the receiver defined by the two given radii.
 Coord randomCoordInSpheroid(Coord axes)
          This method returns a new random coordinate within the spheroid centered around the receiver and having axis lengths corresponding to the given coordinate.
 Coord set(float in_x, float in_y, float in_z)
          This method sets the receiver's cartesian 3-space coordinates to the indicated values.
 Coord setX(float in_x)
          Changes the x component of the coordinate.
 Coord setY(float in_y)
          Changes the y component of the coordinate.
 Coord setZ(float in_z)
          Changes the z component of the coordinate.
 java.lang.String toString()
          This method returns a string equivalent to the coordinate using the format: x, y, z.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

ALPHA_QUADRANT

public static final int ALPHA_QUADRANT
See Also:
Constant Field Values

BETA_QUADRANT

public static final int BETA_QUADRANT
See Also:
Constant Field Values

GAMMA_QUADRANT

public static final int GAMMA_QUADRANT
See Also:
Constant Field Values

DELTA_QUADRANT

public static final int DELTA_QUADRANT
See Also:
Constant Field Values

x

private float x

y

private float y

z

private float z

ourRandGen

private static java.util.Random ourRandGen

ourZero

private static Coord ourZero

ourNumberFormat

private static java.text.NumberFormat ourNumberFormat
Constructor Detail

Coord

public Coord()
This constructor returns a new instance of the coordinate (0, 0, 0).


Coord

public Coord(Coord src)
This constructor returns an exact copy of the supplied object.

Parameters:
src - The coordinate to be copied.

Coord

public Coord(float in_x,
             float in_y,
             float in_z)
The designated constructor; returns a new instance with the given 3-space cartesian coordinates. Not that the given values will be rounded to the nearest hundredth.

Method Detail

clone

public java.lang.Object clone()
Returns an exact copy of this object.

Overrides:
clone in class java.lang.Object

set

public Coord set(float in_x,
                 float in_y,
                 float in_z)
This method sets the receiver's cartesian 3-space coordinates to the indicated values. The method returns the changed Coordinate to facilitate further calculations.


getX

public float getX()
Returns the x component of the coordinate.


getY

public float getY()
Returns the y component of the coordinate.


getZ

public float getZ()
Returns the z component of the coordinate.


getComponent

public float getComponent(int index)
Returns a single component for the coordinate, as indicated by the supplied index (0=x, 1=y, all others=z).

Parameters:
index - The index of the desired component.

setX

public Coord setX(float in_x)
Changes the x component of the coordinate. The method returns the changed Coordinate to facilitate further calculations.


setY

public Coord setY(float in_y)
Changes the y component of the coordinate. The method returns the changed Coordinate to facilitate further calculations.


setZ

public Coord setZ(float in_z)
Changes the z component of the coordinate. The method returns the changed Coordinate to facilitate further calculations.


getQuadrant

public int getQuadrant()
This method returns the quadrant of the receiving coordinate relative to 0,0,0. alpha quadrant = +x, +y beta quadrant = +x, -y gamma quadrant = -x, +y delta quadrant = -x, -y Note: X coordinates on the line that is y=0 are in the beta quadrant. Y coordinates on the line that is x=0 are in the delta quadrant.


distance

public float distance(Coord other)
Computes and returns the distance between two coords.


isInRange

public boolean isInRange(Coord other,
                         float range)
Checks whether this coord is within a certain range of another


toString

public java.lang.String toString()
This method returns a string equivalent to the coordinate using the format: x, y, z. Only 2 post decimal digits will be shown for each component. If more precision is is required, then the caller should handle presentation of each component directly.

Overrides:
toString in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
This method returns true if the given object is a coordinate equivalent to the receiver and false otherwise. Two coordinates are considered the same by this test if they less than 0.001 from each other.

Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
This method returns a hash code value which can be used by Hashtable objects. Two coord objects which are equal will always return the same hash value (although others which are not may also do so).

Overrides:
hashCode in class java.lang.Object

randomCoordInRadius

public Coord randomCoordInRadius(float maxRadius)
This method returns a new random coordinate up to the given radius from the receiver.


randomCoordInShell

public Coord randomCoordInShell(float minRadius,
                                float maxRadius)
This method returns a new random coordinate within the shell around the receiver defined by the two given radii.

Parameters:
minRadius - The minimum distance the returned coordinate should be from the receiver.
maxRadius - The maximum distance the returned coordinate should be from the receiver.

randomCoordInSpheroid

public Coord randomCoordInSpheroid(Coord axes)
This method returns a new random coordinate within the spheroid centered around the receiver and having axis lengths corresponding to the given coordinate.

Parameters:
axes - Coord containing desired axial distances in each direction.


Copyright © 2001 Universe Dev Team All Rights Reserved.