Class AbstractBounds<P extends EuclideanVector<P>,B extends AbstractBounds<P,B>>
- java.lang.Object
-
- org.apache.commons.geometry.euclidean.AbstractBounds<P,B>
-
- Type Parameters:
P
- Point implementation typeB
- Bounds implementation type
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.
-
-
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()
-
-
-
Field Detail
-
min
private final P extends EuclideanVector<P> min
Minimum point.
-
max
private final P extends EuclideanVector<P> max
Maximum point.
-
-
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 inmin
are less than or equal to their corresponding values inmax
. No validation is performed.- Parameters:
min
- minimum pointmax
- 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 frommin
tomax
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 ifpt >= mint
andpt <= maxt
for each coordinate valuet
. 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 tocontains(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 checkprecision
- 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 ifaMint <= bMaxt
andaMaxt >= bMint
for all coordinate valuest
, wherea
is the current instance andb
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 withprecision
- 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 classjava.lang.Object
-
-