Package repast.simphony.space
Class Dimensions
java.lang.Object
repast.simphony.space.Dimensions
Encapsulates the dimensions of a space in N dimensions.
- Author:
- Nick Collier
-
Constructor Summary
ConstructorDescriptionDimensions
(double... dimensions) Creates a Dimensions from the specified array.Dimensions
(double[] dimensions, double[] origin) Dimensions
(double[] dimensions, int[] origin) Dimensions
(int... dimensions) Creates a Dimensions from the specified array.Dimensions
(int[] dimensions, int[] origin) -
Method Summary
Modifier and TypeMethodDescriptionboolean
Overrides equals.double
getDepth()
Gets the size of the z dimension.double
getDimension
(int index) Gets the dimension size at the specified index.double
Gets the size of the y dimension.double
getOrigin
(int index) double
getWidth()
Gets the size of the x dimension.int
hashCode()
double[]
originToDoubleArray
(double[] array) Copies the origin into the provided double array.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 provided double array.int[]
toIntArray
(int[] array) Copies the dimension sizes into the provided int array, casting to an int if necessary.toString()
-
Constructor Details
-
Dimensions
public Dimensions(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
-
Dimensions
public Dimensions(int[] dimensions, int[] origin) -
Dimensions
public Dimensions(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
-
Dimensions
public Dimensions(double[] dimensions, double[] origin) -
Dimensions
public Dimensions(double[] dimensions, int[] origin)
-
-
Method Details
-
getWidth
public double getWidth()Gets the size of the x dimension.- Returns:
- the size of the x dimension.
-
getHeight
public double 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 double 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 double 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 double getOrigin(int 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.
-
toDoubleArray
public double[] toDoubleArray(double[] array) Copies the dimension sizes into the provided 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.
-
originToDoubleArray
public double[] originToDoubleArray(double[] array) Copies the origin into the provided double array. 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.
-
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.
-
toString
-
hashCode
public int hashCode() -
equals
Overrides equals. Returns true if the other object is a Dimension whose dimension values are the same as this one.
-