Example #1
0
 /// <summary>
 /// Contract the polygon toward a specified point.
 /// locks controlls which edges are not able to move to complete the operation
 /// </summary>
 /// <param name="poly"></param>
 /// <param name="center"></param>
 /// <param name="tValue"></param>
 /// <param name="lockList"></param>
 /// <returns></returns>
 public static IPoly Contract(this IPoly poly, Vector3 center, float tValue, bool[] locks)
 {
     if (locks == null)
     {
         return(Contract(poly, center, tValue));
     }
     else
     {
         Vector3[] output = new Vector3[poly.Resolution];
         for (int i = 0; i < poly.Resolution; i++)
         {
             Vector3 point      = poly.GetPoint(i);
             bool    rightLock  = locks[i];
             int     minusIndex = (i + poly.Resolution - 1) % poly.Resolution;
             bool    leftLock   = locks[minusIndex];
             if (!rightLock && !leftLock)
             {
                 output[i] = Vector3.Lerp(point, center, tValue);
             }
             else if (leftLock && rightLock)
             {
                 output[i] = point;
             }
             else if (leftLock && !rightLock)
             {
                 output[i] = Vector3.Lerp(point, poly.GetEdge(minusIndex).Center(), tValue);
             }
             else if (!leftLock && rightLock)
             {
                 output[i] = Vector3.Lerp(point, poly.GetEdge(i).Center(), tValue);
             }
         }
         return(poly.Clone(output));
     }
 }
Example #2
0
 public static IEnumerable <IEdge> Edges(this IPoly poly)
 {
     for (int i = 0; i < poly.Resolution; i++)
     {
         yield return(poly.GetEdge(i));
     }
 }
 public static bool HasIntersection(IPoly a, IPoly b)
 {
     //This logic is just wrong
     //Needs to be recoded
     throw new NotImplementedException();
     for (int i = 0; i < a.Resolution; i++)
     {
         IEdge ea = a.GetEdge(i);
         for (int j = 0; j < b.Resolution; j++)
         {
             IEdge eb = b.GetEdge(j);
             if (ea.CompareLine(eb) && Vector3.Dot(ea.Direction(), eb.Direction()) < 0)
             {
                 return(ea.GetIntersecting(eb) != null);
             }
         }
     }
     return(false);
 }