Beispiel #1
0
        /// <summary>
        /// Computes a convex hull using the Gift Wrap method.
        /// </summary>
        /// <param name="points"></param>
        /// <param name="allocator"></param>
        /// <returns></returns>
        public static void Giftwrap(NativeArray <Vector2> points, Allocator allocator, ref NativeArray <Vector2> convexHullOut)
        {
            if (!points.IsCreated)
            {
                throw new ArgumentException("Array has been disposed.", nameof(points));
            }

            // pointOnHull is initialized to the leftmost point
            // which is guaranteed to be part of the convex hull
            int pointOnHull = 0;

            for (int i = 1; i < points.Length; ++i)
            {
                if (points[i].x < points[pointOnHull].x)
                {
                    pointOnHull = i;
                }
            }

            using (var hullIndices = new NativeFixedList <int>(points.Length, Allocator.Temp))
            {
                int endpoint = 0;
                do
                {
                    hullIndices.Add(pointOnHull);
                    endpoint = 0;      // initial endpoint for a candidate edge on the hull
                    for (int j = 1; j < points.Length; ++j)
                    {
                        endpoint = (endpoint == pointOnHull || IsPointLeftOfLine(points[j], points[pointOnHull], points[endpoint])) ? j : endpoint;
                    }
                    pointOnHull = endpoint;
                } while (endpoint != hullIndices[0]);      // wrapped around to first hull point

                CreateOrResizeNativeArrayIfNecessary <Vector2>(hullIndices.Length, allocator, ref convexHullOut);
                for (int i = 0; i < hullIndices.Length; ++i)
                {
                    convexHullOut[i] = points[hullIndices[i]];
                }
            }
        }
Beispiel #2
0
 internal Enumerator(NativeFixedList <T> list)
 {
     m_Index           = -1;
     m_NativeFixedList = list;
 }
Beispiel #3
0
 public bool Equals(NativeFixedList <T> other)
 {
     return
         (m_NativeArray.Equals(other.m_NativeArray) &&
          (Length == other.Length));
 }