Class RegionBSPTree1D

All Implemented Interfaces:
BSPSubtree<Vector1D,RegionBSPTree1D.RegionNode1D>, BSPTree<Vector1D,RegionBSPTree1D.RegionNode1D>, HyperplaneBoundedRegion<Vector1D>, Splittable<Vector1D,HyperplaneBoundedRegion<Vector1D>>, Region<Vector1D>, Sized

public final class RegionBSPTree1D extends AbstractRegionBSPTree<Vector1D,RegionBSPTree1D.RegionNode1D>
Binary space partitioning (BSP) tree representing a region in one dimensional Euclidean space.
  • Field Details

  • Constructor Details

    • RegionBSPTree1D

      public RegionBSPTree1D()
      Create a new, empty region.
    • RegionBSPTree1D

      public RegionBSPTree1D(boolean full)
      Create a new region. If full is true, then the region will represent the entire number line. Otherwise, it will be empty.
      Parameters:
      full - whether or not the region should contain the entire number line or be empty
  • Method Details

    • copy

      public RegionBSPTree1D copy()
      Return a deep copy of this instance.
      Returns:
      a deep copy of this instance.
      See Also:
    • add

      public void add(Interval interval)
      Add an interval to this region. The resulting region will be the union of the interval and the region represented by this instance.
      Parameters:
      interval - the interval to add
    • classify

      public RegionLocation classify(double x)
      Classify a point location with respect to the region.
      Parameters:
      x - the point to classify
      Returns:
      the location of the point with respect to the region
      See Also:
    • contains

      public boolean contains(double x)
      Return true if the given point location is on the inside or boundary of the region.
      Parameters:
      x - the location to test
      Returns:
      true if the location is on the inside or boundary of the region
      See Also:
    • getBoundarySize

      public double getBoundarySize()
      Get the size of the boundary of the region. The size is a value in the d-1 dimension space. For example, in Euclidean space, this will be a length in 2D and an area in 3D.

      This method simply returns 0 because boundaries in one dimension do not have any size.

      Specified by:
      getBoundarySize in interface Region<Vector1D>
      Overrides:
      getBoundarySize in class AbstractRegionBSPTree<Vector1D,RegionBSPTree1D.RegionNode1D>
      Returns:
      the size of the boundary of the region
    • project

      public Vector1D project(Vector1D pt)
      Project a point onto the boundary of the region. Null is returned if the region contains no boundaries (ie, is either full or empty).
      Specified by:
      project in interface Region<Vector1D>
      Overrides:
      project in class AbstractRegionBSPTree<Vector1D,RegionBSPTree1D.RegionNode1D>
      Parameters:
      pt - pt to project
      Returns:
      projection of the point on the boundary of the region or null if the region does not contain any boundaries
    • split

      public Split<RegionBSPTree1D> split(Hyperplane<Vector1D> splitter)
      Split this instance with the given hyperplane.

      When splitting trees representing single points with a splitter lying directly on the point, the result point is placed on one side of the splitter based on its orientation: if the splitter is positive-facing, the point is placed on the plus side of the split; if the splitter is negative-facing, the point is placed on the minus side of the split.

      Parameters:
      splitter - the hyperplane to split this object with.
      Returns:
      result of the split operation
    • getMin

      public double getMin()
      Get the minimum value on the inside of the region; returns Double.NEGATIVE_INFINITY if the region does not have a minimum value and Double.POSITIVE_INFINITY if the region is empty.
      Returns:
      the minimum value on the inside of the region
    • getMax

      public double getMax()
      Get the maximum value on the inside of the region; returns Double.POSITIVE_INFINITY if the region does not have a maximum value and Double.NEGATIVE_INFINITY if the region is empty.
      Returns:
      the maximum value on the inside of the region
    • toIntervals

      public List<Interval> toIntervals()
      Convert the region represented by this tree into a list of separate Intervals, arranged in order of ascending min value.
      Returns:
      list of Intervals representing this region in order of ascending min value
    • createInterval

      Create an interval instance from the min boundary from the start boundary pair and the max boundary from the end boundary pair. The hyperplane directions are adjusted as needed.
      Parameters:
      start - starting boundary pair
      end - ending boundary pair
      Returns:
      an interval created from the min boundary of the given start pair and the max boundary from the given end pair
    • visitInsideIntervals

      private void visitInsideIntervals(BiConsumer<OrientedPoint,OrientedPoint> visitor)
      Compute the min/max intervals for all interior convex regions in the tree and pass the values to the given visitor function.
      Parameters:
      visitor - the object that will receive the calculated min and max boundary for each insides node's convex region
    • createNode

      protected RegionBSPTree1D.RegionNode1D createNode()
      Create a new node for this tree.
      Specified by:
      createNode in class AbstractBSPTree<Vector1D,RegionBSPTree1D.RegionNode1D>
      Returns:
      a new node for this tree
    • computeRegionSizeProperties

      protected AbstractRegionBSPTree.RegionSizeProperties<Vector1D> computeRegionSizeProperties()
      Compute the size-related properties of the region.
      Specified by:
      computeRegionSizeProperties in class AbstractRegionBSPTree<Vector1D,RegionBSPTree1D.RegionNode1D>
      Returns:
      object containing size properties for the region
    • swapsInsideOutside

      protected boolean swapsInsideOutside(Transform<Vector1D> transform)
      Returns true if the given transform would result in a swapping of the interior and exterior of the region if applied.

      This method always returns false since no swapping of this kind occurs in 1D.

      Overrides:
      swapsInsideOutside in class AbstractBSPTree<Vector1D,RegionBSPTree1D.RegionNode1D>
      Parameters:
      transform - transform to check
      Returns:
      true if the given transform swaps the interior and exterior of the region
    • full

      public static RegionBSPTree1D full()
      Return a new RegionBSPTree1D instance containing the entire space.
      Returns:
      a new RegionBSPTree1D instance containing the entire space
    • empty

      public static RegionBSPTree1D empty()
      Return a new, empty RegionBSPTree1D instance.
      Returns:
      a new, empty RegionBSPTree1D instance
    • from

      public static RegionBSPTree1D from(Interval interval, Interval... more)
      Construct a new instance from one or more intervals. The returned tree represents the same region as the union of all of the input intervals.
      Parameters:
      interval - the input interval
      more - additional intervals to add to the region
      Returns:
      a new instance representing the same region as the union of all of the given intervals
    • from

      public static RegionBSPTree1D from(Iterable<Interval> intervals)
      Construct a new instance from the given collection of intervals.
      Parameters:
      intervals - the intervals to populate the region with
      Returns:
      a new instance constructed from the given collection of intervals
    • intervalToTree

      private static RegionBSPTree1D intervalToTree(Interval interval)
      Return a tree representing the same region as the given interval.
      Parameters:
      interval - interval to create a tree from
      Returns:
      a tree representing the same region as the given interval