Class IntervalsSet
- java.lang.Object
-
- org.apache.commons.math3.geometry.partitioning.AbstractRegion<Euclidean1D,Euclidean1D>
-
- org.apache.commons.math3.geometry.euclidean.oned.IntervalsSet
-
- All Implemented Interfaces:
java.lang.Iterable<double[]>
,Region<Euclidean1D>
public class IntervalsSet extends AbstractRegion<Euclidean1D,Euclidean1D> implements java.lang.Iterable<double[]>
This class represents a 1D region: a set of intervals.- Since:
- 3.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
IntervalsSet.SubIntervalsIterator
Local iterator for sub-intervals.-
Nested classes/interfaces inherited from interface org.apache.commons.math3.geometry.partitioning.Region
Region.Location
-
-
Field Summary
Fields Modifier and Type Field Description private static double
DEFAULT_TOLERANCE
Default value for tolerance.
-
Constructor Summary
Constructors Constructor Description IntervalsSet()
Deprecated.as of 3.1 replaced withIntervalsSet(double)
IntervalsSet(double tolerance)
Build an intervals set representing the whole real line.IntervalsSet(double lower, double upper)
Deprecated.as of 3.3 replaced withIntervalsSet(double, double, double)
IntervalsSet(double lower, double upper, double tolerance)
Build an intervals set corresponding to a single interval.IntervalsSet(java.util.Collection<SubHyperplane<Euclidean1D>> boundary)
Deprecated.as of 3.3, replaced withIntervalsSet(Collection, double)
IntervalsSet(java.util.Collection<SubHyperplane<Euclidean1D>> boundary, double tolerance)
Build an intervals set from a Boundary REPresentation (B-rep).IntervalsSet(BSPTree<Euclidean1D> tree)
Deprecated.as of 3.3, replaced withIntervalsSet(BSPTree, double)
IntervalsSet(BSPTree<Euclidean1D> tree, double tolerance)
Build an intervals set from an inside/outside BSP tree.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.List<Interval>
asList()
Build an ordered list of intervals representing the instance.IntervalsSet
buildNew(BSPTree<Euclidean1D> tree)
Build a region using the instance as a prototype.private static BSPTree<Euclidean1D>
buildTree(double lower, double upper, double tolerance)
Build an inside/outside tree representing a single interval.private BSPTree<Euclidean1D>
childAfter(BSPTree<Euclidean1D> node)
Find the child node just after an internal node.private BSPTree<Euclidean1D>
childBefore(BSPTree<Euclidean1D> node)
Find the child node just before an internal node.protected void
computeGeometricalProperties()
Compute some geometrical properties.private Vector1D
finiteOrNullPoint(double x)
Build a finite point.private double
getAngle(BSPTree<Euclidean1D> node)
Get the abscissa of an internal node.private BSPTree<Euclidean1D>
getFirstIntervalBoundary()
Get the node corresponding to the first interval boundary.private BSPTree<Euclidean1D>
getFirstLeaf(BSPTree<Euclidean1D> root)
Get the first leaf node of a tree.double
getInf()
Get the lowest value belonging to the instance.double
getSup()
Get the highest value belonging to the instance.private boolean
isAfterParent(BSPTree<Euclidean1D> node)
Check if a node is the child after its parent in ascending order.private boolean
isBeforeParent(BSPTree<Euclidean1D> node)
Check if a node is the child before its parent in ascending order.private boolean
isDirect(BSPTree<Euclidean1D> node)
Check if an internal node has a direct oriented point.private boolean
isIntervalEnd(BSPTree<Euclidean1D> node)
Check if an internal node corresponds to the end abscissa of an interval.private boolean
isIntervalStart(BSPTree<Euclidean1D> node)
Check if an internal node corresponds to the start abscissa of an interval.java.util.Iterator<double[]>
iterator()
private BSPTree<Euclidean1D>
leafAfter(BSPTree<Euclidean1D> node)
Find the leaf node just after an internal node.private BSPTree<Euclidean1D>
leafBefore(BSPTree<Euclidean1D> node)
Find the leaf node just before an internal node.private BSPTree<Euclidean1D>
nextInternalNode(BSPTree<Euclidean1D> node)
Get the next internal node.private BSPTree<Euclidean1D>
previousInternalNode(BSPTree<Euclidean1D> node)
Get the previous internal node.BoundaryProjection<Euclidean1D>
projectToBoundary(Point<Euclidean1D> point)
Project a point on the boundary of the region.-
Methods inherited from class org.apache.commons.math3.geometry.partitioning.AbstractRegion
applyTransform, checkPoint, checkPoint, checkPoint, checkPoint, contains, copySelf, getBarycenter, getBoundarySize, getSize, getTolerance, getTree, intersection, isEmpty, isEmpty, isFull, isFull, setBarycenter, setBarycenter, setSize, side
-
-
-
-
Field Detail
-
DEFAULT_TOLERANCE
private static final double DEFAULT_TOLERANCE
Default value for tolerance.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
IntervalsSet
public IntervalsSet(double tolerance)
Build an intervals set representing the whole real line.- Parameters:
tolerance
- tolerance below which points are considered identical.- Since:
- 3.3
-
IntervalsSet
public IntervalsSet(double lower, double upper, double tolerance)
Build an intervals set corresponding to a single interval.- Parameters:
lower
- lower bound of the interval, must be lesser or equal toupper
(may beDouble.NEGATIVE_INFINITY
)upper
- upper bound of the interval, must be greater or equal tolower
(may beDouble.POSITIVE_INFINITY
)tolerance
- tolerance below which points are considered identical.- Since:
- 3.3
-
IntervalsSet
public IntervalsSet(BSPTree<Euclidean1D> tree, double tolerance)
Build an intervals set from an inside/outside BSP tree.The leaf nodes of the BSP tree must have a
Boolean
attribute representing the inside status of the corresponding cell (true for inside cells, false for outside cells). In order to avoid building too many small objects, it is recommended to use the predefined constantsBoolean.TRUE
andBoolean.FALSE
- Parameters:
tree
- inside/outside BSP tree representing the intervals settolerance
- tolerance below which points are considered identical.- Since:
- 3.3
-
IntervalsSet
public IntervalsSet(java.util.Collection<SubHyperplane<Euclidean1D>> boundary, double tolerance)
Build an intervals set from a Boundary REPresentation (B-rep).The boundary is provided as a collection of
sub-hyperplanes
. Each sub-hyperplane has the interior part of the region on its minus side and the exterior on its plus side.The boundary elements can be in any order, and can form several non-connected sets (like for example polygons with holes or a set of disjoints polyhedrons considered as a whole). In fact, the elements do not even need to be connected together (their topological connections are not used here). However, if the boundary does not really separate an inside open from an outside open (open having here its topological meaning), then subsequent calls to the
checkPoint
method will not be meaningful anymore.If the boundary is empty, the region will represent the whole space.
- Parameters:
boundary
- collection of boundary elementstolerance
- tolerance below which points are considered identical.- Since:
- 3.3
-
IntervalsSet
@Deprecated public IntervalsSet()
Deprecated.as of 3.1 replaced withIntervalsSet(double)
Build an intervals set representing the whole real line.
-
IntervalsSet
@Deprecated public IntervalsSet(double lower, double upper)
Deprecated.as of 3.3 replaced withIntervalsSet(double, double, double)
Build an intervals set corresponding to a single interval.- Parameters:
lower
- lower bound of the interval, must be lesser or equal toupper
(may beDouble.NEGATIVE_INFINITY
)upper
- upper bound of the interval, must be greater or equal tolower
(may beDouble.POSITIVE_INFINITY
)
-
IntervalsSet
@Deprecated public IntervalsSet(BSPTree<Euclidean1D> tree)
Deprecated.as of 3.3, replaced withIntervalsSet(BSPTree, double)
Build an intervals set from an inside/outside BSP tree.The leaf nodes of the BSP tree must have a
Boolean
attribute representing the inside status of the corresponding cell (true for inside cells, false for outside cells). In order to avoid building too many small objects, it is recommended to use the predefined constantsBoolean.TRUE
andBoolean.FALSE
- Parameters:
tree
- inside/outside BSP tree representing the intervals set
-
IntervalsSet
@Deprecated public IntervalsSet(java.util.Collection<SubHyperplane<Euclidean1D>> boundary)
Deprecated.as of 3.3, replaced withIntervalsSet(Collection, double)
Build an intervals set from a Boundary REPresentation (B-rep).The boundary is provided as a collection of
sub-hyperplanes
. Each sub-hyperplane has the interior part of the region on its minus side and the exterior on its plus side.The boundary elements can be in any order, and can form several non-connected sets (like for example polygons with holes or a set of disjoints polyhedrons considered as a whole). In fact, the elements do not even need to be connected together (their topological connections are not used here). However, if the boundary does not really separate an inside open from an outside open (open having here its topological meaning), then subsequent calls to the
checkPoint
method will not be meaningful anymore.If the boundary is empty, the region will represent the whole space.
- Parameters:
boundary
- collection of boundary elements
-
-
Method Detail
-
buildTree
private static BSPTree<Euclidean1D> buildTree(double lower, double upper, double tolerance)
Build an inside/outside tree representing a single interval.- Parameters:
lower
- lower bound of the interval, must be lesser or equal toupper
(may beDouble.NEGATIVE_INFINITY
)upper
- upper bound of the interval, must be greater or equal tolower
(may beDouble.POSITIVE_INFINITY
)tolerance
- tolerance below which points are considered identical.- Returns:
- the built tree
-
buildNew
public IntervalsSet buildNew(BSPTree<Euclidean1D> tree)
Build a region using the instance as a prototype.This method allow to create new instances without knowing exactly the type of the region. It is an application of the prototype design pattern.
The leaf nodes of the BSP tree must have a
Boolean
attribute representing the inside status of the corresponding cell (true for inside cells, false for outside cells). In order to avoid building too many small objects, it is recommended to use the predefined constantsBoolean.TRUE
andBoolean.FALSE
. The tree also must have either null internal nodes or internal nodes representing the boundary as specified in thegetTree
method).- Specified by:
buildNew
in interfaceRegion<Euclidean1D>
- Specified by:
buildNew
in classAbstractRegion<Euclidean1D,Euclidean1D>
- Parameters:
tree
- inside/outside BSP tree representing the new region- Returns:
- the built region
-
computeGeometricalProperties
protected void computeGeometricalProperties()
Compute some geometrical properties.The properties to compute are the barycenter and the size.
- Specified by:
computeGeometricalProperties
in classAbstractRegion<Euclidean1D,Euclidean1D>
-
getInf
public double getInf()
Get the lowest value belonging to the instance.- Returns:
- lowest value belonging to the instance
(
Double.NEGATIVE_INFINITY
if the instance doesn't have any low bound,Double.POSITIVE_INFINITY
if the instance is empty)
-
getSup
public double getSup()
Get the highest value belonging to the instance.- Returns:
- highest value belonging to the instance
(
Double.POSITIVE_INFINITY
if the instance doesn't have any high bound,Double.NEGATIVE_INFINITY
if the instance is empty)
-
projectToBoundary
public BoundaryProjection<Euclidean1D> projectToBoundary(Point<Euclidean1D> point)
Project a point on the boundary of the region.- Specified by:
projectToBoundary
in interfaceRegion<Euclidean1D>
- Overrides:
projectToBoundary
in classAbstractRegion<Euclidean1D,Euclidean1D>
- Parameters:
point
- point to check- Returns:
- projection of the point on the boundary
- Since:
- 3.3
-
finiteOrNullPoint
private Vector1D finiteOrNullPoint(double x)
Build a finite point.- Parameters:
x
- abscissa of the point- Returns:
- a new point for finite abscissa, null otherwise
-
asList
public java.util.List<Interval> asList()
Build an ordered list of intervals representing the instance.This method builds this intervals set as an ordered list of
Interval
elements. If the intervals set has no lower limit, the first interval will have its low bound equal toDouble.NEGATIVE_INFINITY
. If the intervals set has no upper limit, the last interval will have its upper bound equal toDouble.POSITIVE_INFINITY
. An empty tree will build an empty list while a tree representing the whole real line will build a one element list with both bounds being infinite.- Returns:
- a new ordered list containing
Interval
elements
-
getFirstLeaf
private BSPTree<Euclidean1D> getFirstLeaf(BSPTree<Euclidean1D> root)
Get the first leaf node of a tree.- Parameters:
root
- tree root- Returns:
- first leaf node
-
getFirstIntervalBoundary
private BSPTree<Euclidean1D> getFirstIntervalBoundary()
Get the node corresponding to the first interval boundary.- Returns:
- smallest internal node, or null if there are no internal nodes (i.e. the set is either empty or covers the real line)
-
isIntervalStart
private boolean isIntervalStart(BSPTree<Euclidean1D> node)
Check if an internal node corresponds to the start abscissa of an interval.- Parameters:
node
- internal node to check- Returns:
- true if the node corresponds to the start abscissa of an interval
-
isIntervalEnd
private boolean isIntervalEnd(BSPTree<Euclidean1D> node)
Check if an internal node corresponds to the end abscissa of an interval.- Parameters:
node
- internal node to check- Returns:
- true if the node corresponds to the end abscissa of an interval
-
nextInternalNode
private BSPTree<Euclidean1D> nextInternalNode(BSPTree<Euclidean1D> node)
Get the next internal node.- Parameters:
node
- current internal node- Returns:
- next internal node in ascending order, or null if this is the last internal node
-
previousInternalNode
private BSPTree<Euclidean1D> previousInternalNode(BSPTree<Euclidean1D> node)
Get the previous internal node.- Parameters:
node
- current internal node- Returns:
- previous internal node in ascending order, or null if this is the first internal node
-
leafBefore
private BSPTree<Euclidean1D> leafBefore(BSPTree<Euclidean1D> node)
Find the leaf node just before an internal node.- Parameters:
node
- internal node at which the sub-tree starts- Returns:
- leaf node just before the internal node
-
leafAfter
private BSPTree<Euclidean1D> leafAfter(BSPTree<Euclidean1D> node)
Find the leaf node just after an internal node.- Parameters:
node
- internal node at which the sub-tree starts- Returns:
- leaf node just after the internal node
-
isBeforeParent
private boolean isBeforeParent(BSPTree<Euclidean1D> node)
Check if a node is the child before its parent in ascending order.- Parameters:
node
- child node considered- Returns:
- true is the node has a parent end is before it in ascending order
-
isAfterParent
private boolean isAfterParent(BSPTree<Euclidean1D> node)
Check if a node is the child after its parent in ascending order.- Parameters:
node
- child node considered- Returns:
- true is the node has a parent end is after it in ascending order
-
childBefore
private BSPTree<Euclidean1D> childBefore(BSPTree<Euclidean1D> node)
Find the child node just before an internal node.- Parameters:
node
- internal node at which the sub-tree starts- Returns:
- child node just before the internal node
-
childAfter
private BSPTree<Euclidean1D> childAfter(BSPTree<Euclidean1D> node)
Find the child node just after an internal node.- Parameters:
node
- internal node at which the sub-tree starts- Returns:
- child node just after the internal node
-
isDirect
private boolean isDirect(BSPTree<Euclidean1D> node)
Check if an internal node has a direct oriented point.- Parameters:
node
- internal node to check- Returns:
- true if the oriented point is direct
-
getAngle
private double getAngle(BSPTree<Euclidean1D> node)
Get the abscissa of an internal node.- Parameters:
node
- internal node to check- Returns:
- abscissa
-
iterator
public java.util.Iterator<double[]> iterator()
The iterator returns the limit values of sub-intervals in ascending order.
The iterator does not support the optional
remove
operation.- Specified by:
iterator
in interfacejava.lang.Iterable<double[]>
- Since:
- 3.3
-
-