Class Circle.CircleApproximationBuilder

  • Enclosing class:
    Circle

    private static class Circle.CircleApproximationBuilder
    extends java.lang.Object
    Class used to build BSP tree circle approximations. Structural BSP tree cuts are used to help balance the tree and improve performance.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private double angleDelta
      Angle delta between vertex points.
      private Circle circle
      Circle being approximated.
      private static int MIN_SEGMENTS
      The minimum number of segments required to create a circle approximation.
      private int segments
      Number of boundary segments in the approximation.
      private static int SPLIT_THRESHOLD
      Minimum number of line segments in a portion of the approximation in order to allow a structural BSP split.
    • Constructor Summary

      Constructors 
      Constructor Description
      CircleApproximationBuilder​(Circle circle, int segments)
      Create a new instance for approximating the given circle.
    • Field Detail

      • MIN_SEGMENTS

        private static final int MIN_SEGMENTS
        The minimum number of segments required to create a circle approximation.
        See Also:
        Constant Field Values
      • SPLIT_THRESHOLD

        private static final int SPLIT_THRESHOLD
        Minimum number of line segments in a portion of the approximation in order to allow a structural BSP split.
        See Also:
        Constant Field Values
      • circle

        private final Circle circle
        Circle being approximated.
      • segments

        private final int segments
        Number of boundary segments in the approximation.
      • angleDelta

        private final double angleDelta
        Angle delta between vertex points.
    • Constructor Detail

      • CircleApproximationBuilder

        CircleApproximationBuilder​(Circle circle,
                                   int segments)
        Create a new instance for approximating the given circle.
        Parameters:
        circle - circle to approximate
        segments - number of boundary segments in the approximation
        Throws:
        java.lang.IllegalArgumentException - if segments is less than 3
    • Method Detail

      • build

        public RegionBSPTree2D build()
        Build the BSP tree circle approximation.
        Returns:
        the BSP tree circle approximation
      • splitAndInsert

        private void splitAndInsert​(RegionBSPTree2D.RegionNode2D node,
                                    int startIdx,
                                    int stopIdx)
        Split the given node if possible and recursively add boundary segments.
        Parameters:
        node - current tree node
        startIdx - index of the start point for this node's boundary segments
        stopIdx - index of the end point for this node's boundary segments
      • insert

        private void insert​(RegionBSPTree2D.RegionNode2D node,
                            int startIdx,
                            int stopIdx)
        Insert boundary segments into the given node. No structural splits are created.
        Parameters:
        node - current tree node
        startIdx - index of the start point for this node's boundary segments
        stopIdx - index of the end point for this node's boundary segments
      • pointAt

        private Vector2D pointAt​(int idx)
        Get the boundary vertex point at the given index.
        Parameters:
        idx - vertex point index
        Returns:
        the vertex point at the given index