Class ArcsSet

  • All Implemented Interfaces:
    java.lang.Iterable<double[]>, Region<Sphere1D>

    public class ArcsSet
    extends AbstractRegion<Sphere1D,​Sphere1D>
    implements java.lang.Iterable<double[]>
    This class represents a region of a circle: a set of arcs.

    Note that due to the wrapping around \(2 \pi\), barycenter is ill-defined here. It was defined only in order to fulfill the requirements of the Region interface, but its use is discouraged.

    Since:
    3.3
    • Constructor Detail

      • ArcsSet

        public ArcsSet​(double tolerance)
        Build an arcs set representing the whole circle.
        Parameters:
        tolerance - tolerance below which close sub-arcs are merged together
      • ArcsSet

        public ArcsSet​(double lower,
                       double upper,
                       double tolerance)
                throws NumberIsTooLargeException
        Build an arcs set corresponding to a single arc.

        If either lower is equals to upper or the interval exceeds \( 2 \pi \), the arc is considered to be the full circle and its initial defining boundaries will be forgotten. lower is not allowed to be greater than upper (an exception is thrown in this case).

        Parameters:
        lower - lower bound of the arc
        upper - upper bound of the arc
        tolerance - tolerance below which close sub-arcs are merged together
        Throws:
        NumberIsTooLargeException - if lower is greater than upper
      • ArcsSet

        public ArcsSet​(BSPTree<Sphere1D> tree,
                       double tolerance)
                throws ArcsSet.InconsistentStateAt2PiWrapping
        Build an arcs 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 constants Boolean.TRUE and Boolean.FALSE

        Parameters:
        tree - inside/outside BSP tree representing the arcs set
        tolerance - tolerance below which close sub-arcs are merged together
        Throws:
        ArcsSet.InconsistentStateAt2PiWrapping - if the tree leaf nodes are not consistent across the \( 0, 2 \pi \) crossing
      • ArcsSet

        public ArcsSet​(java.util.Collection<SubHyperplane<Sphere1D>> boundary,
                       double tolerance)
                throws ArcsSet.InconsistentStateAt2PiWrapping
        Build an arcs 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
        tolerance - tolerance below which close sub-arcs are merged together
        Throws:
        ArcsSet.InconsistentStateAt2PiWrapping - if the tree leaf nodes are not consistent across the \( 0, 2 \pi \) crossing
    • Method Detail

      • buildTree

        private static BSPTree<Sphere1D> buildTree​(double lower,
                                                   double upper,
                                                   double tolerance)
                                            throws NumberIsTooLargeException
        Build an inside/outside tree representing a single arc.
        Parameters:
        lower - lower angular bound of the arc
        upper - upper angular bound of the arc
        tolerance - tolerance below which close sub-arcs are merged together
        Returns:
        the built tree
        Throws:
        NumberIsTooLargeException - if lower is greater than upper
      • getFirstLeaf

        private BSPTree<Sphere1D> getFirstLeaf​(BSPTree<Sphere1D> root)
        Get the first leaf node of a tree.
        Parameters:
        root - tree root
        Returns:
        first leaf node (i.e. node corresponding to the region just after 0.0 radians)
      • getLastLeaf

        private BSPTree<Sphere1D> getLastLeaf​(BSPTree<Sphere1D> root)
        Get the last leaf node of a tree.
        Parameters:
        root - tree root
        Returns:
        last leaf node (i.e. node corresponding to the region just before \( 2 \pi \) radians)
      • getFirstArcStart

        private BSPTree<Sphere1D> getFirstArcStart()
        Get the node corresponding to the first arc start.
        Returns:
        smallest internal node (i.e. first after 0.0 radians, in trigonometric direction), or null if there are no internal nodes (i.e. the set is either empty or covers the full circle)
      • isArcStart

        private boolean isArcStart​(BSPTree<Sphere1D> node)
        Check if an internal node corresponds to the start angle of an arc.
        Parameters:
        node - internal node to check
        Returns:
        true if the node corresponds to the start angle of an arc
      • isArcEnd

        private boolean isArcEnd​(BSPTree<Sphere1D> node)
        Check if an internal node corresponds to the end angle of an arc.
        Parameters:
        node - internal node to check
        Returns:
        true if the node corresponds to the end angle of an arc
      • nextInternalNode

        private BSPTree<Sphere1D> nextInternalNode​(BSPTree<Sphere1D> node)
        Get the next internal node.
        Parameters:
        node - current internal node
        Returns:
        next internal node in trigonometric order, or null if this is the last internal node
      • previousInternalNode

        private BSPTree<Sphere1D> previousInternalNode​(BSPTree<Sphere1D> node)
        Get the previous internal node.
        Parameters:
        node - current internal node
        Returns:
        previous internal node in trigonometric order, or null if this is the first internal node
      • leafBefore

        private BSPTree<Sphere1D> leafBefore​(BSPTree<Sphere1D> 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<Sphere1D> leafAfter​(BSPTree<Sphere1D> 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<Sphere1D> node)
        Check if a node is the child before its parent in trigonometric order.
        Parameters:
        node - child node considered
        Returns:
        true is the node has a parent end is before it in trigonometric order
      • isAfterParent

        private boolean isAfterParent​(BSPTree<Sphere1D> node)
        Check if a node is the child after its parent in trigonometric order.
        Parameters:
        node - child node considered
        Returns:
        true is the node has a parent end is after it in trigonometric order
      • childBefore

        private BSPTree<Sphere1D> childBefore​(BSPTree<Sphere1D> 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<Sphere1D> childAfter​(BSPTree<Sphere1D> 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<Sphere1D> node)
        Check if an internal node has a direct limit angle.
        Parameters:
        node - internal node to check
        Returns:
        true if the limit angle is direct
      • getAngle

        private double getAngle​(BSPTree<Sphere1D> node)
        Get the limit angle of an internal node.
        Parameters:
        node - internal node to check
        Returns:
        limit angle
      • buildNew

        public ArcsSet buildNew​(BSPTree<Sphere1D> 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 constants Boolean.TRUE and Boolean.FALSE. The tree also must have either null internal nodes or internal nodes representing the boundary as specified in the getTree method).

        Specified by:
        buildNew in interface Region<Sphere1D>
        Specified by:
        buildNew in class AbstractRegion<Sphere1D,​Sphere1D>
        Parameters:
        tree - inside/outside BSP tree representing the new region
        Returns:
        the built region
      • asList

        public java.util.List<Arc> asList()
        Build an ordered list of arcs representing the instance.

        This method builds this arcs set as an ordered list of Arc elements. An empty tree will build an empty list while a tree representing the whole circle will build a one element list with bounds set to \( 0 and 2 \pi \).

        Returns:
        a new ordered list containing Arc elements
      • iterator

        public java.util.Iterator<double[]> iterator()

        The iterator returns the limit angles pairs of sub-arcs in trigonometric order.

        The iterator does not support the optional remove operation.

        Specified by:
        iterator in interface java.lang.Iterable<double[]>
      • split

        public ArcsSet.Split split​(Arc arc)
        Split the instance in two parts by an arc.
        Parameters:
        arc - splitting arc
        Returns:
        an object containing both the part of the instance on the plus side of the arc and the part of the instance on the minus side of the arc
      • addArcLimit

        private void addArcLimit​(BSPTree<Sphere1D> tree,
                                 double alpha,
                                 boolean isStart)
        Add an arc limit to a BSP tree under construction.
        Parameters:
        tree - BSP tree under construction
        alpha - arc limit
        isStart - if true, the limit is the start of an arc
      • createSplitPart

        private ArcsSet createSplitPart​(java.util.List<java.lang.Double> limits)
        Create a split part.

        As per construction, the list of limit angles is known to have an even number of entries, with start angles at even indices and end angles at odd indices.

        Parameters:
        limits - limit angles of the split part
        Returns:
        split part (may be null)