/// <summary> /// Joins vertex to the cheapest neighbour. /// </summary> /// <param name="vertex">The vertex to join.</param> /// <param name="type">The type of position join method.</param> /// <returns></returns> public bool JoinToNearestByCost(Vertex vertex, JoinPositionType type = JoinPositionType.Middle) { Debug.Assert(vertex != null); Vertex nearest = vertex.Neighbors.Min(); if (nearest != null) { Vector3 position; switch (type) { case JoinPositionType.Source: { position = vertex.Position; break; } case JoinPositionType.Target: { position = nearest.Position; break; } default: case JoinPositionType.Middle: { position = Vector3Extension.Mean(vertex.Position, nearest.Position); break; } } return(JoinVertices(vertex, nearest, position)); } return(false); }
/// <summary> /// Joins vertex to the closest neighbour. /// </summary> /// <param name="vertex">The vertex to join.</param> /// /// <param name="type">The type of position join method.</param> /// <returns>true when successful, false otherwise.</returns> public bool JoinToNearestByDistance(Vertex vertex, JoinPositionType type = JoinPositionType.Middle) { Debug.Assert(vertex != null); Vertex nearest = null; float minDistance = float.MaxValue; var neighbors = vertex.Neighbors.ToList(); foreach (var neighbor in neighbors) { float distance = Vector3.Distance(vertex.Position, neighbor.Position); if (distance < minDistance) { minDistance = distance; nearest = neighbor; } } if (nearest != null) { Vector3 position; switch (type) { case JoinPositionType.Source: { position = vertex.Position; break; } case JoinPositionType.Target: { position = nearest.Position; break; } default: case JoinPositionType.Middle: { position = Vector3Extension.Mean(vertex.Position, nearest.Position); break; } } return(JoinVertices(vertex, nearest, position)); } return(false); }
/// <summary> /// Joins vertex to the closest neighbour. /// </summary> /// <param name="vertex">The vertex to join.</param> /// /// <param name="type">The type of position join method.</param> /// <returns>true when successful, false otherwise.</returns> public bool JoinToNearestByDistance(Vertex vertex, JoinPositionType type = JoinPositionType.Middle) { Debug.Assert(vertex != null); Vertex nearest = null; float minDistance = float.MaxValue; var neighbors = vertex.Neighbors.ToList(); foreach (var neighbor in neighbors) { float distance = Vector3.Distance(vertex.Position, neighbor.Position); if (distance < minDistance) { minDistance = distance; nearest = neighbor; } } if (nearest != null) { Vector3 position; switch (type) { case JoinPositionType.Source: { position = vertex.Position; break; } case JoinPositionType.Target: { position = nearest.Position; break; } default: case JoinPositionType.Middle: { position = Vector3Extension.Mean(vertex.Position, nearest.Position); break; } } return JoinVertices(vertex, nearest, position); } return false; }
/// <summary> /// Joins vertex to the cheapest neighbour. /// </summary> /// <param name="vertex">The vertex to join.</param> /// <param name="type">The type of position join method.</param> /// <returns></returns> public bool JoinToNearestByCost(Vertex vertex, JoinPositionType type = JoinPositionType.Middle) { Debug.Assert(vertex != null); Vertex nearest = vertex.Neighbors.Min(); if (nearest != null) { Vector3 position; switch (type) { case JoinPositionType.Source: { position = vertex.Position; break; } case JoinPositionType.Target: { position = nearest.Position; break; } default: case JoinPositionType.Middle: { position = Vector3Extension.Mean(vertex.Position, nearest.Position); break; } } return JoinVertices(vertex, nearest, position); } return false; }