コード例 #1
0
        public void addPoint(Vector2 point, bool addToList = true, bool wait = false)
        {
            if (addToList)
            {
                points.Add(point);
            }

            edges = new List <edge>();


            if (_convexHull.ContainPoint(point))
            {
                for (int i = 0; i < triangles.Count; i++)
                {
                    if (triangles[i].ContainPoint(point))
                    {
                        for (int j = 0; j < triangles[i].segments.Length; j++)
                        {
                            edges.Add(triangles[i].segments[j]);
                        }
                        break;
                    }
                }//end for
            }
            else
            {
                for (int i = 0; i < _convexHull.segments.Length; i++)
                {
                    if (_convexHull.segments[i].seePoint(point))
                    {
                        edges.Add(_convexHull.segments[i]);
                    }
                }
            }



            int safelock = 0;

            while (edges.Count > 0)
            {
                edge current = edges[0];
                edges.RemoveAt(0);

                bool intriangle = false;
                for (int i = 0; i < triangles.Count; i++)
                {
                    if (!triangles[i].HasSegment(current))
                    {
                        continue;
                    }
                    if (triangles[i].isinCircumscribed(point) && !triangles[i].isPointOnEdge(point)) // TO DO ne pas add les triangles créé avant la fin de la fonction
                    {
                        intriangle = true;
                        for (int j = 0; j < triangles[i].segments.Length; j++)
                        {
                            if (!triangles[i].segments[j].isEqual(current))
                            {
                                edges.Add(triangles[i].segments[j]);
                            }
                        }
                        triangles.RemoveAt(i);
                        i--;
                    }
                    else
                    {
                    }
                }

                if (!intriangle)
                {
                    triangles.Add(new Triangle(current.a, current.b, point));
                }

                if (safelock++ > 100)
                {
                    Debug.LogError("infinite loop");
                    break;
                }

                //if (wait)
                //{
                //    Debug.Log("number of edges in the list = " + edges.Count);
                //    PointsManager.get().createMeshes();
                //    while (!Input.GetMouseButtonUp(0)) yield return null;
                //    yield return null;
                //
                //}
                recalculateHull();
            }
        }//addPoint