Package net.algart.math.rectangles
Class IRectanglesUnion
java.lang.Object
net.algart.math.rectangles.IRectanglesUnion
Set-theoretic union of several 2-dimensional rectangles
with integer coordinates of vertices and sides, parallel to coordinate axes.
This class allows to solve the following main tasks:
- find connected components in this union;
- find its boundary as a polygon: a sequence of links, where each link is a horizontal or vertical segment (1st link is horizontal, 2nd is vertical, 3rd is horizontal, etc.);
- find the largest rectangle (with sides, parallel to the coordinate axes), which is a subset of this union.
This class is immutable and thread-safe:
there are no ways to modify settings of the created instance.
However, all important information is returned "lazily", i.e. while the 1st attempt to read it.
So, the instance creation method newInstance(Collection)
works quickly and does not lead to complex calculations and allocating additional memory.
- Author:
- Daniel Alievsky
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
static class
static class
static class
static class
static class
static class
static class
-
Method Summary
Modifier and TypeMethodDescriptionstatic double
areaInBoundary
(List<IRectanglesUnion.BoundaryLink> boundary) connectedComponent
(int index) int
void
Forces this object to find the boundary of this union of rectangles.void
Forces this object to find all connected components.void
Forces this object to find the largest rectangle (with sides, parallel to the coordinate axes), which is a subset of this union of rectangles.frames()
static IRectanglesUnion
newInstance
(Collection<IRectangularArea> rectangles) subtractRectangle
(IRectangularArea whatToSubtract) Subtracts the given rectangle (viaIRectangularArea.subtractCollection(Queue, Collection)
method) from the set of rectangles, containing in this object, and return the union of the resulting rectangles.toString()
double
-
Method Details
-
newInstance
-
subtractRectangle
Subtracts the given rectangle (viaIRectangularArea.subtractCollection(Queue, Collection)
method) from the set of rectangles, containing in this object, and return the union of the resulting rectangles.- Parameters:
whatToSubtract
- the subtracted rectangle.- Returns:
- the union of the rest of rectangles after subtraction.
- Throws:
NullPointerException
- if the argument is null.IllegalArgumentException
- if whatToSubtract.coordCount() != 2.
-
subtractLargestRectangle
-
frames
-
circumscribedRectangle
-
horizontalSides
-
verticalSides
-
connectedComponentCount
public int connectedComponentCount() -
connectedComponent
-
allHorizontalBoundaryLinks
-
allVerticalBoundaryLinks
-
allBoundaries
-
unionArea
public double unionArea() -
largestRectangleInUnion
-
findConnectedComponents
public void findConnectedComponents()Forces this object to find all connected components. It does not affect to results of any other methods, but after this call the following methods will work quickly: -
findBoundaries
public void findBoundaries()Forces this object to find the boundary of this union of rectangles. It does not affect to results of any other methods, but after this call the following methods will work quickly: -
findLargestRectangleInUnion
public void findLargestRectangleInUnion()Forces this object to find the largest rectangle (with sides, parallel to the coordinate axes), which is a subset of this union of rectangles. It does not affect to results of any other methods, but after this call the following methods will work quickly: -
toString
-
areaInBoundary
-
boundaryVerticesPlusHalf
-
boundaryVerticesAtRectangles
public static List<IPoint> boundaryVerticesAtRectangles(List<IRectanglesUnion.BoundaryLink> boundary)
-