Class AbstractBounds<P extends EuclideanVector<P>,​B extends AbstractBounds<P,​B>>

  • Type Parameters:
    P - Point implementation type
    B - Bounds implementation type
    Direct Known Subclasses:
    Bounds2D, Bounds3D

    public abstract class AbstractBounds<P extends EuclideanVector<P>,​B extends AbstractBounds<P,​B>>
    extends java.lang.Object
    Base class representing an axis-aligned bounding box with minimum and maximum bounding points.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private P max
      Maximum point.
      private P min
      Minimum point.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected AbstractBounds​(P min, P max)
      Simple constructor.
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      abstract boolean contains​(P pt)
      Return true if the given point is strictly within or on the boundary of the bounding box.
      abstract boolean contains​(P pt, org.apache.commons.numbers.core.Precision.DoubleEquivalence precision)
      Return true if the given point is within or on the boundary of the bounding box, using the given precision context for floating point comparisons.
      boolean eq​(B other, org.apache.commons.numbers.core.Precision.DoubleEquivalence precision)
      Return true if the current instance and argument are considered equal as evaluated by the given precision context.
      P getCentroid()
      Get the centroid, or geometric center, of the bounding box.
      P getDiagonal()
      Get the diagonal of the bounding box.
      P getMax()
      Get the maximum point.
      P getMin()
      Get the minimum point.
      abstract boolean hasSize​(org.apache.commons.numbers.core.Precision.DoubleEquivalence precision)
      Return true if the bounding box has non-zero size along each coordinate axis, as evaluated by the given precision context.
      abstract B intersection​(B other)
      Return the intersection of this bounding box and the argument, or null if no intersection exists.
      abstract boolean intersects​(B other)
      Return true if any point on the interior or boundary of this instance is also considered to be on the interior or boundary of the argument.
      abstract HyperplaneBoundedRegion<P> toRegion​(org.apache.commons.numbers.core.Precision.DoubleEquivalence precision)
      Return a hyperplane-bounded region containing the same points as this instance.
      java.lang.String toString()
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • AbstractBounds

        protected AbstractBounds​(P min,
                                 P max)
        Simple constructor. Callers are responsible for ensuring that all coordinate values are finite and that all values in min are less than or equal to their corresponding values in max. No validation is performed.
        Parameters:
        min - minimum point
        max - maximum point
    • Method Detail

      • getMin

        public P getMin()
        Get the minimum point.
        Returns:
        the minimum point
      • getMax

        public P getMax()
        Get the maximum point.
        Returns:
        the maximum point
      • getDiagonal

        public P getDiagonal()
        Get the diagonal of the bounding box. The return value is a vector pointing from min to max and contains the size of the box along each coordinate axis.
        Returns:
        the diagonal vector of the bounding box
      • getCentroid

        public P getCentroid()
        Get the centroid, or geometric center, of the bounding box.
        Returns:
        the centroid of the bounding box
      • hasSize

        public abstract boolean hasSize​(org.apache.commons.numbers.core.Precision.DoubleEquivalence precision)
        Return true if the bounding box has non-zero size along each coordinate axis, as evaluated by the given precision context.
        Parameters:
        precision - precision context used for floating point comparisons
        Returns:
        true if the bounding box has non-zero size along each coordinate axis
      • contains

        public abstract boolean contains​(P pt)
        Return true if the given point is strictly within or on the boundary of the bounding box. In other words, true if returned if pt >= mint and pt <= maxt for each coordinate value t. Floating point comparisons are strict; values are considered equal only if they match exactly.
        Parameters:
        pt - the point to check
        Returns:
        true if the given point is strictly within or on the boundary of the instance
        See Also:
        contains(EuclideanVector, Precision.DoubleEquivalence)
      • contains

        public abstract boolean contains​(P pt,
                                         org.apache.commons.numbers.core.Precision.DoubleEquivalence precision)
        Return true if the given point is within or on the boundary of the bounding box, using the given precision context for floating point comparisons. This is similar to contains(EuclideanVector) but allows points that may be strictly outside of the box due to floating point errors to be considered inside.
        Parameters:
        pt - the point to check
        precision - precision context used to compare floating point values
        Returns:
        if the given point is within or on the boundary of the bounds, as determined by the given precision context
        See Also:
        contains(EuclideanVector, Precision.DoubleEquivalence)
      • intersects

        public abstract boolean intersects​(B other)
        Return true if any point on the interior or boundary of this instance is also considered to be on the interior or boundary of the argument. Specifically, true is returned if aMint <= bMaxt and aMaxt >= bMint for all coordinate values t, where a is the current instance and b is the argument. Floating point comparisons are strict; values are considered equal only if they match exactly.
        Parameters:
        other - bounding box to intersect with
        Returns:
        true if the bounds intersect
      • intersection

        public abstract B intersection​(B other)
        Return the intersection of this bounding box and the argument, or null if no intersection exists. Floating point comparisons are strict; values are considered equal only if they match exactly. Note this this method may return bounding boxes with zero size in one or more coordinate axes.
        Parameters:
        other - bounding box to intersect with
        Returns:
        the intersection of this instance and the argument, or null if no such intersection exists
        See Also:
        intersects(AbstractBounds)
      • toRegion

        public abstract HyperplaneBoundedRegion<P> toRegion​(org.apache.commons.numbers.core.Precision.DoubleEquivalence precision)
        Return a hyperplane-bounded region containing the same points as this instance.
        Parameters:
        precision - precision context used for floating point comparisons in the returned region instance
        Returns:
        a hyperplane-bounded region containing the same points as this instance
      • eq

        public boolean eq​(B other,
                          org.apache.commons.numbers.core.Precision.DoubleEquivalence precision)
        Return true if the current instance and argument are considered equal as evaluated by the given precision context. Bounds are considered equal if they contain equivalent min and max points.
        Parameters:
        other - bounds to compare with
        precision - precision context to compare floating point numbers
        Returns:
        true if this instance is equivalent to the argument, as evaluated by the given precision context
        See Also:
        EuclideanVector.eq(EuclideanVector, Precision.DoubleEquivalence)
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object