# Class GridExtent

Object
GridExtent

All Implemented Interfaces:
  `Serializable`, `LenientComparable`

public class GridExtent extends Object implements Serializable, LenientComparable
A range of grid coverage coordinates, also known as "grid envelope". `GridExtent` are defined by low coordinates (often all zeros) and high coordinates, inclusive. For example, a grid with a width of 512 cells can have a low coordinate of 0 and high coordinate of 511.
Note: The inclusiveness of high coordinates come from ISO 19123. We follow this specification for all getters methods, but developers should keep in mind that this is the opposite of Java2D usage where `Rectangle` maximal values are exclusive.

`GridExtent` instances are immutable and thread-safe. The same instance can be shared by different `GridGeometry` instances.

Upcoming API generalization: this class may implement the `GridEnvelope` interface in a future Apache SIS version. This is pending GeoAPI update.

Since:
  1.0
See Also:
  - Serialized Form

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `GridExtent(long width, long height)`
  Creates a new grid extent for an image or matrix of the given size.
  `GridExtent(Rectangle bounds)`
  Creates a new grid extent for an image or matrix of the given bounds.
  `GridExtent(GridExtent lower, GridExtent upper)`
  Creates a new grid extent as the concatenation of the two specified grid extent.
  `GridExtent(DimensionNameType[] axisTypes, long[] low, long[] high, boolean isHighIncluded)`
  Constructs a new grid extent set to the specified coordinates.
  `GridExtent(DimensionNameType axisType, long low, long high, boolean isHighIncluded)`
  Constructs a one-dimensional grid extent set to the specified coordinates.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `boolean`
  `contains(long... cell)`
  Returns `true` if this extent contains the given coordinates of a grid cell.
  `boolean`
  `contains(GridExtent other)`
  Returns whether this extent contains the given extent.
  `final boolean`
  `equals(Object object)`
  Compares the specified object with this grid extent for equality.
  `boolean`
  `equals(Object object, ComparisonMode mode)`
  Compares the specified object with this grid extent for equality.
  `GridExtent`
  `expand(long... margins)`
  Returns a grid extent expanded by the given number of cells on both sides along each dimension.
  `Optional<DimensionNameType>`
  `getAxisType(int index)`
  Returns the type (vertical, temporal, …) of grid axis at given dimension.
  `int`
  `getDegreesOfFreedom()`
  Returns the number of dimensions where this grid extent has a size greater than 1.
  `final int`
  `getDimension()`
  Returns the number of dimensions.
  `long`
  `getHigh(int index)`
  Returns the valid maximum inclusive grid coordinate along the specified dimension.
  `int[]`
  `getLargestDimensions(int numDim)`
  Returns the indices of the `numDim` dimensions having the largest sizes.
  `long`
  `getLow(int index)`
  Returns the valid minimum inclusive grid coordinate along the specified dimension.
  `long`
  `getMedian(int index)`
  Returns the average of low and high coordinates, rounded toward positive infinity.
  `double[]`
  `getPointOfInterest(PixelInCell anchor)`
  Returns the grid coordinates of a representative point.
  `long`
  `getRelative(int index, double ratio)`
  Returns a grid coordinate at the given relative position between low and high.
  `long`
  `getSize(int index)`
  Returns the number of integer grid coordinates along the specified dimension.
  `double`
  `getSize(int index, boolean minusOne)`
  Returns the number of grid coordinates as a double precision floating point value.
  `SortedMap<Integer,Long>`
  `getSliceCoordinates()`
  Returns the grid coordinates for all dimensions where the grid has a size of 1.
  `int[]`
  `getSubspaceDimensions(int numDim)`
  Returns indices of all dimensions where this grid extent has a size greater than 1.
  `int`
  `hashCode()`
  Returns a hash value for this grid extent.
  `GridExtent`
  `insertDimension(int index, DimensionNameType axisType, long low, long high, boolean isHighIncluded)`
  Returns a new grid extent with the specified dimension inserted at the given index in this grid extent.
  `GridExtent`
  `intersect(GridExtent other)`
  Returns the intersection of this grid extent with the given grid extent.
  `boolean`
  `intersects(GridExtent other)`
  Returns whether this extent intersects the given extent.
  `GridExtent`
  `resize(long... sizes)`
  Sets the size of grid extent to the given values by moving low and high coordinates.
  `GridExtent`
  `selectDimensions(int... indices)`
  Returns a grid extent that encompass only some dimensions of this grid extent.
  `boolean`
  `startsAtZero()`
  Returns `true` if all low coordinates are zero.
  `GridExtent`
  `subsample(int[] periods)`
  Deprecated.
  Use the version with `long` integers instead of `int`.
  `GridExtent`
  `subsample(long... periods)`
  Creates a new grid extent subsampled by the given number of cells along each grid dimensions.
  `GeneralEnvelope`
  `toEnvelope(MathTransform cornerToCRS)`
  Transforms this grid extent to a "real world" envelope using the given transform.
  `String`
  `toString()`
  Returns a string representation of this grid extent.
  `final GridExtent`
  `translate(long... translation)`
  Returns an extent translated by the given number of cells compared to this extent.
  `GridExtent`
  `translate(long[] translation, boolean negate)`
  Returns an extent translated by the given number of cells, optionally in the reverse direction.
  `static Optional<DimensionNameType>`
  `typeFromAxis(CoordinateSystemAxis axis)`
  Suggests a grid dimension name for the given coordinate system axis.
  `GridExtent`
  `union(GridExtent other)`
  Returns the union of this grid extent with the given grid extent.
  `GridExtent`
  `upsample(int[] periods)`
  Deprecated.
  Use the version with `long` integers instead of `int`.
  `GridExtent`
  `upsample(long... periods)`
  Creates a new grid extent upsampled by the given number of cells along each grid dimensions.
  `GridExtent`
  `withRange(int index, long low, long high)`
  Returns a grid extent identical to this grid extent except for the coordinate values in the specified dimension.

  ### Methods inherited from class Object

  `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- ## Constructor Details

  - ### GridExtent

    public GridExtent(Rectangle bounds)
    Creates a new grid extent for an image or matrix of the given bounds. The axis types are `DimensionNameType​.COLUMN` and `ROW` in that order.
    Parameters:
      `bounds` - the bounds to copy in the new grid extent.
    Throws:
      `IllegalArgumentException` - if the rectangle is empty.
    Since:
      1.1

  - ### GridExtent

    public GridExtent(long width, long height)
    Creates a new grid extent for an image or matrix of the given size. The low grid coordinates are zeros and the axis types are `DimensionNameType​.COLUMN` and `ROW` in that order.
    Parameters:
      `width` - number of pixels in each row.
      `height` - number of pixels in each column.
    Throws:
      `IllegalArgumentException` - if the width or the height is not greater than zero.

  - ### GridExtent

    public GridExtent(DimensionNameType axisType, long low, long high, boolean isHighIncluded)
    Constructs a one-dimensional grid extent set to the specified coordinates. This convenience constructor does the same work as the constructor for the general case. It is provided as a convenience for appending a single dimension to an existing grid.
    Parameters:
      `axisType` - the type of the grid axis, or `null` if unspecified.
      `low` - the valid minimum grid coordinate, always inclusive.
      `high` - the valid maximum grid coordinate, inclusive or exclusive depending on the next argument.
      `isHighIncluded` - `true` if the `high` value is inclusive (as in ISO 19123 specification), or `false` if it is exclusive (as in Java2D usage).
    Throws:
      `IllegalArgumentException` - if `low` is greater than `high`.
    Since:
      1.5

  - ### GridExtent

    public GridExtent(DimensionNameType[] axisTypes, long[] low, long[] high, boolean isHighIncluded)
    Constructs a new grid extent set to the specified coordinates. The given arrays contain a minimum (inclusive) and maximum value for each dimension of the grid coverage. The lowest valid grid coordinates are often zero, but this is not mandatory. As a convenience for this common case, a null `low` array means that all low coordinates are zero.

    An optional (nullable) `axisTypes` argument can be used for attaching a label to each grid axis. For example if this `GridExtent` is four-dimensional, then the axis types may be {column (x), row (y), vertical (z), time (t)}, which means that the last axis is for the temporal dimension, the third axis is for the vertical dimension, etc. This information is related to the "real world" coordinate reference system axes, but not necessarily in the same order; it is caller responsibility to ensure that the grid axes are consistent with the CRS axes. The `axisTypes` array shall not contain duplicated elements, but may contain `null` elements if the type of some axes are unknown.

    Parameters:
      `axisTypes` - the type of each grid axis, or `null` if unspecified.
      `low` - the valid minimum grid coordinates (always inclusive), or `null` for all zeros.
      `high` - the valid maximum grid coordinates, inclusive or exclusive depending on the next argument.
      `isHighIncluded` - `true` if the `high` values are inclusive (as in ISO 19123 specification), or `false` if they are exclusive (as in Java2D usage). This argument does not apply to `low` values, which are always inclusive.
    Throws:
      `IllegalArgumentException` - if a coordinate value in the low part is greater than the corresponding coordinate value in the high part.
    See Also:
      - `getLow()`
      - `getHigh()`
      - `insertDimension(int, DimensionNameType, long, long, boolean)`

  - ### GridExtent

    public GridExtent(GridExtent lower, GridExtent upper)
    Creates a new grid extent as the concatenation of the two specified grid extent. The number of dimensions of the new extent is the sum of the number of dimensions of the two specified extents. The dimensions of the lower extent are first, followed by the dimensions of the upper extent.
    Parameters:
      `lower` - the grid extent providing the lowest dimensions.
      `upper` - the grid extent providing the highest dimensions.
    Throws:
      `IllegalArgumentException` - if the concatenation results in duplicated axis types.
    Since:
      1.5

- ## Method Details

  - ### typeFromAxis

    public static Optional<DimensionNameType> typeFromAxis(CoordinateSystemAxis axis)
    Suggests a grid dimension name for the given coordinate system axis. Note that grid axes are not necessarily in the same order as CRS axes. This method may be used when the caller knows which CRS axis will be associated to a grid axis.
    Parameters:
      `axis` - the coordinate system axis for which to get a suggested grid dimension name.
    Returns:
      suggested grid dimension for the given CRS axis.
    Since:
      1.5

  - ### getDimension

    public final int getDimension()
    Returns the number of dimensions.
    Returns:
      the number of dimensions.
    See Also:
      - `selectDimensions(int[])`

  - ### getDegreesOfFreedom

    public int getDegreesOfFreedom()
    Returns the number of dimensions where this grid extent has a size greater than 1. This is a value between 0 and `getDimension()` inclusive.
    Returns:
      the number of dimensions where this grid extent has a size greater than 1.
    Since:
      1.5
    See Also:
      - `getSubspaceDimensions(int)`

  - ### startsAtZero

    public boolean startsAtZero()
    Returns `true` if all low coordinates are zero. This is a very common case since many grids start their cell numbering at zero.
    Returns:
      whether all low coordinates are zero.
    See Also:
      - `translate(long...)`

  - ### getLow

    public long getLow(int index)
    Returns the valid minimum inclusive grid coordinate along the specified dimension.
    Parameters:
      `index` - the dimension for which to obtain the coordinate value.
    Returns:
      the low coordinate value at the given dimension, inclusive.
    Throws:
      `IndexOutOfBoundsException` - if the given index is negative or is equal or greater than the grid dimension.
    See Also:
      - `getHigh(int)`
      - `withRange(int, long, long)`

  - ### getHigh

    public long getHigh(int index)
    Returns the valid maximum inclusive grid coordinate along the specified dimension.
    Parameters:
      `index` - the dimension for which to obtain the coordinate value.
    Returns:
      the high coordinate value at the given dimension, inclusive.
    Throws:
      `IndexOutOfBoundsException` - if the given index is negative or is equal or greater than the grid dimension.
    See Also:
      - `getLow(int)`
      - `withRange(int, long, long)`

  - ### getMedian

    public long getMedian(int index)
    Returns the average of low and high coordinates, rounded toward positive infinity. This method is equivalent to computing any of the following, except that this method does not overflow even if the sum would overflow:
    - (low + high) / 2 rounded toward positive infinity, or
    - (low + high + 1) / 2 rounded toward negative infinity.
    The two above formulas are equivalent, so the result does not depend on whether the high coordinate should be inclusive or exclusive.
    Parameters:
      `index` - the dimension for which to obtain the coordinate value.
    Returns:
      the median coordinate value at the given dimension.
    Throws:
      `IndexOutOfBoundsException` - if the given index is negative or is equal or greater than the grid dimension.
    Since:
      1.3

  - ### getRelative

    public long getRelative(int index, double ratio)
    Returns a grid coordinate at the given relative position between low and high. The relative position is specified by a ratio between 0 and 1 where 0 maps to low grid coordinates, 1 maps to high grid coordinates and 0.5 maps to median grid coordinates. Ratio values outside the [0 … 1] range result in extrapolations.
    Parameters:
      `index` - the dimension for which to obtain the interpolated coordinate.
      `ratio` - interpolation ratio (0 for low, 0.5 for median, 1 for high coordinate).
    Returns:
      the interpolated coordinate value in the given dimension.
    Throws:
      `IndexOutOfBoundsException` - if the given index is negative or is equal or greater than the grid dimension.
      `ArithmeticException` - if the extrapolated coordinate cannot be represented as a 64 bits integer.
    Since:
      1.4

  - ### getSize

    public long getSize(int index)
    Returns the number of integer grid coordinates along the specified dimension. This is equal to `getHigh(dimension) - getLow(dimension) + 1`.
    Parameters:
      `index` - the dimension for which to obtain the size.
    Returns:
      the number of cells along the given dimension.
    Throws:
      `IndexOutOfBoundsException` - if the given index is negative or is equal or greater than the grid dimension.
      `ArithmeticException` - if the size is too large for the `long` primitive type.
    See Also:
      - `getLow(int)`
      - `getHigh(int)`
      - `resize(long...)`

  - ### getSize

    public double getSize(int index, boolean minusOne)
    Returns the number of grid coordinates as a double precision floating point value. Invoking this method is equivalent to invoking `getSize(int)` and converting the result from `long` to the `double` primitive type, except that this method does not overflow (i.e. does not throw `ArithmeticException`).
    Parameters:
      `index` - the dimension for which to obtain the size.
      `minusOne` - `true` for returning size−1 instead of size.
    Returns:
      the number of cells along the given dimension, optionally minus one.

  - ### getPointOfInterest

    public double[] getPointOfInterest(PixelInCell anchor)
    Returns the grid coordinates of a representative point. This point may be used for estimating a grid resolution. The default implementation returns the median (or center) coordinates of this grid extent, but subclasses can override this method if another point is considered more representative.

    The `anchor` argument tells which transform the caller intends to use for converting the grid coordinates to "real world" coordinates. With the default implementation, the coordinate values returned with `CELL_CORNER` are 0.5 cell units higher than the coordinate values returned with `CELL_CENTER`. Subclasses are free to ignore this argument.

    Parameters:
      `anchor` - the convention to be used for conversion to "real world" coordinates.
    Returns:
      the grid coordinates of a representative point.
    Since:
      1.3

  - ### getSliceCoordinates

    public SortedMap<Integer,Long> getSliceCoordinates()
    Returns the grid coordinates for all dimensions where the grid has a size of 1. Keys are dimensions as values from 0 inclusive to `getDimension()` exclusive. Values are the low and high coordinates (which are equal) in the associated dimension.
    Returns:
      grid coordinates for all dimensions where the grid has a size of 1.
    Since:
      1.3
    See Also:
      - `GridCoverage​.Evaluator​.setDefaultSlice(Map)`

  - ### getSubspaceDimensions

    public int[] getSubspaceDimensions(int numDim)
    Returns indices of all dimensions where this grid extent has a size greater than 1. This method can be used for getting the grid extent of a slice with `numDim` dimensions from a n-dimensional cube where `numDim` ≤ n.

    #### Example

    suppose that we want to get a two-dimensional slice (y,z) in a four-dimensional data cube (x,y,z,t). The first step is to specify the x and t coordinates of the slice. In this example we set x to 5 and t to 8.

        GridGeometry grid = ...;             // Geometry of the (x,y,z,t) grid.
        GridGeometry slice4D = grid.slice(new GeneralDirectPosition(5, NaN, NaN, 8));

    Above code created a slice at the requested position, but that slice still have 4 dimensions. It is a "slice" because the x and t dimensions of `slice4D` have only one cell. If a two-dimensional slice is desired, then above operations can be completed as below. In this example, the result of `getSubspaceDimensions(2)` call will be {1,2}.

        int[]  subDimensions = slice4D.getExtent().getSubspaceDimensions(2);
        GridGeometry slice2D = slice4D.selectDimensions(subDimensions);

    Note that in this example, it would have been more efficient to execute `grid​.selectDimensions(1,2)` directly. This `getSubspaceDimensions(int)` method is more useful for inferring a `slice2D` from a `slice4D` which has been created elsewhere, or when we do not really want the `slice2D` but only its dimension indices.

    #### Number of dimensions

    This method returns exactly `numDim` indices. If there is more than `numDim` dimensions having a size greater than 1, then a `SubspaceNotSpecifiedException` is thrown. If there is less than `numDim` dimensions having a size greater than 1, then the returned list of dimensions is completed with some dimensions of size 1, starting with the first dimensions in this grid extent, until there is exactly `numDim` dimensions. If this grid extent does not have at least `numDim` dimensions, then a `CannotEvaluateException` is thrown.
    Parameters:
      `numDim` - number of dimensions of the sub-space.
    Returns:
      indices of sub-space dimensions, in increasing order in an array of length `numDim`.
    Throws:
      `SubspaceNotSpecifiedException` - if there is more than `numDim` dimensions having a size greater than 1.
      `CannotEvaluateException` - if this grid extent does not have at least `numDim` dimensions.
    See Also:
      - `getDegreesOfFreedom()`

  - ### getLargestDimensions

    public int[] getLargestDimensions(int numDim)
    Returns the indices of the `numDim` dimensions having the largest sizes. This method can be used as an alternative to `getSubspaceDimensions(int)` when it is acceptable that the omitted dimensions have sizes larger than 1 cell.
    Parameters:
      `numDim` - number of dimensions of the sub-space.
    Returns:
      indices of the `numDim` dimensions having the largest sizes, in increasing order.
    Throws:
      `CannotEvaluateException` - if this grid extent does not have at least `numDim` dimensions.
    Since:
      1.4

  - ### getAxisType

    public Optional<DimensionNameType> getAxisType(int index)
    Returns the type (vertical, temporal, …) of grid axis at given dimension. This information is provided because the grid axis type cannot always be inferred from the context. Some examples are:
    - `getAxisType(0)` may return `DimensionNameType​.COLUMN`, `TRACK` or `LINE`.
    - `getAxisType(1)` may return `DimensionNameType​.ROW`, `CROSS_TRACK` or `SAMPLE`.
    - `getAxisType(2)` may return `DimensionNameType​.VERTICAL`.
    - `getAxisType(3)` may return `DimensionNameType​.TIME`.
    Above are only examples; there are no constraints on axis order. In particular grid axes do not need to be in the same order than the corresponding coordinate reference system axes.
    Parameters:
      `index` - the dimension for which to obtain the axis type.
    Returns:
      the axis type at the given dimension. May be absent if the type is unknown.
    Throws:
      `IndexOutOfBoundsException` - if the given index is negative or is equal or greater than the grid dimension.

  - ### withRange

    public GridExtent withRange(int index, long low, long high)
    Returns a grid extent identical to this grid extent except for the coordinate values in the specified dimension. This grid extent is not modified.
    Parameters:
      `index` - the dimension for which to set the coordinate values.
      `low` - the low coordinate value at the given dimension, inclusive.
      `high` - the high coordinate value at the given dimension, inclusive.
    Returns:
      a grid extent with the specified coordinate values, or `this` if values are unchanged.
    Throws:
      `IllegalArgumentException` - if the low coordinate value is greater than the high coordinate value.
    Since:
      1.3
    See Also:
      - `getLow(int)`
      - `getHigh(int)`

  - ### toEnvelope

    public GeneralEnvelope toEnvelope(MathTransform cornerToCRS) throws TransformException
    Transforms this grid extent to a "real world" envelope using the given transform. The given transform shall map cell corners to real world coordinates.
    Parameters:
      `cornerToCRS` - a transform from cell corners to real world coordinates.
    Returns:
      this grid extent in real world coordinates. Upper coordinate values are exclusive.
    Throws:
      `TransformException` - if the envelope cannot be computed with the given transform.
    Since:
      1.1
    See Also:
      - `GridGeometry​.getEnvelope()`
      - `PixelInCell​.CELL_CORNER`

  - ### insertDimension

    public GridExtent insertDimension(int index, DimensionNameType axisType, long low, long high, boolean isHighIncluded)
    Returns a new grid extent with the specified dimension inserted at the given index in this grid extent. To append a new dimension after all existing dimensions, set `index` to `getDimension()`.
    Parameters:
      `index` - where to insert the new dimension, from 0 to `getDimension()` inclusive.
      `axisType` - the type of the grid axis to add, or `null` if unspecified.
      `low` - the valid minimum grid coordinate (always inclusive).
      `high` - the valid maximum grid coordinate, inclusive or exclusive depending on the next argument.
      `isHighIncluded` - `true` if the `high` value is inclusive (as in ISO 19123 specification), or `false` if it is exclusive (as in Java2D usage). This argument does not apply to `low` value, which is always inclusive.
    Returns:
      a new grid extent with the specified dimension added.
    Throws:
      `IndexOutOfBoundsException` - if the given index is negative or greater than the grid dimension.
      `IllegalArgumentException` - if the low coordinate value is greater than the high coordinate value.
    Since:
      1.1
    See Also:
      - `selectDimensions(int...)`

  - ### selectDimensions

    public GridExtent selectDimensions(int... indices)
    Returns a grid extent that encompass only some dimensions of this grid extent. This method copies the specified dimensions of this grid extent into a new grid extent. The given dimensions must be in strictly ascending order without duplicated values. The number of dimensions of the sub grid extent will be `indices​.length`.

    This method performs a dimensionality reduction and can be used as the converse of `insertDimension(…)`. This method cannot be used for changing dimension order.

    Parameters:
      `indices` - the dimensions to select, in strictly increasing order.
    Returns:
      the sub-envelope, or `this` if the given array contains all dimensions of this grid extent.
    Throws:
      `IndexOutOfBoundsException` - if an index is out of bounds.
    Since:
      1.3
    See Also:
      - `getSubspaceDimensions(int)`
      - `GridGeometry​.selectDimensions(int...)`
      - `DimensionalityReduction​.apply(GridExtent)`

  - ### expand

    public GridExtent expand(long... margins)
    Returns a grid extent expanded by the given number of cells on both sides along each dimension. This method adds the given margins to the high coordinates and subtracts the same margins from the low coordinates. If a negative margin is supplied, the extent size decreases accordingly.

    #### Number of arguments

    The `margins` array length should be equal to the number of dimensions. If the array is shorter, missing values default to 0 (i.e. sizes in unspecified dimensions are unchanged). If the array is longer, extraneous values are ignored.
    Parameters:
      `margins` - number of cells to add or subtract on both sides for each dimension.
    Returns:
      a grid extent expanded by the given amount, or `this` if there is no change.
    Throws:
      `ArithmeticException` - if expanding this extent by the given margins overflows `long` capacity.
    See Also:
      - `GridDerivation​.margin(int...)`

  - ### resize

    public GridExtent resize(long... sizes)
    Sets the size of grid extent to the given values by moving low and high coordinates. This method modifies grid coordinates as if they were multiplied by (given size) / (current size), rounded toward zero and with the value farthest from zero adjusted by ±1 for having a size exactly equals to the specified value. In the common case where the low value is zero, this is equivalent to setting the high value to `size` - 1.

    #### Number of arguments

    The `sizes` array length should be equal to the number of dimensions. If the array is shorter, sizes in unspecified dimensions are unchanged. If the array is longer, extraneous values are ignored.
    Parameters:
      `sizes` - the new grid sizes for each dimension.
    Returns:
      a grid extent having the given sizes, or `this` if there is no change.
    Throws:
      `ArithmeticException` - if resizing this extent to the given size overflows `long` capacity.
    See Also:
      - `getSize(int)`
      - `GridDerivation​.subgrid(GridExtent, long...)`

  - ### subsample

    public GridExtent subsample(long... periods)
    Creates a new grid extent subsampled by the given number of cells along each grid dimensions. This method divides low coordinates and grid sizes by the given periods, rounding toward zero. The high coordinates are adjusted accordingly (this is often equivalent to dividing high coordinates by the periods too, but a difference of one cell may exist).

    #### Usage note

    If the "real world" envelope computed from grid extent needs to stay approximately the same, then the grid to CRS transform needs to compensate the subsampling with a pre-multiplication of each grid coordinates by `periods`. However, the envelope computed that way may become larger after subsampling, not smaller. This effect can be understood intuitively if we consider that cells become larger after subsampling, which implies that accurate representation of the same envelope may require fractional cells on some grid borders.

    This method does not reduce the number of dimensions of the grid extent. For dimensionality reduction, see `selectDimensions(int[])`.

    #### Number of arguments

    The `periods` array length should be equal to the number of dimensions. If the array is shorter, missing values default to 1 (i.e. samplings in unspecified dimensions are unchanged). If the array is longer, extraneous values are ignored.
    Parameters:
      `periods` - the subsampling factors for each dimension of this grid extent.
    Returns:
      the subsampled extent, or `this` if subsampling results in the same extent.
    Throws:
      `IllegalArgumentException` - if a period is not greater than zero.
    Since:
      1.5
    See Also:
      - `GridDerivation​.subgrid(GridExtent, long...)`

  - ### subsample

    @Deprecated(since="1.5") public GridExtent subsample(int[] periods)
    Deprecated.
    Use the version with `long` integers instead of `int`. Small overviews of large images require large subsampling factors.
    Creates a new subsampled grid extent (32-bits version). See `subsample(long...)` for details.
    Parameters:
      `periods` - the subsampling factors for each dimension of this grid extent.
    Returns:
      the subsampled extent, or `this` if subsampling results in the same extent.
    Throws:
      `IllegalArgumentException` - if a period is not greater than zero.

  - ### upsample

    public GridExtent upsample(long... periods)
    Creates a new grid extent upsampled by the given number of cells along each grid dimensions. This method multiplies the low coordinates and the size by the given periods. This method does not change the number of dimensions of the grid extent.

    #### Number of arguments

    The `periods` array length should be equal to the number of dimensions. If the array is shorter, missing values default to 1 (i.e. samplings in unspecified dimensions are unchanged). If the array is longer, extraneous values are ignored.
    Parameters:
      `periods` - the upsampling factors for each dimension of this grid extent.
    Returns:
      the upsampled extent, or `this` if upsampling results in the same extent.
    Throws:
      `IllegalArgumentException` - if a period is not greater than zero.
      `ArithmeticException` - if the upsampled extent overflows the `long` capacity.
    Since:
      1.5
    See Also:
      - `GridGeometry​.upsample(long...)`

  - ### upsample

    @Deprecated(since="1.5") public GridExtent upsample(int[] periods)
    Deprecated.
    Use the version with `long` integers instead of `int`. Small overviews of large images require large subsampling factors.
    Creates a new upsampled grid extent (32-bits version). See `upsample(long...)` for details.
    Parameters:
      `periods` - the upsampling factors for each dimension of this grid extent.
    Returns:
      the upsampled extent, or `this` if upsampling results in the same extent.
    Throws:
      `IllegalArgumentException` - if a period is not greater than zero.
      `ArithmeticException` - if the upsampled extent overflows the `long` capacity.
    Since:
      1.3

  - ### translate

    public final GridExtent translate(long... translation)
    Returns an extent translated by the given number of cells compared to this extent. The returned extent has the same size than this extent, i.e. both low and high grid coordinates are displaced by the same number of cells.

    #### Example

    For an extent (x: [0…10], y: [2…4], z: [0…1]) and a translation {-2, 2}, the resulting extent would be (x: [-2…8], y: [4…6], z: [0…1]).

    #### Number of arguments

    The `translation` array length should be equal to the number of dimensions. If the array is shorter, missing values default to 0 (i.e. no translation in unspecified dimensions). If the array is longer, extraneous values are ignored.
    Parameters:
      `translation` - translation to apply on each axis in order. Can be an array of any length.
    Returns:
      a grid extent whose coordinates (both low and high ones) have been translated by the given numbers. If the given translation is a no-op (no value or only 0 ones), then this extent is returned as is.
    Throws:
      `ArithmeticException` - if the translation results in coordinates that overflow 64-bits integer.
    Since:
      1.1
    See Also:
      - `startsAtZero()`
      - `GridGeometry​.shiftGrid(long...)`

  - ### translate

    public GridExtent translate(long[] translation, boolean negate)
    Returns an extent translated by the given number of cells, optionally in the reverse direction. Invoking this method is equivalent to invoking `translate(long...)`, except that this method use the negative values of the given translation terms if the `negate` argument is `true`.
    Parameters:
      `translation` - translation to apply on each axis in order. Can be an array of any length.
      `negate` - whether to use the negative values of the given translation terms.
    Returns:
      a grid extent whose coordinates (both low and high ones) have been translated by the given numbers. If the given translation is a no-op (no value or only 0 ones), then this extent is returned as is.
    Throws:
      `ArithmeticException` - if the translation results in coordinates that overflow 64-bits integer.
    Since:
      1.5

  - ### contains

    public boolean contains(long... cell)
    Returns `true` if this extent contains the given coordinates of a grid cell. A grid coordinate is considered inside the grid extent if its value is between `low` and `high` bounds, inclusive.

    #### Number of arguments

    The `cell` array length should be equal to the number of dimensions. If the array is shorter, missing coordinate values are considered inside the extent. If the array is longer, extraneous coordinate values are ignored.
    Parameters:
      `cell` - grid coordinates of a cell to check for inclusion.
    Returns:
      whether the given grid coordinates are inside this extent.
    Since:
      1.2

  - ### contains

    public boolean contains(GridExtent other)
    Returns whether this extent contains the given extent. The given extent shall have the same number of dimensions as this extent. The axis types (vertical, temporal, …) must be the same in all dimensions, ignoring types that are unspecified.
    Parameters:
      `other` - the grid to text for inclusion.
    Returns:
      whether this grid contains the given grid.
    Throws:
      `MismatchedDimensionException` - if the two extents do not have the same number of dimensions.
      `IllegalArgumentException` - if axis types are specified but inconsistent in at least one dimension.
    Since:
      1.5
    See Also:
      - `GridGeometry​.contains(GridGeometry)`

  - ### intersects

    public boolean intersects(GridExtent other)
    Returns whether this extent intersects the given extent. The given extent shall have the same number of dimensions as this extent. The axis types (vertical, temporal, …) must be the same in all dimensions, ignoring types that are unspecified.

    This method is symmetric: it is guaranteed that `A​.intersects(B) = B​.intersects(A)` for all (A, B) pairs.

    Parameters:
      `other` - the grid to text for inclusion.
    Returns:
      whether this grid intersects the given grid.
    Throws:
      `MismatchedDimensionException` - if the two extents do not have the same number of dimensions.
      `IllegalArgumentException` - if axis types are specified but inconsistent in at least one dimension.
    Since:
      1.5
    See Also:
      - `GridGeometry​.intersects(GridGeometry)`

  - ### intersect

    public GridExtent intersect(GridExtent other)
    Returns the intersection of this grid extent with the given grid extent. The given extent shall have the same number of dimensions as this extent. The axis types (vertical, temporal, …) must be the same in all dimensions, ignoring types that are unspecified.
    Parameters:
      `other` - the grid to intersect with.
    Returns:
      the intersection result. May be one of the existing instances.
    Throws:
      `MismatchedDimensionException` - if the two extents do not have the same number of dimensions.
      `IllegalArgumentException` - if axis types are specified but inconsistent in at least one dimension.
      `DisjointExtentException` - if the given extent does not intersect this extent.
    Since:
      1.3

  - ### union

    public GridExtent union(GridExtent other)
    Returns the union of this grid extent with the given grid extent. The given extent shall have the same number of dimensions as this extent. The axis types (vertical, temporal, …) must be the same in all dimensions, ignoring types that are unspecified.
    Parameters:
      `other` - the grid to combine with.
    Returns:
      the union result. May be one of the existing instances.
    Throws:
      `MismatchedDimensionException` - if the two extents do not have the same number of dimensions.
      `IllegalArgumentException` - if axis types are specified but inconsistent in at least one dimension.
    Since:
      1.3

  - ### equals

    public final boolean equals(Object object)
    Compares the specified object with this grid extent for equality. This method delegates to `equals(object, ComparisonMode​.STRICT)`.
    Specified by:
      `equals` in interface `LenientComparable`
    Overrides:
      `equals` in class `Object`
    Parameters:
      `object` - the object to compare with this grid extent for equality.
    Returns:
      `true` if the given object is equal to this grid extent.
    See Also:
      - `ComparisonMode​.STRICT`

  - ### equals

    public boolean equals(Object object, ComparisonMode mode)
    Compares the specified object with this grid extent for equality. If the mode is `ComparisonMode​.IGNORE_METADATA` or more flexible, then the axis types are ignored.
    Specified by:
      `equals` in interface `LenientComparable`
    Parameters:
      `object` - the object to compare with this grid extent for equality.
      `mode` - the strictness level of the comparison.
    Returns:
      `true` if the given object is equal to this grid extent.
    Since:
      1.1
    See Also:
      - `Utilities​.deepEquals(Object, Object, ComparisonMode)`

  - ### hashCode

    public int hashCode()
    Returns a hash value for this grid extent. This value needs not to remain consistent between different implementations of the same class.
    Overrides:
      `hashCode` in class `Object`
    Returns:
      a hash value for this grid extent.

  - ### toString

    public String toString()
    Returns a string representation of this grid extent. The returned string is implementation dependent and is provided for debugging purposes only.
    Overrides:
      `toString` in class `Object`