Class AbstractUniformGridPattern
- All Implemented Interfaces:
Pattern,UniformGridPattern
A skeletal implementation of the UniformGridPattern interface to minimize
the effort required to implement this interface.
All non-abstract methods are completely implemented here and may be not overridden in subclasses.
- Author:
- Daniel Alievsky
-
Field Summary
Fields inherited from class net.algart.math.patterns.AbstractPattern
dimCountFields inherited from interface net.algart.math.patterns.Pattern
MAX_COORDINATE -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractUniformGridPattern(Point originOfGrid, double[] stepsOfGrid, boolean trivialUnionDecomposition) Creates a uniform grid pattern with the given origin and steps of the grid. -
Method Summary
Modifier and TypeMethodDescriptionallUnionDecompositions(int minimalPointCount) This implementation uses a common algorithm that usually provide good results.carcass()//TODO!! - that it checks isActuallyRectangular() This method is fully implemented in this class and usually should not be overridden.coordRange(int coordIndex) Returns the minimal and maximal coordinate with the given index (Point.coord(coordIndex)) among all points of this pattern.This implementation is based on the loop of calls ofgridIndexRange(int)method for all coordinate indexes from 0 toAbstractPattern.dimCount()-1.Returns a set of all grid indexes ij of this pattern.This implementation is based on the loop of calls ofgridIndexRange(int)method for all coordinate indexes from 0 toAbstractPattern.dimCount()-1.This implementation is based on the loop of calls ofgridIndexRange(int)method for all coordinate indexes from 0 toAbstractPattern.dimCount()-1.abstract UniformGridPatternReturns anordinaryinteger pattern with the same set of grid indexes ij(k) as this pattern.abstract IRangegridIndexRange(int coordIndex) Returns the minimal and maximal grid index ij among all points of this pattern for the specified coordinate index j==coordIndex.protected StringbooleanThis implementation returnsminkowskiDecomposition(0).size()>1.booleanThis implementation returns true if and only ifpointCount()=r0r1...<Long.MAX_VALUE, where ri=gridIndexRange(i).size().static booleanisAllowedGridIndex(IPoint gridIndex) static booleanisAllowedGridIndexRange(IRange gridIndexRange) final booleanReturns true if and only if this uniform-grid pattern is an ordinary integer pattern, i.e. if the grid origin o is the origin of coordinates (0,0,...,0) and all grid steps dj are 1.0.booleanThis implementation callsAbstractPattern.points()method and checks, whether all returned points are integer, i.e.Point.isInteger()method returns true for all elements the returned set.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 stepdj= , does not belong to this pattern.stepOfGrid(coordIndex)maxBound(int coordIndex) This implementation callsAbstractPattern.points()method and builds the result on the base of analysis of the returned point set.int//TODO!! - write that it checks isActuallyRectangular() This method is fully implemented in this class and usually should not be overridden.minBound(int coordIndex) This implementation callsAbstractPattern.points()method and builds the result on the base of analysis of the returned point set.minkowskiAdd(Pattern added) This implementation is based on the loop on all points returned byroundedPoints()method in both patterns and always returns thesimple patternconsisting of sums of all point pairs.minkowskiDecomposition(int minimalPointCount) This implementation returns Collections.<Pattern>singletonList(thisInstance) for non-rectangular patterns or a good decomposition ifisActuallyRectangular()method returns true.minkowskiSubtract(Pattern subtracted) This implementation is based on the loop on all points returned byroundedPoints()method in both patterns and always returns thesimple patternconsisting of sums of all point pairs.multiply(double multiplier) This implementation creates Java array double[] by the call "a = new double[ ", fills all its elements by multiplier argument and then callsAbstractPattern.dimCount]scale(a).This implementation returns the grid origin, specified in the constructor.abstract longReturns the number of points in this pattern.points()Returns a set of all points of this pattern.abstract UniformGridPatternprojectionAlongAxis(int coordIndex) Returns the projection of this pattern along the given axis.round()This implementation callsAbstractPattern.roundedPoints()method and constructs a new integer pattern on the base of this set, like as it is performed inPatterns.newIntegerPattern(java.util.Collection)method.This implementation callsAbstractPattern.points()method and returns a new set, built from the returned set of real points by conversion of every point to an integer point viaPoint.toRoundedPoint()method, as written incomments to this method in Pattern interface.abstract UniformGridPatternscale(double... multipliers) Returns this pattern, scaled by the specified multipliers along all coordinates.abstract UniformGridPatternReturns this pattern, shifted by the argument.abstract UniformGridPatternshiftGridIndexes(IPoint shift) Returns another uniform-grid pattern, identical to this one with the only difference, that the grid indexi(k) = (i0(k), i1(k), ..., in−1(k)) for each point #k of the result is shifted by the argument of this method via the call i(k).add(shift).doublestepOfGrid(int coordIndex) Returns the grid step dj along the coordinate #j of this pattern along the coordinate #j=coordIndex.double[]This implementation returns a new copy of Java array of grid steps, specified in the constructor.booleanstepsOfGridEqual(UniformGridPattern pattern) Indicates whether the other uniform-grid pattern has the same grid steps.surface()Returns the set-theoretical union of all patterns, returned byUniformGridPattern.lowerSurface(int)UniformGridPattern.upperSurface(int)methods for all coordinates.This implementation callsmultiply(-1.0).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 stepdj= , does not belong to this pattern.stepOfGrid(coordIndex)Methods inherited from class net.algart.math.patterns.AbstractPattern
checkCoordIndex, coordArea, coordMax, coordMin, dimCount, isAllowedCoordRange, isAllowedPoint, isPointCountVeryLarge, isSurelyOriginPoint, isSurelySinglePoint, largePointCount, roundedCoordArea, roundedCoordRange, unionDecompositionMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.algart.math.patterns.Pattern
coordArea, coordMax, coordMin, dimCount, isSurelyOriginPoint, isSurelySinglePoint, largePointCount, roundedCoordArea, roundedCoordRange, unionDecomposition
-
Constructor Details
-
AbstractUniformGridPattern
protected AbstractUniformGridPattern(Point originOfGrid, double[] stepsOfGrid, boolean trivialUnionDecomposition) Creates a uniform grid pattern with the given origin and steps of the grid.The trivialUnionDecomposition determines behavior of
AbstractPattern.unionDecomposition(int)andallUnionDecompositions(int)methods. If it is false, they will perform some common algorithm suitable for most patterns, that have no good Minkowski decompositions (alike spheres). If it is true, they will return degenerated decomposition consisting of this pattern as the only element. You should use true argument in inheritors that have a good Minkowski decomposition.The passed stepsOfGrid argument is cloned by this method: no references to it are maintained by the created pattern.
- Parameters:
originOfGrid- theorigin of the grid.stepsOfGrid- thesteps of the grid.trivialUnionDecomposition- whether this pattern has the degenerated union decomposition.- Throws:
NullPointerException- if originOfGrid or stepsOfGrid argument is null.IllegalArgumentException- if originOfGrid.coordCount()!=stepsOfGrid.length, or if one of the passed steps is zero (==0.0).
-
-
Method Details
-
originOfGrid
This implementation returns the grid origin, specified in the constructor.- Specified by:
originOfGridin interfaceUniformGridPattern- Returns:
- the origin o of the uniform grid of this pattern.
-
stepsOfGrid
public double[] stepsOfGrid()This implementation returns a new copy of Java array of grid steps, specified in the constructor.- Specified by:
stepsOfGridin interfaceUniformGridPattern- Returns:
- an array containing all grid steps of this pattern.
-
stepOfGrid
public double stepOfGrid(int coordIndex) Description copied from interface:UniformGridPatternReturns the grid step dj along the coordinate #j of this pattern along the coordinate #j=coordIndex. Equivalent toUniformGridPattern.stepsOfGrid()[coordIndex], but works faster.There is a guarantee, that this method always works very quickly (maximally O(
dimCount()) operations) and without exceptions.- Specified by:
stepOfGridin interfaceUniformGridPattern- Returns:
- the grid step of this pattern along the specified coordinate axis.
-
stepsOfGridEqual
Description copied from interface:UniformGridPatternIndicates whether the other uniform-grid pattern has the same grid steps. In other words, returns true if and only if both patterns have the same dimension count (dimCount()) and the corresponding grid stepsstepOfGrid((k)are equal for every k.Note: this method does not compare the origin of grid.
Equality of grid steps is important, for example, while calculation of a Minkowski sum of this and another patterns by
Pattern.minkowskiAdd(Pattern)method. If two uniform-grid patterns have identical grid steps, then a Minkowski sum of them can be also represented by uniform-grid pattern (with same grid steps). In other case, it is usually impossible — the Minkowski sum, returned byPattern.minkowskiAdd(Pattern), will not implementUniformGridPattern.- Specified by:
stepsOfGridEqualin interfaceUniformGridPattern- Parameters:
pattern- another uniform-grid pattern, the grid steps of which should be compared with grid steps of this one.- Returns:
- true if the specified pattern has the same steps of grid.
-
gridIndexes
Description copied from interface:UniformGridPatternReturns a set of all grid indexes ij of this pattern. Namely, the elements of the returned set contain grid indexesi(k) = (i0(k), i1(k), ..., in−1(k)) of all pointsx(k) = (x0(k), x1(k), ..., xn−1(k)) of this pattern:x0(k) = o0 + i0(k)d0
x1(k) = o1 + i1(k)d1
. . .
xn−1(k) = on−1 + in−1(k)dn−1The result of this method is immutable (Collections.unmodifiableSet). Moreover, the result is always the same for different calls of this method for the same instance — there are no ways to change it, in particular, via any custom methods of the implementation class (it is a conclusion from the common requirement, that all implementations of
Patterninterface must be immutable).The returned set is always non-empty, and the number of its elements is always equal to
Pattern.pointCount().Warning! This method can work slowly for some forms of large patterns. In these cases, this method can also throw
TooManyPointsInPatternErroror OutOfMemoryError. This method surely fails (throws one of these exception), if the total number of pointsPattern.pointCount()>Integer.MAX_VALUE, because Java Set object cannot contain more than Integer.MAX_VALUE elements.For example, implementations of the
rectangular patternsallow to successfully define a very large 3D parallelepipedn x n x n . Fur such pattern, this method will require a lot of memory for n=1000 and will fail (probably withTooManyPointsInPatternError) for n=2000 (20003>Integer.MAX_VALUE).There is a guarantee, that if this object implements
DirectPointSetPatterninterface, then this method requires not greater than O(N) operations and memory (N=pointCount()) and never throwsTooManyPointsInPatternError.Note: if you do not really need to get a Java collection of all grid indexes, you can use
UniformGridPattern.gridIndexPattern()method, which returns the same result in a form of another (integer) pattern. That method, unlike this one, never spends extreme amount of memory and time and has no risk to fail withTooManyPointsInPatternError/ OutOfMemoryError.- Specified by:
gridIndexesin interfaceUniformGridPattern- Returns:
- all grid indexes of this pattern.
- See Also:
-
gridIndexRange
Description copied from interface:UniformGridPatternReturns the minimal and maximal grid index ij among all points of this pattern for the specified coordinate index j==coordIndex. The minimal grid index will be r.min(), the maximal grid index will be r.max(), where r is the result of this method. See thecomments to this interfacefor more details.There is a guarantee, that if this object implements
RectangularPatterninterface, then this method works very quickly (O(1) operations) and without exceptions.Moreover, all patterns, implemented in this package, have very quick implementations of this method (O(1) operations). Also, the implementations of this method in this package never throw exceptions.
It is theoretically possible, that in custom implementations of this interface (outside this package) this method will work slowly, up to O(N) operations, N is the number of points in this pattern. However, even in such implementations this method must not lead to
TooManyPointsInPatternError/ OutOfMemoryError, likePattern.points()method.- Specified by:
gridIndexRangein interfaceUniformGridPattern- Parameters:
coordIndex- the index j of the coordinate (0 for x, 1 for y, 2 for z, etc.).- Returns:
- the range from minimal to maximal grid index ij.
- See Also:
-
gridIndexArea
This implementation is based on the loop of calls ofgridIndexRange(int)method for all coordinate indexes from 0 toAbstractPattern.dimCount()-1.- Specified by:
gridIndexAreain interfaceUniformGridPattern- Returns:
- the ranges from minimal to maximal coordinate for all space dimensions.
-
gridIndexMin
This implementation is based on the loop of calls ofgridIndexRange(int)method for all coordinate indexes from 0 toAbstractPattern.dimCount()-1.- Specified by:
gridIndexMinin interfaceUniformGridPattern- Returns:
- minimal grid index for all space dimensions as a point.
-
gridIndexMax
This implementation is based on the loop of calls ofgridIndexRange(int)method for all coordinate indexes from 0 toAbstractPattern.dimCount()-1.- Specified by:
gridIndexMaxin interfaceUniformGridPattern- Returns:
- maximal grid index for all space dimensions as a point.
-
isOrdinary
public final boolean isOrdinary()Description copied from interface:UniformGridPatternReturns true if and only if this uniform-grid pattern is an ordinary integer pattern, i.e. if the grid origin o is the origin of coordinates (0,0,...,0) and all grid steps dj are 1.0. Equivalent toUniformGridPattern.originOfGrid().isOrigin()&&gridIndexRange(0)==1.0 &&gridIndexRange(1)==1.0 && ... Ordinary integer patterns are a simplest form of integer pattern: see comments toPatterninterface, section "Uniform-grid patterns".There is a guarantee, that this method always works very quickly (maximally O(
dimCount()) operations) and without exceptions.- Specified by:
isOrdinaryin interfaceUniformGridPattern- Returns:
- whether the grid origin o=(0,0,...,0) and also all grid steps dj=1.0.
-
isActuallyRectangular
public boolean isActuallyRectangular()This implementation returns true if and only ifpointCount()=r0r1...<Long.MAX_VALUE, where ri=gridIndexRange(i).size().This method caches its results: the following calls will work faster.
This method does not provide correct result, if a pattern contains ≥Long.MAX_VALUE points.
This method should be overridden for rectangular patterns, implementing
RectangularPatterninterface, or for patterns that surely are not rectangular.- Specified by:
isActuallyRectangularin interfaceUniformGridPattern- Returns:
- true if this pattern is n-dimensional rectangular parallelepiped.
-
gridIndexPattern
Description copied from interface:UniformGridPatternReturns anordinaryinteger pattern with the same set of grid indexes ij(k) as this pattern. In other words, if this pattern is a set of pointsx0(k) = o0 + i0(k)d0
x1(k) = o1 + i1(k)d1
. . .
xn−1(k) = on−1 + in−1(k)dn−1(k=0,1,...,N−1, n=
dimCount()), then the returned pattern consists of pointsy0(k) = (double)i0(k)
y1(k) = (double)i1(k)
. . .
yn−1(k) = (double)in−1(k)Note: here is a guarantee, that all grid indexes ij 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 toPattern.MAX_COORDINATEand the section "Grid index restrictions" in the comments toUniformGridPatterninterface.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 ofUniformGridPattern.gridIndexes()method.The returned pattern always implements
DirectPointSetPatternif this pattern implementsDirectPointSetPattern.The returned pattern always implements
RectangularPatternif this pattern implementsRectangularPattern.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()).- Specified by:
gridIndexPatternin interfaceUniformGridPattern- Returns:
- an ordinary integer pattern, consisting of all grid indexes of this pattern (represented by double values).
- See Also:
-
shiftGridIndexes
Description copied from interface:UniformGridPatternReturns another uniform-grid pattern, identical to this one with the only difference, that the grid indexi(k) = (i0(k), i1(k), ..., in−1(k)) for each point #k of the result is shifted by the argument of this method via the call i(k).add(shift). In other words, if this pattern is a set of pointsx0(k) = o0 + i0(k)d0
x1(k) = o1 + i1(k)d1
. . .
xn−1(k) = on−1 + in−1(k)dn−1(k=0,1,...,N−1, n=
dimCount()), then the returned pattern has the samegrid oridin, the samegrid stepsand consists of pointsy0(k) = o0 + (i0(k)+shift.
coord(0))*d0
y1(k) = o1 + (i1(k)+shift.coord(1))*d1
. . .
yn−1(k) = on−1 + (in−1(k)+shift.coord(n−1))*dn−1The returned pattern always implements
DirectPointSetPatternif this pattern implementsDirectPointSetPatternThe returned pattern always implements
RectangularPatternif this pattern implementsRectangularPattern.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 viaUniformGridPattern.gridIndexes()call, correcting them and forming a new pattern viaPatterns.newUniformGridPattern(Point, double[], java.util.Collection)will lead toTooManyPointsInPatternError/ 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 toPatterninterface, section "Coordinate restrictions", and in the comments toUniformGridPatterninterface, 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 floating-point 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 ofUniformGridPattern.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 viaUniformGridPattern.gridIndexPattern()orUniformGridPattern.gridIndexes()method.- Specified by:
shiftGridIndexesin interfaceUniformGridPattern- Parameters:
shift- the shift of the grid indexes.- Returns:
- the shifted pattern.
-
lowerSurface
Description copied from interface:UniformGridPatternReturns 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 stepdj= , does not belong to this pattern. The number of dimensions in the resulting pattern (stepOfGrid(coordIndex)dimCount()) is the same as in this one.In other words, the point
A = (x0, x1, ..., xj, ..., xn−1) belongs to the returned pattern if and only if it belongs to this pattern and the pointB = (x0, x1, ..., xj−dj, ..., xn−1) (corresponding to decreasing the grid index ij by 1) does not belong to this pattern.Please compare with
UniformGridPattern.minBound(int)method. This method can return a pattern containing more points thanUniformGridPattern.minBound(int), in particular, if this pattern contains some "holes".The returned pattern always implements
DirectPointSetPatternif this pattern implementsDirectPointSetPatternThe returned pattern always implements
RectangularPatternif this pattern implementsRectangularPattern.Note: if this object is not
DirectPointSetPatternand is notRectangularPattern, 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 throwTooManyPointsInPatternErroror OutOfMemoryError. The situation is like inPattern.points()andPattern.roundedPoints()method. However, this situation is possible only in custom implementation of this interface — all implementations, provided by this package, implement eitherDirectPointSetPatternorRectangularPatterninterface.There is a guarantee, that if this object implements
DirectPointSetPatterninterface, then this method requires not greater than O(N) memory (N=pointCount()) and never throwsTooManyPointsInPatternError.There is a guarantee, that if this object implements
RectangularPatterninterface, then this method works quickly (O(1) operations) and without exceptions.- Specified by:
lowerSurfacein interfaceUniformGridPattern- Parameters:
coordIndex- the index of the coordinate (0 for x, 1 for y, 2 for z, etc.)- Returns:
- the "lower boundary" of this pattern: new pattern consisting of all points of this pattern, which have no leftward neighbour along the given coordinate.
-
upperSurface
Description copied from interface:UniformGridPatternReturns 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 stepdj= , does not belong to this pattern. The number of dimensions in the resulting pattern (stepOfGrid(coordIndex)dimCount()) is the same as in this one.In other words, the point
A = (x0, x1, ..., xj, ..., xn−1) belongs to the returned pattern if and only if it belongs to this pattern and the pointB = (x0, x1, ..., xj+dj, ..., xn−1) (corresponding to increasing the grid index ij by 1) does not belong to this pattern.Please compare with
UniformGridPattern.maxBound(int)method. This method can return a pattern containing more points thanUniformGridPattern.maxBound(int), in particular, if this pattern contains some "holes".The returned pattern always implements
DirectPointSetPatternif this pattern implementsDirectPointSetPatternThe returned pattern always implements
RectangularPatternif this pattern implementsRectangularPattern.Note: if this object is not
DirectPointSetPatternand is notRectangularPattern, 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 throwTooManyPointsInPatternErroror OutOfMemoryError. The situation is like inPattern.points()andPattern.roundedPoints()method. However, this situation is possible only in custom implementation of this interface — all implementations, provided by this package, implement eitherDirectPointSetPatternorRectangularPatterninterface.There is a guarantee, that if this object implements
DirectPointSetPatterninterface, then this method requires not greater than O(N) memory (N=pointCount()) and never throwsTooManyPointsInPatternError.There is a guarantee, that if this object implements
RectangularPatterninterface, then this method works quickly (O(1) operations) and without exceptions.- Specified by:
upperSurfacein interfaceUniformGridPattern- Parameters:
coordIndex- the index of the coordinate (0 for x, 1 for y, 2 for z, etc.)- Returns:
- the "upper boundary" of this pattern: new pattern consisting of all points of this pattern, which have no rightward neighbour along the given coordinate.
-
surface
Description copied from interface:UniformGridPatternReturns the set-theoretical union of all patterns, returned byUniformGridPattern.lowerSurface(int)UniformGridPattern.upperSurface(int)methods for all coordinates. In other words, the returned pattern contains full "boundary" of this pattern. The number of dimensions in the resulting pattern (dimCount()) is the same as in this one.Note: if this object is not
DirectPointSetPatternand is notRectangularPattern, 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 throwTooManyPointsInPatternErroror OutOfMemoryError. The situation is like inPattern.points()andPattern.roundedPoints()method. However, this situation is possible only in custom implementation of this interface — all implementations, provided by this package, implement eitherDirectPointSetPatternorRectangularPatterninterface.- Specified by:
surfacein interfaceUniformGridPattern- Returns:
- the "boundary" of this pattern: new pattern consisting of all points of this pattern, which have no leftward or rightward neighbour along at least one coordinate.
-
pointCount
public abstract long pointCount()Description copied from interface:PatternReturns the number of points in this pattern. This value is always positive (>=1). If the number of points is greater than Long.MAX_VALUE, returns Long.MAX_VALUE.Warning! This method can work slowly for some forms of large patterns: the required time can be O(N), where N is the number of points (result of this method). In these cases, this method can also throw
TooManyPointsInPatternErroror OutOfMemoryError.There is a guarantee, that if this object implements
QuickPointCountPatterninterface, then this method works very quickly (O(1) operations) and without exceptions.There is a guarantee, that if this object implements
DirectPointSetPatterninterface, then the result of this method is not greater than Integer.MAX_VALUE.Note: if this method returns some value greater than Integer.MAX_VALUE, it means that you cannot use
Pattern.points()andPattern.roundedPoints()methods, because Java Set object cannot contain more than Integer.MAX_VALUE elements.- Specified by:
pointCountin interfacePattern- Specified by:
pointCountin classAbstractPattern- Returns:
- the number of
pointsin this pattern. - See Also:
-
points
Description copied from interface:PatternReturns a set of all points of this pattern.The result of this method is immutable (Collections.unmodifiableSet). Moreover, the result is always the same for different calls of this method for the same instance — there are no ways to change it, in particular, via any custom methods of the implementation class (it is a conclusion from the common requirement, that all implementations of this interface must be immutable).
The returned set is always non-empty, and the number of its elements is always equal to
Pattern.pointCount().Warning! This method can work slowly for some forms of large patterns. In these cases, this method can also throw
TooManyPointsInPatternErroror OutOfMemoryError. This method surely fails (throws one of these exception), if the total number of pointsPattern.pointCount()>Integer.MAX_VALUE, because Java Set object cannot contain more than Integer.MAX_VALUE elements.For example, implementations of the
rectangular patternsallow to successfully define a very large 3D parallelepipedn x n x n . Fur such pattern, this method will require a lot of memory for n=1000 and will fail (probably withTooManyPointsInPatternError) for n=2000 (20003>Integer.MAX_VALUE).There is a guarantee, that if this object implements
DirectPointSetPatterninterface, then this method requires not greater than O(N) operations and memory (N=pointCount()) and never throwsTooManyPointsInPatternError.Note: this method works very quickly (O(1) operations) in
SimplePatternclass.- Specified by:
pointsin interfacePattern- Specified by:
pointsin classAbstractPattern- Returns:
- all points of this pattern.
-
roundedPoints
Description copied from class:AbstractPatternThis implementation callsAbstractPattern.points()method and returns a new set, built from the returned set of real points by conversion of every point to an integer point viaPoint.toRoundedPoint()method, as written incomments to this method in Pattern interface. Please override this method if there is more efficient way to get all rounded points.- Specified by:
roundedPointsin interfacePattern- Overrides:
roundedPointsin classAbstractPattern- Returns:
- all points of this pattern, rounded to the nearest integer points.
-
coordRange
Description copied from interface:PatternReturns the minimal and maximal coordinate with the given index (Point.coord(coordIndex)) among all points of this pattern. The minimal coordinate will be r.min(), the maximal coordinate will be r.max(), where r is the result of this method.There is a guarantee, that if this object implements
RectangularPatterninterface, then this method works very quickly (O(1) operations) and without exceptions.Moreover, all patterns, implemented in this package, have very quick implementations of this method (O(1) operations). Also, the implementations of this method in this package never throw exceptions.
It is theoretically possible, that in custom implementations of this interface (outside this package) this method will work slowly, up to O(N) operations, N is the number of points in this pattern. However, even in such implementations this method must not lead to
TooManyPointsInPatternError/ OutOfMemoryError, likePattern.points()method.- Specified by:
coordRangein interfacePattern- Specified by:
coordRangein classAbstractPattern- Parameters:
coordIndex- the index of the coordinate (0 for x, 1 for y, 2 for z, etc.).- Returns:
- the range from minimal to maximal coordinate with this index.
- See Also:
-
isSurelyInteger
public boolean isSurelyInteger()Description copied from class:AbstractPatternThis implementation callsAbstractPattern.points()method and checks, whether all returned points are integer, i.e.Point.isInteger()method returns true for all elements the returned set. If all points, returned byAbstractPattern.points()call, are integer, this method returns true, in other case it returns false.This method caches its results: the following calls will work faster.
Note: according the
comments to this method in Pattern interface, such implementation is correct only ifAbstractPattern.minkowskiDecomposition(int),AbstractPattern.unionDecomposition(int)andAbstractPattern.allUnionDecompositions(int)methods have default implementations (not overridden). If some of them are overridden and return some non-trivial results, this method must be also overridden.Note: according the
comments to this method in Pattern interface, this method must be overridden if the number of points can be very large and a call ofAbstractPattern.points()method leads to a risk ofTooManyPointsInPatternError/ OutOfMemoryError. In particular, this method should be usually overridden in implementations ofRectangularPattern.- Specified by:
isSurelyIntegerin interfacePattern- Overrides:
isSurelyIntegerin classAbstractPattern- Returns:
- true if this pattern assuredly contain only
integerpoints.
-
round
Description copied from class:AbstractPatternThis implementation callsAbstractPattern.roundedPoints()method and constructs a new integer pattern on the base of this set, like as it is performed inPatterns.newIntegerPattern(java.util.Collection)method. Please override this method if there is more efficient way to round this pattern, for example, if this pattern is already an integer one.- Specified by:
roundin interfacePattern- Overrides:
roundin classAbstractPattern- Returns:
- the integer pattern, geometrically nearest to this one.
-
projectionAlongAxis
Description copied from interface:PatternReturns the projection of this pattern along the given axis. The number of dimensions in the resulting 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
DirectPointSetPatternif this pattern implementsDirectPointSetPatternThe returned pattern always implements
RectangularPatternif this pattern implementsRectangularPattern.The returned pattern always implements
UniformGridPatternif this pattern implementsUniformGridPattern.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 viaPatterns.newPattern(java.util.Collection)will lead toTooManyPointsInPatternError/ OutOfMemoryError for some forms of large patterns.- Specified by:
projectionAlongAxisin interfacePattern- Specified by:
projectionAlongAxisin interfaceUniformGridPattern- Specified by:
projectionAlongAxisin classAbstractPattern- Parameters:
coordIndex- the index of the coordinate (0 for x-axis , 1 for y-axis, 2 for za-xis, etc.).- Returns:
- the projection of this pattern (its
Pattern.dimCount()is equal to thisInstance.Pattern.dimCount()-1).
-
minBound
Description copied from class:AbstractPatternThis implementation callsAbstractPattern.points()method and builds the result on the base of analysis of the returned point set. Please override this method if there is more efficient way to find the result, for example, if this pattern is a rectangular one.- Specified by:
minBoundin interfacePattern- Specified by:
minBoundin interfaceUniformGridPattern- Overrides:
minBoundin classAbstractPattern- Parameters:
coordIndex- the index of the coordinate (0 for x-axis , 1 for y-axis, 2 for za-xis, etc.).- Returns:
- the minimal boundary of this pattern for the given axis.
- See Also:
-
maxBound
Description copied from class:AbstractPatternThis implementation callsAbstractPattern.points()method and builds the result on the base of analysis of the returned point set. Please override this method if there is more efficient way to find the result, for example, if this pattern is a rectangular one.- Specified by:
maxBoundin interfacePattern- Specified by:
maxBoundin interfaceUniformGridPattern- Overrides:
maxBoundin classAbstractPattern- Parameters:
coordIndex- the index of the coordinate (0 for x-axis , 1 for y-axis, 2 for za-xis, etc.).- Returns:
- the maximal boundary of this pattern for the given axis.
- See Also:
-
carcass
//TODO!! - that it checks isActuallyRectangular() This method is fully implemented in this class and usually should not be overridden. If you override it, you must overridemaxCarcassMultiplier()also, because that method returns the private field calculated by this one.- Specified by:
carcassin interfacePattern- Specified by:
carcassin interfaceUniformGridPattern- Overrides:
carcassin classAbstractPattern- Returns:
- the carcass of this pattern.
-
maxCarcassMultiplier
public int maxCarcassMultiplier()//TODO!! - write that it checks isActuallyRectangular() This method is fully implemented in this class and usually should not be overridden.- Specified by:
maxCarcassMultiplierin interfacePattern- Overrides:
maxCarcassMultiplierin classAbstractPattern- Returns:
- the maximal multiplier, for which the calculation of the Minkowski multiple can be optimized
by using the
carcass.
-
shift
Description copied from interface:PatternReturns this pattern, shifted by the argument.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
DirectPointSetPatternif this pattern implementsDirectPointSetPatternThe returned pattern always implements
RectangularPatternif this pattern implementsRectangularPattern.The returned pattern always implements
UniformGridPatternif this pattern implementsUniformGridPattern.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 viaPatterns.newPattern(java.util.Collection)will lead toTooManyPointsInPatternError/ OutOfMemoryError for some forms of large patterns.Warning: this method can fail with
TooLargePatternCoordinatesException, if some of new points violate restrictions, described in thecomments to this interface, section "Coordinate restrictions" (for example, due to very large shift).However,
TooLargePatternCoordinatesExceptionis impossible in many important cases, when this pattern is an integer pattern and each coordinateXj=shift. of the argument is equal to −xj for some some pointcoord(j)(x0, x1, ..., xn−1) of this pattern. In particular, you can use this method for integer patterns without a risk ofTooLargePatternCoordinatesExceptionin the following situations:- shift is thisIntegerPattern.
coordMin().symmetric(), - shift is thisIntegerPattern.
coordMax().symmetric(), - shift is p.
symmetric(), where p is some of thepointsif this integer pattern.
See more details in the
comments to this interface, section "Coordinate restrictions", the theorem II.- Specified by:
shiftin interfacePattern- Specified by:
shiftin interfaceUniformGridPattern- Specified by:
shiftin classAbstractPattern- Parameters:
shift- the shift.- Returns:
- the shifted pattern.
- shift is thisIntegerPattern.
-
symmetric
Description copied from class:AbstractPatternThis implementation callsmultiply(-1.0). There are no reasons to override this method usually.- Specified by:
symmetricin interfacePattern- Specified by:
symmetricin interfaceUniformGridPattern- Overrides:
symmetricin classAbstractPattern- Returns:
- the symmetric pattern.
-
multiply
Description copied from class:AbstractPatternThis implementation creates Java array double[] by the call "a = new double[ ", fills all its elements by multiplier argument and then callsAbstractPattern.dimCount]scale(a). There are no reasons to override this method usually.- Specified by:
multiplyin interfacePattern- Specified by:
multiplyin interfaceUniformGridPattern- Overrides:
multiplyin classAbstractPattern- Parameters:
multiplier- the scale along all coordinates.- Returns:
- the scaled pattern.
- See Also:
-
scale
Description copied from interface:PatternReturns this pattern, scaled by the specified multipliers along all coordinates.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
DirectPointSetPatternif this pattern implementsDirectPointSetPatternThe returned pattern always implements
RectangularPatternif this pattern implementsRectangularPattern.The returned pattern always implements
UniformGridPatternif this pattern implementsUniformGridPattern.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 viaPatterns.newPattern(java.util.Collection)will lead toTooManyPointsInPatternError/ OutOfMemoryError for some forms of large patterns.Warning: this method can fail with
TooLargePatternCoordinatesException, if some of new points violate restrictions, described in thecomments 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.- Specified by:
scalein interfacePattern- Specified by:
scalein interfaceUniformGridPattern- Specified by:
scalein classAbstractPattern- Parameters:
multipliers- the scales along coordinates.- Returns:
- the scaled pattern.
- See Also:
-
minkowskiAdd
This implementation is based on the loop on all points returned byroundedPoints()method in both patterns and always returns thesimple patternconsisting of sums of all point pairs. This algorithm may be very slow for large patterns (O(NM) operations, N=pointCount(), M=added.pointCount()) and does not work at all if the number of resulting points is greater than Integer.MAX_VALUE. Please override this method if there is better implementation.- Specified by:
minkowskiAddin interfacePattern- Overrides:
minkowskiAddin classAbstractPattern- Parameters:
added- another pattern.- Returns:
- the Minkowski sum of this and another patterns.
- Throws:
NullPointerException- if the argument is null.IllegalArgumentException- if the numbers of space dimensions of both patterns are different.- See Also:
-
minkowskiSubtract
This implementation is based on the loop on all points returned byroundedPoints()method in both patterns and always returns thesimple patternconsisting of sums of all point pairs. This algorithm may be very slow for large patterns (O(NM) operations, N=pointCount(), M=added.pointCount()) and does not work at all if the number of resulting points is greater than Integer.MAX_VALUE. Please override this method if there is better implementation.- Specified by:
minkowskiSubtractin interfacePattern- Overrides:
minkowskiSubtractin classAbstractPattern- Parameters:
subtracted- another pattern.- Returns:
- the erosion of this pattern by the specified pattern or null if this erosion is the empty set.
- Throws:
NullPointerException- if the argument is null.IllegalArgumentException- if the numbers of space dimensions of both patterns are different.- See Also:
-
minkowskiDecomposition
This implementation returns Collections.<Pattern>singletonList(thisInstance) for non-rectangular patterns or a good decomposition ifisActuallyRectangular()method returns true. This method caches its results for several little values of the argument: the following calls will work faster. Please override this method if there is better implementation.- Specified by:
minkowskiDecompositionin interfacePattern- Overrides:
minkowskiDecompositionin classAbstractPattern- Parameters:
minimalPointCount- this method does not try to decompose patterns that contain less than minimalPointCount points. In particular, if the minkowski sum of several patterns containing less than minimalPointCount points, this method should return this sum in the resulting list instead of its summands.- Returns:
- the decomposition of this pattern to Minkowski sum.
- Throws:
IllegalArgumentException- if the argument is negative.
-
hasMinkowskiDecomposition
public boolean hasMinkowskiDecomposition()This implementation returnsminkowskiDecomposition(0).size()>1. Please override this method ifminkowskiDecomposition(int)method works slowly and it's possible to know, whether the pattern has Minkowski decomposition, much faster.- Specified by:
hasMinkowskiDecompositionin interfacePattern- Overrides:
hasMinkowskiDecompositionin classAbstractPattern- Returns:
- true if the Minkowski decomposition contains 2 or more elements.
-
allUnionDecompositions
This implementation uses a common algorithm that usually provide good results. This method caches its results for several little values of the argument: the following calls will work faster. Please override this method if the better implementation is known.- Specified by:
allUnionDecompositionsin interfacePattern- Overrides:
allUnionDecompositionsin classAbstractPattern- Parameters:
minimalPointCount- the minimal number of points in every pattern in all resulting decompositions: all pattern containing less points should be joined into one element of the resulting list.- Returns:
- several good variants of decomposition of this pattern to the union of patterns.
- Throws:
IllegalArgumentException- if the argument is negative.
-
isAllowedGridIndex
-
isAllowedGridIndexRange
-
gridToString
-