示例#1
0
 /// <summary>
 /// Measures the distance of two point with a given metric.
 /// Default is manhatten metric
 /// </summary>
 /// <param name="otherPoint"></param>
 /// <param name="metric"></param>
 /// <returns></returns>
 public int MeasureDistance(CoordinatePoint otherPoint, Metric metric = Metric.Manhatten)
 {
     return(metric switch
     {
         Metric.Manhatten => Math.Abs(X - otherPoint.X) + Math.Abs(Y - otherPoint.Y),
         _ => throw new ArgumentException("Metric is not defined"),
     });
示例#2
0
 /// <summary>
 /// Creates a new instance of a wire
 /// </summary>
 /// <param name="startingPoint"></param>
 /// <param name="path"></param>
 public Wire(CoordinatePoint startingPoint, IEnumerable <string> path)
 {
     StartingPoint = startingPoint;
     Path          = path;
 }
示例#3
0
        /// <summary>
        /// Returns the closest point from a list of candidates to a given reference Point on the grid
        /// </summary>
        /// <param name="candidates"></param>
        /// <param name="referencePoint"></param>
        /// <param name="metric">The default metric is Manhatten</param>
        /// <returns></returns>
        public (CoordinatePoint point, int distance) GetClosestPointTo(List <CoordinatePoint> candidates, CoordinatePoint referencePoint, Metric metric = Metric.Manhatten)
        {
            var distances               = candidates.Select(c => c.MeasureDistance(referencePoint, metric));
            var shortestDistance        = distances.Min();
            var indexOfShortestDistance = distances.ToList().IndexOf(shortestDistance);

            return(candidates[indexOfShortestDistance], shortestDistance);
        }