/// Convenience method to get a list of all segments of the contours of a graph.
/// Returns: A list of segments. Every 2 elements form a line segment. The first segment is (result[0], result[1]), the second one is (result[2], result[3]) etc.
/// The line segments are oriented so that the navmesh is on the right side of the segments when seen from above.
///
/// This method works for navmesh, recast, grid graphs and layered grid graphs. For other graph types it will return an empty list.
///
/// If you need more information about how the contours are connected you can take a look at the other variants of this method.
///
/// <code>
/// // Get the first graph
/// var navmesh = AstarPath.active.graphs[0];
///
/// // Get all contours of the graph (works for grid, navmesh and recast graphs)
/// var segments = GraphUtilities.GetContours(navmesh);
///
/// // Every 2 elements form a line segment. The first segment is (segments[0], segments[1]), the second one is (segments[2], segments[3]) etc.
/// // The line segments are oriented so that the navmesh is on the right side of the segments when seen from above.
/// This image is just used to illustrate the difference between chains and cycles. That it shows a grid graph is not relevant.
/// [Open online documentation to see images]
///
/// See: <see cref="GetContours(NavGraph)"/>
/// </summary>
/// <param name="navmesh">The navmesh-like object to trace. This can be a recast or navmesh graph or it could be a single tile in one such graph.</param>
/// <param name="results">Will be called once for each contour with the contour as a parameter as well as a boolean indicating if the contour is a cycle or a chain (see second image).</param>
/// In the image below you can see the contour of a graph.
/// [Open online documentation to see images]
///
/// In the image below you can see the contour of just a part of a grid graph (when the nodes parameter is supplied)
/// [Open online documentation to see images]
///
/// Contour of a hexagon graph
/// [Open online documentation to see images]
///
/// See: <see cref="GetContours(NavGraph)"/>
/// </summary>
/// <param name="grid">The grid to find the contours of</param>
/// <param name="callback">The callback will be called once for every contour that is found with the vertices of the contour. The contour always forms a cycle.</param>
/// <param name="yMergeThreshold">Contours will be simplified if the y coordinates for adjacent vertices differ by no more than this value.</param>
/// <param name="nodes">Only these nodes will be searched. If this parameter is null then all nodes in the grid graph will be searched.</param>
/// <param name="connectionFilter">Allows you to disable connections between nodes. If null, no additional filtering will be done. The filter must be symmetric, so that f(A,B) == f(B,A). A contour edge will be generated between two adjacent nodes if this function returns false for the pair.</param>
// The third check is a fast check for if the node has connections in all grid directions, if it has then we can skip processing it (unless the nodes parameter was used in which case we have to handle the edge cases)
// Replace the previous point if it is colinear with the point just before it and just after it (the current point), because that point wouldn't add much information, but it would add CPU overhead
thrownewSystem.InvalidOperationException("Cannot calculate contour. The graph contains one-way connections. A contour is not well defined if one-way connections exist.");
// Simplify the contour a bit around the start point.
// Otherwise we might return a cycle which was not as simplified as possible and the number of vertices
// would depend on where in the cycle the algorithm started to traverse the contour.
if(trace.Count>=3){
varv0=trace[trace.Count-2];
varv1=trace[trace.Count-1];
varv1d=v1-v0;
varv2d=trace[0]-v0;
// Replace the previous point if it is colinear with the point just before it and just after it (the current point), because that point wouldn't add much information, but it would add CPU overhead
// Replace the previous point if it is colinear with the point just before it and just after it (the current point), because that point wouldn't add much information, but it would add CPU overhead