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; }
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); }
public void NearestTTest1() { LineF line = new LineF(new Vector2(), new Vector2(0, 1)); Assert.IsTrue(line.NearestT(new Vector2(-4, 2), false) == 2); }
public void NearestTTest0() { LineF line = new LineF(new Vector2(), new Vector2(1, 0)); Assert.IsTrue(line.NearestT(new Vector2(1, 5), false) == 1); }