Package repast.simphony.space.grid
Class GridDimensions
- java.lang.Object
-
- repast.simphony.space.grid.GridDimensions
-
public class GridDimensions extends Object
Encapsulates the dimensions of a space in N dimensions.- Author:
- Nick Collier
-
-
Constructor Summary
Constructors Constructor Description GridDimensions(double... dimensions)
Creates a Dimensions from the specified array.GridDimensions(double[] dimensions, double[] origin)
Creates a Dimensions from the specified array.GridDimensions(int... dimensions)
Creates a Dimensions from the specified array.GridDimensions(int[] dimensions, int[] origin)
Creates a Dimensions from the specified array.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object obj)
Overrides equals.int
getDepth()
Gets the size of the z dimension.int
getDimension(int index)
Gets the dimension size at the specified index.int
getHeight()
Gets the size of the y dimension.int
getOrigin(int index)
Gets the origin at the specified index.int
getWidth()
Gets the size of the x dimension.int
hashCode()
int[]
originToIntArray(int[] array)
Copies the origin into the provided int array, casting to an int if necessary.int
size()
Gets the number of dimensions in this Dimensions.double[]
toDoubleArray(double[] array)
Copies the dimension sizes into the provied double array.int[]
toIntArray(int[] array)
Copies the dimension sizes into the provided int array, casting to an int if necessary.String
toString()
-
-
-
Constructor Detail
-
GridDimensions
public GridDimensions(int... dimensions)
Creates a Dimensions from the specified array. The first element in the array will be the size in the x dimension, the second the size in the y dimension and so on.- Parameters:
dimensions
- the dimension values
-
GridDimensions
public GridDimensions(int[] dimensions, int[] origin)
Creates a Dimensions from the specified array. The first element in the array will be the size in the x dimension, the second the size in the y dimension and so on.- Parameters:
dimensions
- the dimension valuesorigin
- the origin values
-
GridDimensions
public GridDimensions(double... dimensions)
Creates a Dimensions from the specified array. The first element in the array will be the size in the x dimension, the second the size in the y dimension and so on.- Parameters:
dimensions
- the dimension values
-
GridDimensions
public GridDimensions(double[] dimensions, double[] origin)
Creates a Dimensions from the specified array. The first element in the array will be the size in the x dimension, the second the size in the y dimension and so on.- Parameters:
dimensions
- the dimension valuesorigin
- the origin values
-
-
Method Detail
-
getWidth
public int getWidth()
Gets the size of the x dimension.- Returns:
- the size of the x dimension.
-
getHeight
public int getHeight()
Gets the size of the y dimension.- Returns:
- the size of the y dimension.
- Throws:
ArrayIndexOutOfBoundsException
- if the number of dimensions encapsulated by this Dimensions object is < 2.
-
getDepth
public int getDepth()
Gets the size of the z dimension.- Returns:
- the size of the z dimension.
- Throws:
ArrayIndexOutOfBoundsException
- if the number of dimensions encapsulated by this Dimensions object is < 3.
-
getDimension
public int getDimension(int index)
Gets the dimension size at the specified index. The x coordinate is at index 0, y at 1, z at 2 and so on.- Parameters:
index
- the index of the dimension- Returns:
- the dimension size at the specified index.
- Throws:
ArrayIndexOutOfBoundsException
- if the number of dimensions encapsulated by this Dimensions object is less than specified index.
-
getOrigin
public int getOrigin(int index)
Gets the origin at the specified index. The x coordinate is at index 0, y at 1, z at 2 and so on.- Parameters:
index
- the index of the dimension- Returns:
- the origin at the specified index.
- Throws:
ArrayIndexOutOfBoundsException
- if the number of dimensions encapsulated by this Dimensions object is less than specified index.
-
size
public int size()
Gets the number of dimensions in this Dimensions.- Returns:
- the number of dimensions in this Dimensions.
-
toIntArray
public int[] toIntArray(int[] array)
Copies the dimension sizes into the provided int array, casting to an int if necessary. If the array is null, a new one is created and returned.- Parameters:
array
- the array to put the dimension sizes in. If the array is null, a new one is created and returned.- Returns:
- an array containing the dimension sizes.
- Throws:
ArrayIndexOutOfBoundsException
- if the passed in array is not the correct length.
-
originToIntArray
public int[] originToIntArray(int[] array)
Copies the origin into the provided int array, casting to an int if necessary. If the array is null, a new one is created and returned.- Parameters:
array
- the array to put the origin in. If the array is null, a new one is created and returned.- Returns:
- an array containing the origin.
- Throws:
ArrayIndexOutOfBoundsException
- if the passed in array is not the correct length.
-
toDoubleArray
public double[] toDoubleArray(double[] array)
Copies the dimension sizes into the provied double array. If the array is null, a new one is created and returned.- Parameters:
array
- the array to put the dimension sizes in. If the array is null, a new one is created and returned.- Returns:
- an array containing the dimension sizes.
- Throws:
ArrayIndexOutOfBoundsException
- if the passed in array is not the correct length.
-
equals
public boolean equals(Object obj)
Overrides equals. Returns true if the other object is a Dimension whose dimension values are the same as this one.
-
-