public interface RectangularPattern extends UniformGridPattern, QuickPointCountPattern
Interface, used by Pattern
implementations to indicate that
they are rectangular patterns, i.e.
consist of all points of some uniform grid inside some hyperparallelepiped.
(For 2D patterns it means a rectangle, for 1D pattern it means an interval.)
This interface is a subinterface of UniformGridPattern
: all rectangular patterns
are also uniformgrid.
See also the section "Rectangular patterns" in the comments to Pattern
interface.
More precisely, a pattern, implementing this interface, is a nonempty set of all points
Pattern.dimCount()
), such that:
x_{0}^{(k)} = o_{0} + i_{0}^{(k)}d_{0}where o_{j} are coordinates of the
x_{1}^{(k)} = o_{1} + i_{1}^{(k)}d_{1}
. . .
x_{n−1}^{(k)} = o_{n−1} + i_{n−1}^{(k)}d_{n−1},
min_{j} ≤ i_{j}^{(k)} ≤ max_{j} for allj=0,1,...,n−1 ,
origin of the grid
,
d_{j} are steps of the grid
,
and the integer numbers min_{j} / max_{j} are
coordinates of two integer points, specified while creating the pattern.
Moreover, these parameters (o_{j}, d_{j},
min_{j} / max_{j})
are stored inside the object and can be quickly read at any time
by UniformGridPattern.gridIndexMin()
, UniformGridPattern.gridIndexMax()
and similar methods
— this condition is a requirement for all implementations of this interface.
Note: not only patterns, implementing this interface, can be such sets of points.
In particular, you can construct an analogous set by Patterns.newPattern(net.algart.math.Point...)
method, and it will not implement this interface. If a uniformgrid pattern
does not implement this interface, you can still try to detect, whether it is really a rectangular parallelepiped,
by UniformGridPattern.isActuallyRectangular()
method.
If a pattern implements this interface, then there is a guarantee that the following
methods work very quickly (O(1) or O(dimCount()
) operations):
Pattern.pointCount()
,Pattern.largePointCount()
,Pattern.isSurelySinglePoint()
,Pattern.isSurelyOriginPoint()
,Pattern.coordRange(int)
,Pattern.coordArea()
,Pattern.coordMin()
,Pattern.coordMax()
,Pattern.roundedCoordRange(int)
,Pattern.roundedCoordArea()
,Pattern.round()
,UniformGridPattern.gridIndexRange(int)
,UniformGridPattern.gridIndexArea()
,UniformGridPattern.gridIndexMin()
,UniformGridPattern.gridIndexMax()
,UniformGridPattern.isActuallyRectangular()
(this method just returns true immediately),lowerSurface(int)
,upperSurface(int)
,UniformGridPattern.surface()
,minBound(int)
,maxBound(int)
,UniformGridPattern.carcass()
.Also in such patterns there is a guarantee, that all these methods work successfully,
i.e. without risk to throw TooManyPointsInPatternError
or OutOfMemoryError.
If a pattern implements this interface, it never implements DirectPointSetPattern
interface.
There is a guarantee, that the following methods (and, in this package, only they) create patterns, implementing this interface:
UniformGridPattern.isActuallyRectangular()
,
QuickPointCountPattern
MAX_COORDINATE
Modifier and Type  Method and Description 

RectangularPattern 
gridIndexPattern()
Returns an
ordinary integer pattern with the same set of grid indexes
i_{j}^{(k)} as this pattern. 
RectangularPattern 
lowerSurface(int coordIndex)
Returns the lower boundary of this pattern along the given axis:
a pattern consisting of all such points A of this pattern,
that the neighbour point B,
generated by the backward shift of point A along the coordinate #j=coordIndex
by the corresponding grid step
stepOfGrid(coordIndex) 
RectangularPattern 
maxBound(int coordIndex)
Returns the maximal boundary of this pattern along the given axis:
a pattern consisting of all points of this pattern, for which there are
no other points with greater coordinate #coordIndex
and same other coordinates.

RectangularPattern 
minBound(int coordIndex)
Returns the minimal boundary of this pattern along the given axis:
a pattern consisting of all points of this pattern, for which there are
no other points with less coordinate #coordIndex
and same other coordinates.

RectangularPattern 
multiply(double multiplier)
Returns this pattern, scaled by the specified multiplier along all coordinates.

RectangularPattern 
projectionAlongAxis(int coordIndex)
Returns the projection of this pattern along the given axis.

RectangularPattern 
scale(double... multipliers)
Returns this pattern, scaled by the specified multipliers along all coordinates.

RectangularPattern 
shift(Point shift)
Returns this pattern, shifted by the argument.

RectangularPattern 
shiftGridIndexes(IPoint shift)
Returns another uniformgrid pattern, identical to this one with the only difference, that
the grid index
add (shift). 
RectangularPattern 
symmetric()
Returns the symmetric pattern: equivalent to
multiply(1.0) . 
RectangularPattern 
upperSurface(int coordIndex)
Returns the upper boundary of this pattern along the given axis:
a pattern consisting of all such points A of this pattern,
that the neighbour point B,
generated by the forward shift of point A along the coordinate #j=coordIndex
by the corresponding grid step
stepOfGrid(coordIndex) 
carcass, gridIndexArea, gridIndexes, gridIndexMax, gridIndexMin, gridIndexRange, isActuallyRectangular, isOrdinary, originOfGrid, stepOfGrid, stepsOfGrid, stepsOfGridEqual, surface
isPointCountVeryLarge
allUnionDecompositions, coordArea, coordMax, coordMin, coordRange, dimCount, hasMinkowskiDecomposition, isSurelyInteger, isSurelyOriginPoint, isSurelySinglePoint, largePointCount, maxCarcassMultiplier, minkowskiAdd, minkowskiDecomposition, minkowskiSubtract, pointCount, points, round, roundedCoordArea, roundedCoordRange, roundedPoints, unionDecomposition
RectangularPattern shift(Point shift)
Pattern
More precisely, the resulting pattern consists of the points,
obtained from all points of this pattern by the call point.add
(shift).
The returned pattern always implements DirectPointSetPattern
if this pattern implements DirectPointSetPattern
The returned pattern always implements RectangularPattern
if this pattern implements RectangularPattern
.
The returned pattern always implements UniformGridPattern
if this pattern implements UniformGridPattern
.
There is a guarantee, that this method does not try to allocate much more memory,
that it is required for storing this pattern itself, and that it
never throws TooManyPointsInPatternError
.
For comparison, an attempt to do the same operation via getting all points (Pattern.points()
method),
correcting them and forming a new pattern via Patterns.newPattern(java.util.Collection)
will lead to TooManyPointsInPatternError
/ OutOfMemoryError for some forms of large patterns.
Warning: this method can fail with TooLargePatternCoordinatesException
, if some of new points
violate restrictions, described in the comments to this interface
,
section "Coordinate restrictions" (for example, due to very large shift).
However, TooLargePatternCoordinatesException
is impossible in many important cases, when
this pattern is an integer pattern and each coordinate
coord
(j)TooLargePatternCoordinatesException
in the following situations:
coordMin()
.symmetric()
,coordMax()
.symmetric()
,symmetric()
, where p is
some of the points
if this integer pattern.See more details in the comments to this interface
,
section "Coordinate restrictions", the theorem II.
shift
in interface Pattern
shift
in interface UniformGridPattern
shift
 the shift.RectangularPattern symmetric()
Pattern
multiply(1.0)
.
The returned pattern always implements DirectPointSetPattern
if this pattern implements DirectPointSetPattern
The returned pattern always implements RectangularPattern
if this pattern implements RectangularPattern
.
The returned pattern always implements UniformGridPattern
if this pattern implements UniformGridPattern
.
There is a guarantee, that this method does not try to allocate much more memory,
that it is required for storing this pattern itself, and that it
never throws TooManyPointsInPatternError
.
For comparison, an attempt to do the same operation via getting all points (Pattern.points()
method),
correcting them and forming a new pattern via Patterns.newPattern(java.util.Collection)
will lead to TooManyPointsInPatternError
/ OutOfMemoryError for some forms of large patterns.
symmetric
in interface Pattern
symmetric
in interface UniformGridPattern
RectangularPattern multiply(double multiplier)
Pattern
More precisely, the resulting pattern consists of the points,
obtained from all points of this pattern by the call
point.multiply
(multipliers).
This method is equivalent to Pattern.scale(double... multipliers)
, where all
Pattern.dimCount()
arguments of that method are equal to multiplier.
The returned pattern always implements DirectPointSetPattern
if this pattern implements DirectPointSetPattern
The returned pattern always implements RectangularPattern
if this pattern implements RectangularPattern
.
The returned pattern always implements UniformGridPattern
if this pattern implements UniformGridPattern
.
There is a guarantee, that this method does not try to allocate much more memory,
that it is required for storing this pattern itself, and that it
never throws TooManyPointsInPatternError
.
For comparison, an attempt to do the same operation via getting all points (Pattern.points()
method),
correcting them and forming a new pattern via Patterns.newPattern(java.util.Collection)
will lead to TooManyPointsInPatternError
/ OutOfMemoryError for some forms of large patterns.
Warning: this method can fail with TooLargePatternCoordinatesException
, if some of new points
violate restrictions, described in the comments to this interface
,
section "Coordinate restrictions" (for example, due to a very large multiplier).
However, such failure is obviously impossible, if the multiplier is
in range 1.0<=multiplier<=1.0.
multiply
in interface Pattern
multiply
in interface UniformGridPattern
multiplier
 the scale along all coordinates.Pattern.scale(double...)
RectangularPattern scale(double... multipliers)
Pattern
More precisely, the resulting pattern consists of the points,
obtained from all points of this pattern by the call
point.scale
(multipliers).
The returned pattern always implements DirectPointSetPattern
if this pattern implements DirectPointSetPattern
The returned pattern always implements RectangularPattern
if this pattern implements RectangularPattern
.
The returned pattern always implements UniformGridPattern
if this pattern implements UniformGridPattern
.
There is a guarantee, that this method does not try to allocate much more memory,
that it is required for storing this pattern itself, and that it
never throws TooManyPointsInPatternError
.
For comparison, an attempt to do the same operation via getting all points (Pattern.points()
method),
correcting them and forming a new pattern via Patterns.newPattern(java.util.Collection)
will lead to TooManyPointsInPatternError
/ OutOfMemoryError for some forms of large patterns.
Warning: this method can fail with TooLargePatternCoordinatesException
, if some of new points
violate restrictions, described in the comments to this interface
,
section "Coordinate restrictions" (for example, due to very large multipliers).
However, such failure is obviously impossible, if all multipliers are
in range 1.0<=multipliers[k]<=1.0.
scale
in interface Pattern
scale
in interface UniformGridPattern
multipliers
 the scales along coordinates.Pattern.multiply(double)
RectangularPattern projectionAlongAxis(int coordIndex)
Pattern
Pattern.dimCount()
) is less by 1, than in this one.
More precisely, the resulting pattern consists of the points,
obtained from all points of this pattern by the call
point.projectionAlongAxis
(coordIndex).
The returned pattern always implements DirectPointSetPattern
if this pattern implements DirectPointSetPattern
The returned pattern always implements RectangularPattern
if this pattern implements RectangularPattern
.
The returned pattern always implements UniformGridPattern
if this pattern implements UniformGridPattern
.
There is a guarantee, that this method does not try to allocate much more memory,
that it is required for storing this pattern itself, and that it
never throws TooManyPointsInPatternError
.
For comparison, an attempt to do the same operation via getting all points (Pattern.points()
method),
correcting them and forming a new pattern via Patterns.newPattern(java.util.Collection)
will lead to TooManyPointsInPatternError
/ OutOfMemoryError for some forms of large patterns.
projectionAlongAxis
in interface Pattern
projectionAlongAxis
in interface UniformGridPattern
coordIndex
 the index of the coordinate (0 for xaxis , 1 for yaxis,
2 for zaxis, etc.).Pattern.dimCount()
is equal to
thisInstance.Pattern.dimCount()
1).RectangularPattern minBound(int coordIndex)
Pattern
Pattern.dimCount()
) is the same as in this one.
In other words, this method removes some points from this pattern according the following rule:
if this pattern contains several points p_{0}, p_{1}, ...,
p_{m−1} with identical projection to the given axis
(p_{i}.projectionAlongAxis
(coordIndex).equals(p_{j}.projectionAlongAxis
(coordIndex)) for all i, j),
then the resulting pattern contains only one from these points, for which
the given coordinate coord
(coordIndex) has the minimal value.
This method is especially useful for uniformgrid
patterns.
For example, in rectangular patterns
this method returns
one of the facets of the hyperparallelepiped.
In most cases (including all rectangular patterns
)
this method returns the same result as UniformGridPattern.lowerSurface(int)
;
but if the figure, described by this pattern, contains some "holes", the result of this method
contains fewer points than UniformGridPattern.lowerSurface(int)
.
The returned pattern always implements DirectPointSetPattern
if this pattern implements DirectPointSetPattern
The returned pattern always implements RectangularPattern
if this pattern implements RectangularPattern
.
The returned pattern always implements UniformGridPattern
if this pattern implements UniformGridPattern
.
Warning! If this object is not DirectPointSetPattern
and is not RectangularPattern
, this method can work slowly for some large patterns:
the required time can be O(N), where N is the number of points.
In these cases, this method can also throw TooManyPointsInPatternError
or OutOfMemoryError. The situation is like in Pattern.points()
and Pattern.roundedPoints()
method.
There is a guarantee, that if this object implements DirectPointSetPattern
interface,
then this method requires not greater than O(N) memory
(N=pointCount()
)
and never throws TooManyPointsInPatternError
.
There is a guarantee, that if this object implements RectangularPattern
interface,
then this method works quickly (O(1) operations) and without exceptions.
minBound
in interface Pattern
minBound
in interface UniformGridPattern
coordIndex
 the index of the coordinate (0 for xaxis , 1 for yaxis,
2 for zaxis, etc.).Pattern.maxBound(int)
RectangularPattern maxBound(int coordIndex)
Pattern
Pattern.dimCount()
) is the same as in this one.
In other words, this method removes some points from this pattern according the following rule:
if this pattern contains several points p_{0}, p_{1}, ...,
p_{m−1} with identical projection to the given axis
(p_{i}.projectionAlongAxis
(coordIndex).equals(p_{j}.projectionAlongAxis
(coordIndex)) for all i, j),
then the resulting pattern contains only one from these points, for which
the given coordinate coord
(coordIndex) has the maximal value.
This method is especially useful for uniformgrid
patterns.
For example, in rectangular patterns
this method returns
one of the facets of the hyperparallelepiped.
In most cases (including all rectangular patterns
)
this method returns the same result as UniformGridPattern.upperSurface(int)
;
but if the figure, described by this pattern, contains some "holes", the result of this method
contains fewer points than UniformGridPattern.upperSurface(int)
.
The returned pattern always implements DirectPointSetPattern
if this pattern implements DirectPointSetPattern
The returned pattern always implements RectangularPattern
if this pattern implements RectangularPattern
.
The returned pattern always implements UniformGridPattern
if this pattern implements UniformGridPattern
.
Warning! If this object is not DirectPointSetPattern
and is not RectangularPattern
, this method can work slowly for some large patterns:
the required time can be O(N), where N is the number of points.
In these cases, this method can also throw TooManyPointsInPatternError
or OutOfMemoryError. The situation is like in Pattern.points()
and Pattern.roundedPoints()
method.
There is a guarantee, that if this object implements DirectPointSetPattern
interface,
then this method requires not greater than O(N) memory
(N=pointCount()
)
and never throws TooManyPointsInPatternError
.
There is a guarantee, that if this object implements RectangularPattern
interface,
then this method works quickly (O(1) operations) and without exceptions.
maxBound
in interface Pattern
maxBound
in interface UniformGridPattern
coordIndex
 the index of the coordinate (0 for xaxis , 1 for yaxis,
2 for zaxis, etc.).Pattern.minBound(int)
RectangularPattern gridIndexPattern()
UniformGridPattern
ordinary
integer pattern with the same set of grid indexes
i_{j}^{(k)} as this pattern.
In other words, if this pattern is a set of points
x_{0}^{(k)} = o_{0} + i_{0}^{(k)}d_{0}
x_{1}^{(k)} = o_{1} + i_{1}^{(k)}d_{1}
. . .
x_{n−1}^{(k)} = o_{n−1} + i_{n−1}^{(k)}d_{n−1}
(k=0,1,...,N−1, n=dimCount()
), then the returned pattern
consists of points
y_{0}^{(k)} = (double)i_{0}^{(k)}
y_{1}^{(k)} = (double)i_{1}^{(k)}
. . .
y_{n−1}^{(k)} = (double)i_{n−1}^{(k)}
Note: here is a guarantee, that all grid indexes i_{j} will be strictly
represented by double type.
Moreover, there is a guarantee that the returned pattern is correct, i.e. will be successfully built
without a risk of TooLargePatternCoordinatesException
.
See the comments to Pattern.MAX_COORDINATE
and the section "Grid index restrictions" in the comments to UniformGridPattern
interface.
You can use this method to get a set of all grid indexes (integer values):
it is enough to call Pattern.roundedPoints()
in the returned pattern.
The results will be the same as the result of UniformGridPattern.gridIndexes()
method.
The returned pattern always implements DirectPointSetPattern
if this pattern implements DirectPointSetPattern
.
The returned pattern always implements RectangularPattern
if this pattern implements RectangularPattern
.
There is a guarantee, that this method does not try to allocate much more memory,
that it is required for storing this pattern itself, and that it
never throws TooManyPointsInPatternError
.
This method works quickly enough: in the worst case,
it can require O(N) operations (N=pointCount()
).
gridIndexPattern
in interface UniformGridPattern
UniformGridPattern.gridIndexes()
RectangularPattern shiftGridIndexes(IPoint shift)
UniformGridPattern
add
(shift).
In other words, if this pattern is a set of points
x_{0}^{(k)} = o_{0} + i_{0}^{(k)}d_{0}
x_{1}^{(k)} = o_{1} + i_{1}^{(k)}d_{1}
. . .
x_{n−1}^{(k)} = o_{n−1} + i_{n−1}^{(k)}d_{n−1}
(k=0,1,...,N−1, n=dimCount()
), then the returned pattern
has the same grid oridin
, the same grid steps
and consists of points
y_{0}^{(k)} = o_{0} + (i_{0}^{(k)}+shift.coord
(0))*d_{0}
y_{1}^{(k)} = o_{1} + (i_{1}^{(k)}+shift.coord
(1))*d_{1}
. . .
y_{n−1}^{(k)} = o_{n−1} + (i_{n−1}^{(k)}+shift.coord
(n−1))*d_{n−1}
The returned pattern always implements DirectPointSetPattern
if this pattern implements DirectPointSetPattern
The returned pattern always implements RectangularPattern
if this pattern implements RectangularPattern
.
There is a guarantee, that this method does not try to allocate much more memory,
that it is required for storing this pattern itself, and that it
never throws TooManyPointsInPatternError
.
For comparison, an attempt to do the same operation via getting all grid indexes via
UniformGridPattern.gridIndexes()
call, correcting them and forming a new pattern via
Patterns.newUniformGridPattern(Point, double[], java.util.Collection)
will lead to TooManyPointsInPatternError
/ OutOfMemoryError for some forms of large patterns.
Warning: this method can fail with TooLargePatternCoordinatesException
, if some of new points
violate restrictions, described in the comments to Pattern
interface,
section "Coordinate restrictions", and in the comments to UniformGridPattern
interface,
section "Coordinate restrictions" (for example, due to very large shift).
Note: the similar results can be got with help of UniformGridPattern.shift(Point)
method
with a corresponding floatingpoint shift. However, this method
guarantees that the returned pattern has the same origin of the grid, but corrected grid indexes.
Unlike this, a good implementation of UniformGridPattern.shift(Point)
method just corrects the grid origin,
but does not change grid indexes. This difference is important, if you are going to get
the grid indexes from the shifted pattern via UniformGridPattern.gridIndexPattern()
or UniformGridPattern.gridIndexes()
method.
shiftGridIndexes
in interface UniformGridPattern
shift
 the shift of the grid indexes.RectangularPattern lowerSurface(int coordIndex)
UniformGridPattern
stepOfGrid(coordIndex)
dimCount()
) is the same as in this one.
In other words, the point
Please compare with UniformGridPattern.minBound(int)
method. This method can return a pattern
containing more points than UniformGridPattern.minBound(int)
, in particular, if this pattern contains some "holes".
The returned pattern always implements DirectPointSetPattern
if this pattern implements DirectPointSetPattern
The returned pattern always implements RectangularPattern
if this pattern implements RectangularPattern
.
Note: if this object is not DirectPointSetPattern
and is not RectangularPattern
, this method can work slowly for some large patterns:
the required time can be O(N), where N is the number of points.
In these cases, this method can also throw TooManyPointsInPatternError
or OutOfMemoryError. The situation is like in Pattern.points()
and Pattern.roundedPoints()
method.
However, this situation is possible only in custom implementation of this interface —
all implementations, provided by this package, implement either DirectPointSetPattern
or RectangularPattern
interface.
There is a guarantee, that if this object implements DirectPointSetPattern
interface,
then this method requires not greater than O(N) memory
(N=pointCount()
)
and never throws TooManyPointsInPatternError
.
There is a guarantee, that if this object implements RectangularPattern
interface,
then this method works quickly (O(1) operations) and without exceptions.
lowerSurface
in interface UniformGridPattern
coordIndex
 the index of the coordinate (0 for x, 1 for y, 2 for z, etc.)RectangularPattern upperSurface(int coordIndex)
UniformGridPattern
stepOfGrid(coordIndex)
dimCount()
) is the same as in this one.
In other words, the point
Please compare with UniformGridPattern.maxBound(int)
method. This method can return a pattern
containing more points than UniformGridPattern.maxBound(int)
, in particular, if this pattern contains some "holes".
The returned pattern always implements DirectPointSetPattern
if this pattern implements DirectPointSetPattern
The returned pattern always implements RectangularPattern
if this pattern implements RectangularPattern
.
Note: if this object is not DirectPointSetPattern
and is not RectangularPattern
, this method can work slowly for some large patterns:
the required time can be O(N), where N is the number of points.
In these cases, this method can also throw TooManyPointsInPatternError
or OutOfMemoryError. The situation is like in Pattern.points()
and Pattern.roundedPoints()
method.
However, this situation is possible only in custom implementation of this interface —
all implementations, provided by this package, implement either DirectPointSetPattern
or RectangularPattern
interface.
There is a guarantee, that if this object implements DirectPointSetPattern
interface,
then this method requires not greater than O(N) memory
(N=pointCount()
)
and never throws TooManyPointsInPatternError
.
There is a guarantee, that if this object implements RectangularPattern
interface,
then this method works quickly (O(1) operations) and without exceptions.
upperSurface
in interface UniformGridPattern
coordIndex
 the index of the coordinate (0 for x, 1 for y, 2 for z, etc.)