예제 #1
0
 /// <summary>Create a new instance with a specific search result count</summary>
 /// <param name="search_start">Node to search from.</param>
 /// <param name="search_start_index">Index of base node (this index will be ignored during the search).</param>
 /// <param name="max_results">Maximum number of results to return.</param>
 public Node2Proximity(Node2 search_start, int search_start_index, int max_results)
 {
     this.m_max_count    = 1;
     this.m_cur_count    = 0;
     this.m_min_distance = double.MinValue;
     this.m_max_distance = double.MaxValue;
     this.m_min_2        = double.MinValue;
     this.m_max_2        = double.MaxValue;
     this.m_base_index   = -1;
     this.m_D            = new List <double>();
     this.m_I            = new List <int>();
     this.m_base         = search_start;
     this.m_base_index   = search_start_index;
     this.m_max_count    = Math.Max(max_results, 1);
     this.ResetLists();
 }
예제 #2
0
        public static Line2 MidLine(Node2 A, Node2 B)
        {
            Line2 line2;

            if (Math.Abs(A.DistanceSquared(B)) < Line2.tolerance)
            {
                line2 = (Line2)null;
            }
            else
            {
                double nAx  = 0.5 * (A.x + B.x);
                double nAy  = 0.5 * (A.y + B.y);
                double num1 = B.x - A.x;
                double num2 = B.y - A.y;
                line2 = new Line2(nAx, nAy, nAx + num2, nAy - num1);
            }
            return(line2);
        }
예제 #3
0
        public static Line2 MidLine(Node2 A, Node2 B, double Wa, double Wb)
        {
            Line2 line2;

            if (Math.Abs(A.DistanceSquared(B)) < Line2.tolerance)
            {
                line2 = (Line2)null;
            }
            else
            {
                double num1 = Wa / (Wa + Wb);
                double nAx  = A.x + num1 * (B.x - A.x);
                double nAy  = A.y + num1 * (B.y - A.y);
                double num2 = B.x - A.x;
                double num3 = B.y - A.y;
                line2 = new Line2(nAx, nAy, nAx + num3, nAy - num2);
            }
            return(line2);
        }
예제 #4
0
 /// <summary>Create a new instance with a specific search result count</summary>
 /// <param name="search_start">Node to search from.</param>
 /// <param name="search_start_index">Index of base node (this index will be ignored during the search).</param>
 /// <param name="max_results">Maximum number of results to return.</param>
 /// <param name="min_distance">Minimum allowed distance for search results.</param>
 /// <param name="max_distance">Maximum allowed distance for search results.</param>
 public Node2Proximity(
     Node2 search_start,
     int search_start_index,
     int max_results,
     double min_distance,
     double max_distance)
     : this(search_start, search_start_index, max_results)
 {
     this.m_min_distance = min_distance;
     this.m_max_distance = max_distance;
     this.m_max_2        = this.m_max_distance < Math.Sqrt(1E+300) ? Math.Pow(this.m_max_distance, 2.0) : double.MaxValue;
     if (this.m_min_distance < 0.0)
     {
         this.m_min_2 = double.MinValue;
     }
     else
     {
         this.m_min_2 = Math.Pow(this.m_min_distance, 2.0);
     }
 }
예제 #5
0
 /// <summary>Create a circle from origin and radius</summary>
 /// <param name="origin">Origin point of circle</param>
 /// <param name="radius">Radius of circle (&gt;0.0 for valid circle)</param>
 public Circle2(Node2 origin, double radius)
 {
     this.O = origin;
     this.R = radius;
 }
예제 #6
0
 public Containment Contains(Node2 pt)
 {
     return(this.Contains(pt.x, pt.y));
 }
예제 #7
0
 public Node2 ClosestPointTo(Node2 pt, ref double t)
 {
     return(this.ClosestPointTo(pt.x, pt.y, ref t));
 }
예제 #8
0
 public double ClosestPointTo(Node2 pt)
 {
     return(this.ClosestPointTo(pt.x, pt.y));
 }
예제 #9
0
        /// <summary>Builds a subtree from a Node list.</summary>
        /// <param name="nodes">All the nodes that are supposed to be included in this tree.</param>
        /// <param name="index_subset">A subset of nodes on which to perform the subdivision. Pass a null-pointer to use ALL nodes.
        /// If the list is not null, used indices will be extracted from the list, in order to reduce the number of pointless inclusion tests.</param>
        /// <param name="group_limit">The number of allowed Nodes per Leaf. If a Leaf contains more than N nodes, it will subdivide.</param>
        public void SubDivide(Node2List nodes, List <int> index_subset, int group_limit)
        {
            this.m_nodes = new List <int>(nodes.Count);
            this.m_A     = (Node2Leaf)null;
            this.m_B     = (Node2Leaf)null;
            this.m_C     = (Node2Leaf)null;
            this.m_D     = (Node2Leaf)null;
            if (index_subset == null)
            {
                int num = nodes.Count - 1;
                for (int index = 0; index <= num; ++index)
                {
                    this.m_nodes.Add(index);
                }
            }
            else
            {
                int num1   = index_subset.Count - 1;
                int index1 = 0;
                int num2   = num1;
                for (int index2 = 0; index2 <= num2; ++index2)
                {
                    int   index3 = index_subset[index2];
                    Node2 node   = nodes[index3];
                    if (node != null)
                    {
                        if (this.Contains(node.x, node.y))
                        {
                            this.m_nodes.Add(index3);
                        }
                        else
                        {
                            index_subset[index1] = index3;
                            ++index1;
                        }
                    }
                }
                if (index1 < index_subset.Count)
                {
                    if (index1 == 0)
                    {
                        index_subset.Clear();
                    }
                    else
                    {
                        index_subset.RemoveRange(index1, index_subset.Count - index1);
                    }
                }
            }
            double num3 = (this.m_x1 - this.m_x0) * (this.m_x1 - this.m_x0) + (this.m_y1 - this.m_y0) * (this.m_y1 - this.m_y0);

            if (this.m_nodes.Count > group_limit && num3 > 1E-08)
            {
                this.CreateSubLeafs();
                this.m_A.SubDivide(nodes, this.m_nodes, group_limit);
                this.m_B.SubDivide(nodes, this.m_nodes, group_limit);
                this.m_C.SubDivide(nodes, this.m_nodes, group_limit);
                this.m_D.SubDivide(nodes, this.m_nodes, group_limit);
                this.TrimSubLeafs();
                this.m_nodes = (List <int>)null;
            }
            else if (this.m_nodes.Count == 0)
            {
                this.m_nodes = (List <int>)null;
            }
            else
            {
                this.m_nodes.TrimExcess();
            }
        }
예제 #10
0
 /// <summary>Create a new instance for a single result.</summary>
 /// <param name="search_start">Node to search from.</param>
 /// <param name="search_start_index">Index of base node (this index will be ignored during the search).</param>
 public Node2Proximity(Node2 search_start, int search_start_index)
     : this(search_start, search_start_index, 1)
 {
 }
예제 #11
0
 public double DistanceToSquared(Node2 pt)
 {
     return(this.DistanceToSquared(pt.x, pt.y));
 }
예제 #12
0
 public static Side2 Side(Line2 edge, Node2 pt)
 {
     return(Line2.Side(edge.Ax, edge.Ay, edge.Bx, edge.By, pt.x, pt.y));
 }