Class Matrices.Hyperparallelepiped

java.lang.Object
net.algart.arrays.Matrices.Region
net.algart.arrays.Matrices.Hyperparallelepiped
Enclosing class:
Matrices

public static final class Matrices.Hyperparallelepiped extends Matrices.Region

Hyperparallelepiped: the simplest n-dimensional region. In 1-dimensional case it is a segment, in 2-dimensional case it is a rectangle, in 3-dimensional case it is a parallelepiped. All edges of the hyperparallelepiped are supposed to be parallel to coordinate axes.

More precisely, the region, specified by this class, consists of all such points (x0, x1, ..., xn−1), that:

coordRanges[0].min()x0coordRanges[0].max(),
coordRanges[1].min()x1coordRanges[1].max(),
...,
coordRanges[n-1].min()xn−1coordRanges[n-1].max(),

where coordRanges is the result of Matrices.Region.coordRanges() method.

Hyperparallelepipeds can be created by the following methods:

This class is immutable and thread-safe: there are no ways to modify settings of the created instance.

  • Method Details

    • isRectangular

      public boolean isRectangular()
      Description copied from class: Matrices.Region
      Returns true if this region is rectangular, that is if it contains the same set of integer points (points with integer coordinates) as some hyperparallelepiped. This method always returns false if this region is not rectangular, but there is no guarantee that it returns true when it is rectangular.

      This default implementation returns false. In Matrices.Hyperparallelepiped class this method returns true. In all other inheritors of this class, implemented in this package, it returns false.

      Overrides:
      isRectangular in class Matrices.Region
      Returns:
      true if this region is rectangular.
    • contains

      public boolean contains(long... coordinates)
      Description copied from class: Matrices.Region
      Returns true if and only if the point with the specified integer coordinates belongs to this region.

      The coordinates must contain at least Matrices.Region.n() elements. It can contain more than Matrices.Region.n() elements; then the extra elements will be ignored.

      Warning! Some inheritors of this class does not provide correct implementation of this method. In this case, Matrices.Region.isContainsSupported() method returns false and this method throws UnsupportedOperationException. So, you must always check the result of Matrices.Region.isContainsSupported() method before calling this one.

      However, this method must be correctly implemented, if this region is a 1-dimensional (Matrices.Region.n()==1) and Matrices.Region.isRectangular() method returns false.

      Note: even if the inheritor does not provide correct implementation of this method, it must always provide correct implementation of Matrices.Region.sectionAtLastCoordinate(long) method.

      Specified by:
      contains in class Matrices.Region
      Parameters:
      coordinates - the coordinates of the point: the first element is x, the second is y, ...
      Returns:
      true if and only if the point with the specified coordinates belongs to this region.
    • sectionAtLastCoordinate

      public Matrices.Region[] sectionAtLastCoordinate(long sectionCoordinateValue)
      Description copied from class: Matrices.Region
      Finds the intersection of this region with the hyperplane, described by the equation xn−1=sectionCoordinateValue, and returns this intersection as an array of (n−1)-dimensional regions. (Here xn−1 is the last coordinate of the points: y-coordinate in 2-dimensional case, z-coordinate in 3-dimensional case, etc.) If the intersection is empty, this method returns an empty array ("new Region[0]"). This method never returns null.

      This method must not be used if this region is 1-dimensional (Matrices.Region.n()==1). In this case, it throws IllegalStateException.

      This default implementation is based on Matrices.Region.contains(long...) method, which is supposed to be correctly implemented.

      Note: it is possible (in some rare exotic cases), that the regions, returned by this method, intersects with each other: some points will belong to 2 and more elements of the result. In particular, it is possible for Matrices.Polygon2D, if some sides of the polygon lie exactly at the horizontal y=sectionCoordinateValue.

      Implementations of this method in this packages, besides the implementation in Matrices.Polygon2D class, never return more than 1 region in the result.

      You must override this method if you prefer not to implement Matrices.Region.contains(long...) method (Matrices.Region.isContainsSupported() returns false). In this case, your implementation must not call Matrices.Region.contains(long...) method or super.Matrices.Region.sectionAtLastCoordinate(long).

      Overrides:
      sectionAtLastCoordinate in class Matrices.Region
      Parameters:
      sectionCoordinateValue - the value of the last coordinate.
      Returns:
      the intersection of this region and the (n−1)-dimensional hyperplane, corresponding to the specified value of the last coordinate (0, 1 or more regions, every region is (n−1)-dimensional).
    • isInsideMatrix

      public boolean isInsideMatrix(Matrix<?> matrix)
      Returns true if and only if the coordinates of all points (with integer coordinates), belonging to this hyperparallelepiped, lies inside the specified matrix.

      Note: the number of matrix dimensions can differ from the number of dimensions of this region. (All matrix dimensions after the first Matrices.Region.n(), as usual, are supposed to be 1.)

      More precisely, this method returns true if and only if the following 2*Matrices.Region.n() conditions are fulfilled:

      0 ≤ coordRanges[0].min(),    coordRanges[0].max() < matrix.dim(0),
      0 ≤ coordRanges[1].min(),    coordRanges[1].max() < matrix.dim(1),
      ...,
      0 ≤ coordRanges[n-1].min(),    coordRanges[n-1].max() < matrix.dim(n-1)

      This method is equivalent to the following call: isInsideMatrix(matrix, new long[0]).

      Parameters:
      matrix - the matrix.
      Returns:
      true if this region lies fully inside the specified matrix.
      Throws:
      NullPointerException - if the matrix argument is null.
    • isInsideMatrix

      public boolean isInsideMatrix(Matrix<?> matrix, long... backShifts)
      Returns true if and only if the coordinates of all points (with integer coordinates), belonging to this hyperparallelepiped, will lie inside the specified matrix after subtraction the specified values backShifts from them.

      Note: the number of matrix dimensions can differ from the number of dimensions of this region. (All matrix dimensions after the first Matrices.Region.n(), as usual, are supposed to be 1.) The number of elements of backShifts also can differ from the number of dimensions. All missing elements of backShifts array are supposed to be zero.

      More precisely, this method returns true if and only if the following 2*Matrices.Region.n() conditions are fulfilled:

      0 ≤ coordRanges[0].min() - sh0,
      coordRanges[0].max() - sh0 < matrix.dim(0),
      0 ≤ coordRanges[1].min() - sh1,
      coordRanges[1].max() - sh1 < matrix.dim(1),
      ...,
      0 ≤ coordRanges[n-1].min() - shn-1,
      coordRanges[n-1].max() - shn-1 < matrix.dim(n-1),

      where shk = k < backShifts.length ? backShifts[k] : 0

      Parameters:
      matrix - the matrix.
      backShifts - the shifts, which are subtracted from all coordinates of this region before the check.
      Returns:
      true if this region, shifted backwards by the specified shifts, lies fully inside the specified matrix.
      Throws:
      NullPointerException - if the matrix or backShifts argument is null.
    • toString

      public String toString()
      Returns a brief string description of this object.

      The result of this method may depend on implementation.

      Overrides:
      toString in class Object
      Returns:
      a brief string description of this object.