Class IRectangularArea
Rectangular integer area, i.e.
hyperparallelepiped in multidimensional space with integer coordinates of vertices.
All edges of the hyperparallelepiped are parallel to coordinate axes.
In 1-dimensional case it is an equivalent of IRange
class,
in 2-dimensional case it is an analog of the standard java.awt.Rectangle class.
More precisely, the region, specified by this class, is defined by two n-dimensional points
with integer coordinates (IPoint
),
named the minimal vertex min and maximal vertex max,
and consists of all such points
min.coord(0)
≤ x0 ≤ max.coord(0)
,
min.coord(1)
≤ x1 ≤ max.coord(1)
,
...,
min.coord(n-1)
≤ xn−1 ≤ max.coord(n-1)
.
The min and max points are specified while creating an instance of this class
and can be retrieved by min()
and max()
methods.
The coordinates of the minimal vertex
min.coord(i)
are never greater than the corresponding coordinates of the maximal vertex
max.coord(i)
,
the coordinates of the minimal and maximal vertices are always in range
coord(i)
-min.coord(i)
+1"size(int)
method, and also
coord(i)
-1"coord(i)
-2"coord(i)
+1"range(int)
This class is immutable and thread-safe: there are no ways to modify settings of the created instance.
- Author:
- Daniel Alievsky
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
contains
(Collection<IRectangularArea> areas, IPoint point) Returns true if at least one of the specified areas contains the passed point (seecontains(IPoint)
method).static boolean
contains
(Collection<IRectangularArea> areas, IRectangularArea area) Returns true if at least one of the specified areas contains the passed area (seecontains(IRectangularArea)
method).boolean
boolean
contains
(IRectangularArea area) int
Returns the number of dimensions of this rectangular area.difference
(Collection<IRectangularArea> results, IRectangularArea area) Calculates the set-theoretical difference A \ B of this (A) and the passed rectangular area (B) in a form of N rectangular areasR1,R2,...,RN , the set-theoretical union of which is equal to this difference (R1∪R2∪...∪RN = A \ B) .dilate
(long expansion) Equivalent todilate
(IPoint.valueOfEqualCoordinates(thisObjects.coordCount()
, expansion).static List<IRectangularArea>
dilate
(Collection<IRectangularArea> areas, IPoint expansion, boolean straightOnly) Dilates all areas, specified by the argument, bydilate
ordilateStraightOnly
method, and returns the list of dilated areas.Returns this rectangular area, dilated (expanded) according the argument.dilateStraightOnly
(List<IRectangularArea> results, long expansion) Equivalent todilateStraightOnly
(results, IPoint.valueOfEqualCoordinates(thisObjects.coordCount()
, expansion).dilateStraightOnly
(List<IRectangularArea> results, IPoint expansion) Returns this area, dilated according the argument only along coordinate axes, without full hypercube areas near vertices (like indilate(IPoint)
method).boolean
Indicates whether some other rectangular area is equal to this instance.Returns the minimal rectangular area, containing this area and the given point.expand
(IRectangularArea area) Returns the minimal rectangular area, containing this and the passed area.int
hashCode()
Returns the hash code of this rectangular area.intersection
(Collection<IRectangularArea> areas) Returns a list of set-theoretical intersections A ∩ Bi of this rectangular area (A) and all rectangular areas (Bi), specified by areas argument.intersection
(IRectangularArea area) Returns the set-theoretical intersection A ∩ B of this (A) and the passed rectangular area (B) or null if they do notintersect
(A ∩ B = ∅).boolean
intersects
(IRectangularArea area) max()
Returns the maximal vertex of this rectangular area: the point with maximal coordinates, belonging to this area.long
max
(int coordIndex) long
maxX()
long
maxY()
long
maxZ()
min()
Returns the minimal vertex of this rectangular area: the point with minimal coordinates, belonging to this area.long
min
(int coordIndex) static IRectangularArea
Returns the minimal rectangular area, containing all passed areas.long
minX()
long
minY()
long
minZ()
long
parallelDistance
(long... coordinates) Equivalent toparallelDistance
(IPoint.valueOf
(coordinates)), but works faster because does not require to create an instance ofIPoint
class.long
parallelDistance
(long x, long y) Equivalent toparallelDistance
(IPoint.valueOf
(x, y)), but works faster because does not require to allocate any objects.long
parallelDistance
(long x, long y, long z) Equivalent toparallelDistance
(IPoint.valueOf
(x, y, z)), but works faster because does not require to allocate any objects.long
parallelDistance
(IPoint point) Returns the parallel distance from the given point to this rectangular area.range
(int coordIndex) IRange[]
ranges()
Returns the projections of this rectangular area to all axes.static IRectangularArea
roundOf
(RectangularArea area) Returns a new rectangular area with the same coordinates as the given area.Shifts this rectangular area by the specified vector and returns the shifted area.Shifts this rectangular area by vector.symmetric()
and returns the shifted area.size()
Returns all sizes of this rectangular area in a form ofIPoint
.long
size
(int coordIndex) long[]
sizes()
Returns the sizes of this rectangular area along all dimensions.long
sizeX()
long
sizeY()
long
sizeZ()
subtract
(Collection<IRectangularArea> whatToSubtract) Equivalent tosubtractCollection
(fromWhatToSubtract, whatToSubtract, where fromWhatToSubtract contains this object as the only element.subtract
(IRectangularArea... whatToSubtract) Equivalent tosubtract
(java.util.Arrays.asList(whatToSubtract)).static Queue<IRectangularArea>
subtractCollection
(Queue<IRectangularArea> fromWhatToSubtract, Collection<IRectangularArea> whatToSubtract) Calculates the set-theoretical difference A \ B of the set-theoretical union A of all elements of the collection fromWhatToSubtract and the set-theoretical union B of all elements of the collection whatToSubtract, in a form of a union of N rectangular areas, and replaces the old content of fromWhatToSubtract with the resulting N areas.static Queue<IRectangularArea>
subtractCollection
(Queue<IRectangularArea> fromWhatToSubtract, IRectangularArea... whatToSubtract) Equivalent tosubtractCollection
(fromWhatToSubtract, java.util.Arrays.asList(whatToSubtract)).Equivalent toRectangularArea.valueOf
(thisInstance).toString()
Returns a brief string description of this object.static IRectangularArea
valueOf
(long minX, long maxX) Returns a 1-dimensional rectangular area (range) with the given minimal and maximal vertex.static IRectangularArea
valueOf
(long minX, long minY, long maxX, long maxY) Returns a 2-dimensional rectangle with the given minimal and maximal vertex.static IRectangularArea
valueOf
(long minX, long minY, long minZ, long maxX, long maxY, long maxZ) Returns a 3-dimensional parallelepiped with the given minimal and maximal vertex.static IRectangularArea
Returns an instance of this class with the given minimal vertex min and maximal vertex max.static IRectangularArea
Returns the Cartesian product of the specified coordinate ranges.static IRectangularArea
valueOf
(RectangularArea area) Returns a new rectangular area with the same coordinates as the given area.double
volume()
Returns the volume of this rectangular area: the product of all sizes returned bysizes()
method.width()
Returns all sizes of this rectangular area, decreased by 1, in a form ofIPoint
.long
width
(int coordIndex) long[]
widths()
Returns the sizes of this rectangular area along all dimensions, decreased by 1.long
widthX()
long
widthY()
long
widthZ()
-
Method Details
-
valueOf
Returns an instance of this class with the given minimal vertex min and maximal vertex max. See thecomments to this class
for more details.- Parameters:
min
- the minimal vertex, inclusive.max
- the maximal vertex, inclusive.- Returns:
- the new rectangular area "between" these vertices.
- Throws:
NullPointerException
- if one of arguments is null.IllegalArgumentException
- if thenumbers of dimensions
in min and max points are different, or if, for some i, min.coord
(i) > max.coord
(i), or ifmax. > Long.MAX_VALUE (more precisely, if this Java expression is nonpositive due to integer overflow), or ifcoord
(i)-min.coord
(i)+1min. , or ifcoord
(i) <= -Long.MAX_VALUEmax. .coord
(i) == Long.MAX_VALUE
-
valueOf
Returns the Cartesian product of the specified coordinate ranges. More precisely, return an n-dimensionalrectangular area
with the minimal vertex min and maximal vertex max, where n=coordRanges.length, min.coord(i)
=coordRanges[i].min()
, max.coord(i)
=coordRanges[i].max()
. See thecomments to this class
for more details.- Parameters:
coordRanges
- the coordinate ranges.- Returns:
- the Cartesian product of the specified coordinate ranges.
- Throws:
NullPointerException
- if the argument is null or if one of specified coordRanges is null.IllegalArgumentException
- if the passed array is empty (no ranges are passed).
-
valueOf
Returns a 1-dimensional rectangular area (range) with the given minimal and maximal vertex. Equivalent tovalueOf
(IPoint.valueOf
(minX),IPoint.valueOf
(maxX));- Parameters:
minX
- the minimal x-coordinate, inclusive.maxX
- the maximal x-coordinate, inclusive.- Returns:
- the new 1-dimensional rectangular area.
- Throws:
IllegalArgumentException
- in the same situations asvalueOf(IPoint, IPoint)
method.
-
valueOf
Returns a 2-dimensional rectangle with the given minimal and maximal vertex. Equivalent tovalueOf
(IPoint.valueOf
(minX, minY),IPoint.valueOf
(maxX, maxY));- Parameters:
minX
- the minimal x-coordinate, inclusive.minY
- the minimal y-coordinate, inclusive.maxX
- the maximal x-coordinate, inclusive.maxY
- the maximal y-coordinate, inclusive.- Returns:
- the new 2-dimensional rectangle.
- Throws:
IllegalArgumentException
- in the same situations asvalueOf(IPoint, IPoint)
method.
-
valueOf
public static IRectangularArea valueOf(long minX, long minY, long minZ, long maxX, long maxY, long maxZ) Returns a 3-dimensional parallelepiped with the given minimal and maximal vertex. Equivalent tovalueOf
(IPoint.valueOf
(minX, minY, minZ),IPoint.valueOf
(maxX, maxY, maxZ));- Parameters:
minX
- the minimal x-coordinate, inclusive.minY
- the minimal y-coordinate, inclusive.minZ
- the minimal z-coordinate, inclusive.maxX
- the maximal x-coordinate, inclusive.maxY
- the maximal y-coordinate, inclusive.maxZ
- the maximal z-coordinate, inclusive.- Returns:
- the new 3-dimensional parallelepiped.
- Throws:
IllegalArgumentException
- in the same situations asvalueOf(IPoint, IPoint)
method.
-
valueOf
Returns a new rectangular area with the same coordinates as the given area. All double coordinates of the passed area are converted to long coordinates of the returned area by standard Java typecast (long)doubleValue. Equivalent tovalueOf
(IPoint.valueOf
(area.min()
),IPoint.valueOf
(area.max()
)).- Parameters:
area
- the real rectangular area.- Returns:
- the integer rectangular area with same (cast) coordinates.
- Throws:
NullPointerException
- if the passed area is null.IllegalArgumentException
- if the pointsIPoint.valueOf
(area.min()
) andIPoint.valueOf
(area.max()
) do not match requirements ofvalueOf(IPoint, IPoint)
method.
-
roundOf
Returns a new rectangular area with the same coordinates as the given area. All double coordinates of the passed area are converted to long coordinates of the returned area by StrictMath.round method. Java typecast (long)doubleValue. Equivalent tovalueOf
(IPoint.roundOf
(area.min()
),IPoint.roundOf
(area.max()
)).- Parameters:
area
- the real rectangular area.- Returns:
- the integer rectangular area with same (rounded) coordinates.
- Throws:
NullPointerException
- if the passed area is null.IllegalArgumentException
- if the pointsIPoint.valueOf
(area.min()
) andIPoint.valueOf
(area.max()
) do not match requirements ofvalueOf(IPoint, IPoint)
method.
-
coordCount
public int coordCount()Returns the number of dimensions of this rectangular area. Equivalent tomin()
.coordCount()
ormax()
.coordCount()
, but works faster.The result of this method is always positive (>0).
- Returns:
- the number of dimensions of this rectangular area.
-
min
Returns the minimal vertex of this rectangular area: the point with minimal coordinates, belonging to this area. See thecomments to this class
for more details.- Returns:
- the minimal vertex of this rectangular area.
-
max
Returns the maximal vertex of this rectangular area: the point with maximal coordinates, belonging to this area. See thecomments to this class
for more details.- Returns:
- the maximal vertex of this rectangular area.
-
size
Returns all sizes of this rectangular area in a form ofIPoint
. Equivalent toIPoint.valueOf
(sizes()
). The coordinates of the returned point are greater by 1 than coordinates ofmax()
.subtract
(min()
).- Returns:
- all sizes of this rectangular area in a form of
IPoint
.
-
width
Returns all sizes of this rectangular area, decreased by 1, in a form ofIPoint
. Equivalent toIPoint.valueOf
(widths()
). The coordinates of the returned point are equal to coordinates ofmax()
.subtract
(min()
).- Returns:
- all sizes of this rectangular area, decreased by 1, in a form of
IPoint
.
-
min
public long min(int coordIndex) - Parameters:
coordIndex
- the index of the coordinate.- Returns:
min()
.coord
(coordIndex).- Throws:
IndexOutOfBoundsException
- if coordIndex<0 or coordIndex>=coordCount()
.
-
max
public long max(int coordIndex) - Parameters:
coordIndex
- the index of the coordinate.- Returns:
max()
.coord
(coordIndex).- Throws:
IndexOutOfBoundsException
- if coordIndex<0 or coordIndex>=coordCount()
.
-
size
public long size(int coordIndex) - Parameters:
coordIndex
- the index of the coordinate.- Returns:
max
(coordIndex) -min
(coordIndex) + 1.- Throws:
IndexOutOfBoundsException
- if coordIndex<0 or coordIndex>=coordCount()
.
-
width
public long width(int coordIndex) - Parameters:
coordIndex
- the index of the coordinate.- Returns:
max
(coordIndex) -min
(coordIndex).- Throws:
IndexOutOfBoundsException
- if coordIndex<0 or coordIndex>=coordCount()
.
-
minX
public long minX() -
maxX
public long maxX() -
sizeX
public long sizeX() -
widthX
public long widthX() -
minY
public long minY()- Returns:
min()
.y()
.- Throws:
IllegalStateException
- ifcoordCount()
<2.
-
maxY
public long maxY()- Returns:
max()
.y()
.- Throws:
IllegalStateException
- ifcoordCount()
<2.
-
sizeY
public long sizeY()- Returns:
maxY()
-minY()
+ 1.- Throws:
IllegalStateException
- ifcoordCount()
<2.
-
widthY
public long widthY()- Returns:
maxY()
-minY()
.- Throws:
IllegalStateException
- ifcoordCount()
<2.
-
minZ
public long minZ()- Returns:
min()
.z()
.- Throws:
IllegalStateException
- ifcoordCount()
<3.
-
maxZ
public long maxZ()- Returns:
max()
.z()
.- Throws:
IllegalStateException
- ifcoordCount()
<3.
-
sizeZ
public long sizeZ()- Returns:
maxZ()
-minZ()
+ 1.- Throws:
IllegalStateException
- ifcoordCount()
<3.
-
widthZ
public long widthZ()- Returns:
maxZ()
-minZ()
.- Throws:
IllegalStateException
- ifcoordCount()
<3.
-
sizes
public long[] sizes()Returns the sizes of this rectangular area along all dimensions. The returned array consists ofcoordCount()
elements, and the element #k containssize
(k).- Returns:
- the sizes of this rectangular area along all dimensions.
-
widths
public long[] widths()Returns the sizes of this rectangular area along all dimensions, decreased by 1. The returned array consists ofcoordCount()
elements, and the element #k containswidth
(k).- Returns:
- the sizes of this rectangular area along all dimensions, decreased by 1.
-
volume
public double volume()Returns the volume of this rectangular area: the product of all sizes returned bysizes()
method. This area is calculated in double values.- Returns:
- the multidimensional volume of this rectangular area (usual area in 2-dimensional case).
-
range
-
ranges
Returns the projections of this rectangular area to all axes. The returned array consists ofcoordCount()
elements, and the element #k containsrange
(k).- Returns:
- the projections of this rectangular area to all axes.
-
contains
- Parameters:
point
- the checked point.- Returns:
- true if this rectangular area contains the given point.
- Throws:
NullPointerException
- if the argument is null.IllegalArgumentException
- if point.coordCount()
is not equal to thenumber of dimensions
of this instance.
-
contains
Returns true if at least one of the specified areas contains the passed point (seecontains(IPoint)
method).- Parameters:
areas
- list of checked rectangular areas.point
- the checked point.- Returns:
- true if one of the passed areas contains the given point.
- Throws:
NullPointerException
- if one of the arguments or one of the areas is null.IllegalArgumentException
- if point.coordCount()
is not equal to thenumber of dimensions
of one of areas.
-
contains
- Parameters:
area
- the checked rectangular area.- Returns:
- true if the checked rectangular area is a subset of this area.
- Throws:
NullPointerException
- if the argument is null.IllegalArgumentException
- if area.coordCount()
is not equal to thenumber of dimensions
of this instance.
-
contains
Returns true if at least one of the specified areas contains the passed area (seecontains(IRectangularArea)
method).- Parameters:
areas
- list of checked rectangular areas.area
- the checked area.- Returns:
- true if one of the passed areas (1st argument) contains the given area (2nd argument).
- Throws:
NullPointerException
- if one of the arguments or one of the areas is null.IllegalArgumentException
- if area.coordCount()
is not equal to thenumber of dimensions
of one of areas in the 1st argument.
-
intersects
- Parameters:
area
- the checked rectangular area.- Returns:
- true if the checked rectangular area overlaps with this area, maybe in boundary points only.
- Throws:
NullPointerException
- if the argument is null.IllegalArgumentException
- if area.coordCount()
is not equal to thenumber of dimensions
of this instance.
-
intersection
Returns the set-theoretical intersection A ∩ B of this (A) and the passed rectangular area (B) or null if they do notintersect
(A ∩ B = ∅). Equivalent tothisInstance.
.intersects
(area) ?IRectangularArea.valueOf
( thisInstance.min()
.max
(area.min()
), thisInstance.max()
.min
(area.max()
)) : null- Parameters:
area
- the second rectangular area.- Returns:
- intersection of this and the second rectangular area or null if they do not intersect.
- Throws:
NullPointerException
- if the argument is null.IllegalArgumentException
- if area.coordCount()
is not equal to thenumber of dimensions
of this instance.
-
intersection
Returns a list of set-theoretical intersections A ∩ Bi of this rectangular area (A) and all rectangular areas (Bi), specified by areas argument. If the passed collection doesn't contain areas, intersecting this area, the result will be an empty list.Equivalent to the following loop:
final List
.result = ... (some empty list); for (IRectangularArea area : areas) { IRectangularArea intersection = intersection
(area); if (intersection != null) { result.add(intersection); } }- Parameters:
areas
- collection of areas (we find intersection with each from them).- Returns:
- intersection of this and the second rectangular area or null if they do not intersect.
- Throws:
NullPointerException
- if the argument is null or one of its elements is null.IllegalArgumentException
- if this rectangular area or some of elements of the passed collection have differentcoordCount()
.
-
difference
public Collection<IRectangularArea> difference(Collection<IRectangularArea> results, IRectangularArea area) Calculates the set-theoretical difference A \ B of this (A) and the passed rectangular area (B) in a form of N rectangular areasR1,R2,...,RN , the set-theoretical union of which is equal to this difference (R1∪R2∪...∪RN = A \ B) . The resulting areasR1,R2,...,RN are added into the collection results by Collection.add(...) method. So, the collection results must be not-null and support adding elements (usually it is List or Queue).It is possible that the difference is empty (A \ B = ∅), i.e. this area A is a subset of the passed one B. In this case, this method does nothing.
It is possible that the difference is equal to this area (A \ B = A), i.e. this area A does not intersect the passed one B. In this case, this method is equivalent to results.add(thisInstance) call.
In other cases, there is more than 1 way to represent the resulting difference in a form of union of several rectangular areas
R1,R2,...,RN . The precise way, how this method forms this set of rectangular areas Ri, is not documented, but this method tries to minimize the number N of such areas. In any case, there is a guarantee that N≤2*coordCount()
.- Parameters:
results
- the collection to store results (new areas will be added to this collection).area
- the area B, subtracted from this area A.- Returns:
- a reference to the results argument.
- Throws:
NullPointerException
- if result or area argument is null.IllegalArgumentException
- if area.coordCount()
is not equal to thenumber of dimensions
of this instance.- See Also:
-
subtractCollection
public static Queue<IRectangularArea> subtractCollection(Queue<IRectangularArea> fromWhatToSubtract, Collection<IRectangularArea> whatToSubtract) Calculates the set-theoretical difference A \ B of the set-theoretical union A of all elements of the collection fromWhatToSubtract and the set-theoretical union B of all elements of the collection whatToSubtract, in a form of a union of N rectangular areas, and replaces the old content of fromWhatToSubtract with the resulting N areas.More precisely, this method is equivalent to the following loop:
for (IRectangularArea area : whatToSubtract) { for (int i = 0, n = fromWhatToSubtract.size(); i < n; i++) { IRectangularArea minuend = fromWhatToSubtract.poll(); minuend.
difference
(fromWhatToSubtract, area); } if (fromWhatToSubtract.isEmpty()) { break; } }Note: if some exception occurs while execution of the listed loop (for example, some elements of the collections are null or have different number of dimensions), the fromWhatToSubtract stays partially modified. In other words, this method is non-atomic regarding failures.
- Parameters:
fromWhatToSubtract
- the minuend A, which will be replaced with A \ B.whatToSubtract
- the subtrahend B.- Returns:
- a reference to fromWhatToSubtract argument, which will contain the difference A \ B.
- Throws:
NullPointerException
- if fromWhatToSubtract or whatToSubtract argument is null or if one of their elements it null.IllegalArgumentException
- if some of elements of the passed collections have differentcoordCount()
.- See Also:
-
subtractCollection
public static Queue<IRectangularArea> subtractCollection(Queue<IRectangularArea> fromWhatToSubtract, IRectangularArea... whatToSubtract) Equivalent tosubtractCollection
(fromWhatToSubtract, java.util.Arrays.asList(whatToSubtract)).- Parameters:
fromWhatToSubtract
- the minuend A, which will be replaced with A \ B.whatToSubtract
- the subtrahend B.- Returns:
- a reference to fromWhatToSubtract argument, which will contain the difference A \ B.
- Throws:
NullPointerException
- if fromWhatToSubtract or whatToSubtract argument is null or if one of their elements it null.IllegalArgumentException
- if some of elements of the passed collection and array have differentcoordCount()
.
-
subtract
Equivalent tosubtractCollection
(fromWhatToSubtract, whatToSubtract, where fromWhatToSubtract contains this object as the only element.- Parameters:
whatToSubtract
- the subtrahend B.- Returns:
- new collection, containing the difference A \ B (A = this object, B = union of all whatToSubtract).
- Throws:
NullPointerException
- if whatToSubtract argument is null or if one of their elements it null.IllegalArgumentException
- if this rectangular area or some of elements of the passed collection have differentcoordCount()
.
-
subtract
Equivalent tosubtract
(java.util.Arrays.asList(whatToSubtract)).- Parameters:
whatToSubtract
- the subtrahend B.- Returns:
- new collection, containing the difference A \ B (A = this object, B = union of all whatToSubtract).
- Throws:
NullPointerException
- if whatToSubtract argument is null or if one of their elements it null.IllegalArgumentException
- if this rectangular area or some of elements of the passed array have differentcoordCount()
.
-
expand
Returns the minimal rectangular area, containing this area and the given point. In the returned area, theminimal vertex
is equal to thisInstance.min()
.min
(point) and themaximal vertex
is equal to thisInstance.max()
.max
(point).- Parameters:
point
- some point that should be included to the new rectangular area.- Returns:
- the expanded rectangular area.
- Throws:
NullPointerException
- if the argument is null.IllegalArgumentException
- if point.coordCount()
is not equal to thenumber of dimensions
of this instance, or if the points thisInstance.min()
.min
(point) and thisInstance.max()
.max
(point) do not match requirements ofvalueOf(IPoint, IPoint)
method.
-
expand
Returns the minimal rectangular area, containing this and the passed area. Equivalent to
.IRectangularArea.valueOf
( thisInstance.min()
.min
(area.min()
), thisInstance.max()
.max
(area.max()
))- Parameters:
area
- the second rectangular area.- Returns:
- the minimal rectangular area, containing this and the passed area.
- Throws:
NullPointerException
- if the argument is null.IllegalArgumentException
- if area.coordCount()
is not equal to thenumber of dimensions
of this instance.
-
minimalContainingArea
Returns the minimal rectangular area, containing all passed areas. Equivalent to the loop ofexpand(IRectangularArea)
methods, called for each element of the passed collection, but works faster.If the passed collection is empty, returns null.
- Parameters:
areas
- some collection of rectangular areas.- Returns:
- the minimal rectangular area, containing all them, or null for empty collection.
- Throws:
NullPointerException
- if the argument or one of the passed areas is null.IllegalArgumentException
- ifcoordCount()
is not equal for all areas.
-
parallelDistance
Returns the parallel distance from the given point to this rectangular area. The parallel distance is a usual distance, with plus or minus sign, from the point to some of hyperplanes, containing the hyperfacets of this hyperparallelepiped, chosen so that:- the parallel distance is zero at the hyperfacets, negative inside the rectangular area and positive outside it;
- for any constant c, the set of all such points, that the parallel distance from them to this rectangular area ≤c, is also hyperparallelepiped (rectangular area) wich hyperfacets, parallel to the the coordinate hyperplanes, or an empty set if c<c0, where c0 is the (negative) parallel distance from the geometrical center of this hyperparallelepiped.
Formally, let p is any point with coordinates
p0, p1, ..., pn−1 , li =min
(i), ri =max
(i), di = max(li−pi, pi−ri). Note that di is positive if pi<li or pi>ri and negative if pi is inside li..ri range. The parallel distance from the point p to this rectangular area is defined as maximal value from all di:max(d0, d1, ..., dn−1) .- Parameters:
point
- some point.- Returns:
- the parallel distance from this point to this rectangular area.
- Throws:
NullPointerException
- if the argument is null.IllegalArgumentException
- if point.coordCount()
is not equal to thenumber of dimensions
of this instance.
-
parallelDistance
public long parallelDistance(long... coordinates) Equivalent toparallelDistance
(IPoint.valueOf
(coordinates)), but works faster because does not require to create an instance ofIPoint
class.- Parameters:
coordinates
- coordinates of some point.- Returns:
- the parallel distance from this point to this rectangular area.
- Throws:
NullPointerException
- if coordinates argument is null.IllegalArgumentException
- if coordinates.length is not equal to thenumber of dimensions
of this instance.
-
parallelDistance
public long parallelDistance(long x, long y) Equivalent toparallelDistance
(IPoint.valueOf
(x, y)), but works faster because does not require to allocate any objects. Works only for 2-dimensional rectangular areas, in other cases throws IllegalArgumentException.- Parameters:
x
- the 1st coordinate of some point.y
- the 2nd coordinate of some point.- Returns:
- the parallel distance from this point to this rectangular area.
- Throws:
IllegalArgumentException
- if coordinates.length!=2 .
-
parallelDistance
public long parallelDistance(long x, long y, long z) Equivalent toparallelDistance
(IPoint.valueOf
(x, y, z)), but works faster because does not require to allocate any objects. Works only for 3-dimensional rectangular areas, in other cases throws IllegalArgumentException.- Parameters:
x
- the 1st coordinate of some point.y
- the 2nd coordinate of some point.z
- the 3rd coordinate of some point.- Returns:
- the parallel distance from this point to this rectangular area.
- Throws:
IllegalArgumentException
- if coordinates.length!=2 .
-
shift
Shifts this rectangular area by the specified vector and returns the shifted area. Equivalent tovalueOf
(thisInstance.min()
.addExact
(vector), thisInstance.max()
.addExact
(vector))Note: the coordinates of new areas are calculated with overflow control.
- Parameters:
vector
- the vector which is added to all vertices of this area.- Returns:
- the shifted area.
- Throws:
NullPointerException
- if the argument is null.IllegalArgumentException
- if vector.coordCount()
is not equal to thenumber of dimensions
of this instance, or if the result is illegal due to the integer overflow.ArithmeticException
- in a case of long overflow.
-
shiftBack
Shifts this rectangular area by vector.symmetric()
and returns the shifted area. Equivalent tovalueOf
(thisInstance.min()
.subtractExact
(vector), thisInstance.max()
.subtractExact
(vector))Note: the coordinates of new areas are calculated with overflow control.
- Parameters:
vector
- the vector which is subtracted from all vertices of this area.- Returns:
- the shifted area.
- Throws:
NullPointerException
- if the argument is null.IllegalArgumentException
- if vector.coordCount()
is not equal to thenumber of dimensions
of this instance, or if the result is illegal due to the integer overflow.ArithmeticException
- in a case of long overflow.
-
dilate
Returns this rectangular area, dilated (expanded) according the argument. More precisely, returnsIRectangularArea.valueOf( thisInstance.
(but if expansion.min()
.subtractExact
(expansion), thisInstance.max()
.addExact
(expansion))isOrigin()
, return this object without changes).- Parameters:
expansion
- how to dilate this area.- Returns:
- dilated area.
- Throws:
NullPointerException
- if the argument is null.IllegalArgumentException
- if expansion.coordCount()
is not equal to thenumber of dimensions
of this instance, or if the result area will be incorrect (see comments tovalueOf(IPoint, IPoint)
method).ArithmeticException
- in a case of long overflow.
-
dilate
Equivalent todilate
(IPoint.valueOfEqualCoordinates(thisObjects.coordCount()
, expansion).- Parameters:
expansion
- how to dilate this area.- Returns:
- dilated area.
- Throws:
NullPointerException
- if the argument is null.IllegalArgumentException
- if the result area will be incorrect (see comments tovalueOf(IPoint, IPoint)
method).ArithmeticException
- in a case of long overflow.
-
dilateStraightOnly
Returns this area, dilated according the argument only along coordinate axes, without full hypercube areas near vertices (like indilate(IPoint)
method).More precisely, the result is a list, consisting of this area and (usually) 2*
coordCount()
rectangular areas, lying along facets of this area, like in the following picture:aaaaaaaaaaaa bbRRRRRRRRRRRRcc bbRRRRRRRRRRRRcc bbRRRRRRRRRRRRcc ddddddddddd
This figure shows dilation of some 2-dimensional rectangle R by expansion=IPoint.valueOf(2,1): the results consists of the original rectangle and 4 rectangles a, b (height 1) and c, d (width 2).Note: all coordinates of expansion argument must be non-negative (unlike
dilate(IPoint)
method).Note: the coordinates of new areas are calculated with overflow control: if the result cannot be exactly represented by 64-bit long integers, this method throws ArithmeticException.
If some of coordinates of the point expansion are zero, new areas along the corresponding facets are not added (recanglar area cannot be empty). In particular, if expansion.
isOrigin()
, the result will contain this area as the only element.- Parameters:
results
- the list to store results (new areas will be added to the end of this list).expansion
- how to dilate this area.- Returns:
- a reference to the results argument.
- Throws:
NullPointerException
- if one of the arguments is null.IllegalArgumentException
- if expansion.coordCount()
is not equal to thenumber of dimensions
of this instance, or if one of coordinates of expansion is negative, or if the result area will be incorrect (see comments tovalueOf(IPoint, IPoint)
method).ArithmeticException
- in a case of long overflow.
-
dilateStraightOnly
Equivalent todilateStraightOnly
(results, IPoint.valueOfEqualCoordinates(thisObjects.coordCount()
, expansion).- Parameters:
results
- the list to store results (new areas will be added to the end of this list).expansion
- how to dilate this area.- Returns:
- a reference to the results argument.
- Throws:
NullPointerException
- if the argument is null.IllegalArgumentException
- if expansion < 0 or if the result area will be incorrect (see comments tovalueOf(IPoint, IPoint)
method).ArithmeticException
- in a case of long overflow.
-
dilate
public static List<IRectangularArea> dilate(Collection<IRectangularArea> areas, IPoint expansion, boolean straightOnly) Dilates all areas, specified by the argument, bydilate
ordilateStraightOnly
method, and returns the list of dilated areas.If straightOnly argument is false, this method is equivalent to the following code:
final List
result = new ArrayList (); for (IRectangularArea area : areas) { result.add(area. dilate
(expansion)); }If straightOnly argument is true, this method is equivalent to the following code:
final List
result = new ArrayList (); for (IRectangularArea area : areas) { area. dilateStraightOnly
(result, expansion); }Note that in the second case the resulting list will usually contain more elements than the source areas collection.
- Parameters:
areas
- areas to be dilated.expansion
- how to dilate these areas.straightOnly
- dilation mode.- Returns:
- list of dilated areas.
- Throws:
NullPointerException
- if one of the arguments is null or one of areas is null.IllegalArgumentException
- if expansion.coordCount()
is not equal to thenumber of dimensions
of one of areas, or if straightOnly amd one of coordinates of expansion is negative (and collection of areas is not empty), or if one of the result areas will be incorrect (see comments tovalueOf(IPoint, IPoint)
method).ArithmeticException
- in a case of long overflow.
-
toRectangularArea
Equivalent toRectangularArea.valueOf
(thisInstance).- Returns:
- the rectangular area with same real coordinates as this one.
-
toString
Returns a brief string description of this object.The result of this method may depend on implementation and usually contains information about all coordinates ranges between the minimum and maximum vertices of this area.
-
hashCode
public int hashCode()Returns the hash code of this rectangular area. -
equals
Indicates whether some other rectangular area is equal to this instance. Returns true if and only if obj instanceof IRectangularArea, ((IRectangularArea)obj).min().equals(this.min()) and ((IRectangularArea)obj).max().equals(this.max()).
-