示例#1
0
 public static WallCoord GetNearestPortalableEdge(IList<IWall> walls, Vector2 point, float maxRadius, float portalSize)
 {
     WallCoord wallCoord = null;
     double distanceMin = -1;
     for (int i = 0; i < walls.Count; i++)
     {
         IList<Vector2> vertices = walls[i].GetWorldVertices();
         for (int edgeIndex = 0; edgeIndex < walls[i].Vertices.Count; edgeIndex++)
         {
             int edgeIndexNext = (edgeIndex + 1) % vertices.Count;
             LineF edge = new LineF(vertices[edgeIndex], vertices[edgeIndexNext]);
             if (!EdgeValidLength(edge.Length, portalSize))
             {
                 continue;
             }
             Vector2 nearPos = edge.Nearest(point, true);
             float portalT = edge.NearestT(point, true);
             portalT = GetValidT(portalT, edge, portalSize);
             Vector2 portalPos = edge.Lerp(portalT);
             double distance = (portalPos - point).Length;
             if (maxRadius < (nearPos - point).Length)
             {
                 continue;
             }
             if (distanceMin == -1 || distance < distanceMin)
             {
                 wallCoord = new WallCoord(walls[i], edgeIndex, portalT);
                 distanceMin = distance;
             }
         }
     }
     return wallCoord;
 }
示例#2
0
 public void NearestTTest2()
 {
     LineF line = new LineF(new Vector2(3.3f,-4.9f), new Vector2(-5.3f, -6.1f));
     Assert.IsTrue(line.NearestT(new Vector2(-4, 2), false) == 0.722811639f);
 }
示例#3
0
 public void NearestTTest1()
 {
     LineF line = new LineF(new Vector2(), new Vector2(0, 1));
     Assert.IsTrue(line.NearestT(new Vector2(-4, 2), false) == 2);
 }
示例#4
0
 public void NearestTTest0()
 {
     LineF line = new LineF(new Vector2(), new Vector2(1, 0));
     Assert.IsTrue(line.NearestT(new Vector2(1, 5), false) == 1);
 }