/// <summary> /// Finds the distance between a point and the nearest edge of a polygon. /// </summary> /// <param name="pt">A point.</param> /// <param name="verts">A set of vertices that define a polygon.</param> /// <param name="nverts">The number of vertices to use from <c>verts</c>.</param> /// <param name="edgeDist">A buffer for edge distances to be stored in.</param> /// <param name="edgeT">A buffer for parametrization ratios to be stored in.</param> /// <returns>A value indicating whether the point is contained in the polygon.</returns> internal static bool PointToPolygonEdgeSquared(Vector3 pt, Vector3[] verts, int nverts, float[] edgeDist, float[] edgeT) { for (int i = 0, j = nverts - 1; i < nverts; j = i++) { edgeDist[j] = PointToSegment2DSquared(ref pt, ref verts[j], ref verts[i], out edgeT[j]); } return(Containment.PointInPoly(pt, verts, nverts)); }
//TOOD where did these come from? /// <summary> /// Finds the squared distance between a point and the nearest edge of a polygon. /// </summary> /// <param name="pt">A point.</param> /// <param name="verts">A set of vertices that define a polygon.</param> /// <param name="nverts">The number of vertices to use from <c>verts</c>.</param> /// <returns>The squared distance between a point and the nearest edge of a polygon.</returns> internal static float PointToPolygonEdgeSquared(Vector3 pt, Vector3[] verts, int nverts) { float dmin = float.MaxValue; for (int i = 0, j = nverts - 1; i < nverts; j = i++) { dmin = Math.Min(dmin, Distance.PointToSegment2DSquared(ref pt, ref verts[j], ref verts[i])); } return(Containment.PointInPoly(pt, verts, nverts) ? -dmin : dmin); }