Class RegionBSPTree2D.PartitionedRegionBuilder2D
- Enclosing class:
RegionBSPTree2D
Usage
Usage of this class consists of two phases: (1) partition insertion and (2) boundary
insertion. Instances begin in the partition insertion phase. Here, partitions can be inserted
into the empty tree using insertPartition
or similar methods. The INHERIT
cut rule is used internally to insert the cut so the represented region remains empty even as partitions are
inserted.
The instance moves into the boundary insertion phase when the caller inserts the first region
boundary, using insertBoundary
or
similar methods. Attempting to insert a partition after this point results in an IllegalStateException
.
This ensures that partitioning cuts are always located higher up the tree than boundary cuts.
After all boundaries are inserted, the build
method is used
to perform final processing and return the computed tree.
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
Construct a new builder instance. -
Method Summary
Modifier and TypeMethodDescriptionbuild()
Build and return the region BSP tree.insertAxisAlignedGrid
(Bounds2D bounds, int level, org.apache.commons.numbers.core.Precision.DoubleEquivalence precision) Insert a grid of partitions.private void
insertAxisAlignedGridRecursive
(Vector2D min, Vector2D max, int level, org.apache.commons.numbers.core.Precision.DoubleEquivalence precision) Recursively insert axis-aligned grid partitions.insertAxisAlignedPartitions
(Vector2D center, org.apache.commons.numbers.core.Precision.DoubleEquivalence precision) Insert two axis aligned lines intersecting at the given point as partitions.insertBoundaries
(Iterable<? extends LineConvexSubset> boundaries) Insert a collection of region boundaries.insertBoundaries
(BoundarySource2D boundarySrc) Insert all boundaries from the given source.insertBoundary
(LineConvexSubset boundary) Insert a region boundary.insertPartition
(Line partition) Insert a partition line.insertPartition
(LineConvexSubset partition) Insert a line convex subset as a partition.Methods inherited from class org.apache.commons.geometry.core.partitioning.bsp.AbstractPartitionedRegionBuilder
buildInternal, insertBoundaryInternal, insertPartitionInternal
-
Constructor Details
-
PartitionedRegionBuilder2D
private PartitionedRegionBuilder2D()Construct a new builder instance.
-
-
Method Details
-
insertPartition
Insert a partition line.- Parameters:
partition
- partition to insert- Returns:
- this instance
- Throws:
IllegalStateException
- if a boundary has previously been inserted
-
insertPartition
Insert a line convex subset as a partition.- Parameters:
partition
- partition to insert- Returns:
- this instance
- Throws:
IllegalStateException
- if a boundary has previously been inserted
-
insertAxisAlignedPartitions
public RegionBSPTree2D.PartitionedRegionBuilder2D insertAxisAlignedPartitions(Vector2D center, org.apache.commons.numbers.core.Precision.DoubleEquivalence precision) Insert two axis aligned lines intersecting at the given point as partitions. The lines each contain thecenter
point and have the directions+x
and+y
in that order. If inserted into an empty tree, this will partition the space into 4 sections.- Parameters:
center
- center point for the partitions; the inserted lines intersect at this pointprecision
- precision context used to construct the lines- Returns:
- this instance
- Throws:
IllegalStateException
- if a boundary has previously been inserted
-
insertAxisAlignedGrid
public RegionBSPTree2D.PartitionedRegionBuilder2D insertAxisAlignedGrid(Bounds2D bounds, int level, org.apache.commons.numbers.core.Precision.DoubleEquivalence precision) Insert a grid of partitions. The partitions are constructed recursively: at each level two axis-aligned partitioning lines are inserted usinginsertAxisAlignedPartitions
. The algorithm then recurses using bounding boxes from the min point to the center and from the center point to the max. Note that this means no partitions are ever inserted directly on the boundaries of the given bounding box. This is intentional and done to allow this method to be called directly with the bounding box from a set of boundaries to be inserted without unnecessarily adding partitions that will never have region boundaries on both sides.- Parameters:
bounds
- bounding box for the gridlevel
- recursion level for the grid; each level subdivides each grid cube into 4 sections, making the total number of grid cubes equal to4 ^ level
precision
- precision context used to construct the partition lines- Returns:
- this instance
- Throws:
IllegalStateException
- if a boundary has previously been inserted
-
insertAxisAlignedGridRecursive
private void insertAxisAlignedGridRecursive(Vector2D min, Vector2D max, int level, org.apache.commons.numbers.core.Precision.DoubleEquivalence precision) Recursively insert axis-aligned grid partitions.- Parameters:
min
- min point for the grid square to partitionmax
- max point for the grid square to partitionlevel
- current recursion levelprecision
- precision context used to construct the partition planes
-
insertBoundary
Insert a region boundary.- Parameters:
boundary
- region boundary to insert- Returns:
- this instance
-
insertBoundaries
public RegionBSPTree2D.PartitionedRegionBuilder2D insertBoundaries(Iterable<? extends LineConvexSubset> boundaries) Insert a collection of region boundaries.- Parameters:
boundaries
- boundaries to insert- Returns:
- this instance
-
insertBoundaries
Insert all boundaries from the given source.- Parameters:
boundarySrc
- source of boundaries to insert- Returns:
- this instance
-
build
Build and return the region BSP tree.- Returns:
- the region BSP tree
-