/// <summary>
        /// Does the ship's heading put it on course to enter Duluth Canal?
        /// Ships report numerous false destinations. Therefore, we use this method
        /// to check a ship's actual heading against the bearing to the two nearest ports
        /// and make a determination whether or not the ship will actually use Duluth Canal
        /// </summary>
        /// <param name="shipTest">shipTest object</param>
        /// <returns>true or false</returns>
        public static bool IsHeadingTowardDuluth(this ShipTest shipTest)
        {
            var twoNearestPortsAndBearing = Ports.All.Select(p => {
                var bearing    = GeoHelper.GetBearing(shipTest.Position, p);
                var adjustment = Math.Abs(bearing - shipTest.Heading);
                if (adjustment > 180)
                {
                    adjustment = 360 - adjustment;
                }
                return(new {
                    Position = p,
                    Bearing = bearing,
                    Adjustment = adjustment
                });
            }).OrderBy(
                p => p.Adjustment
                ).Take(2).ToArray();

            var firstPort  = twoNearestPortsAndBearing[0];
            var secondPort = twoNearestPortsAndBearing[1];

            var portBearingDiff = Math.Abs(firstPort.Bearing - secondPort.Bearing);

            var weight = 1 / 2D;

            if (shipTest.Destination == firstPort.Position)
            {
                weight = 2 / 3D;
            }
            else if (shipTest.Destination == secondPort.Position)
            {
                weight = 1 / 3D;
            }

            var threshold = weight * portBearingDiff;

            Position nearestPort = null;

            if (firstPort.Adjustment <= threshold)
            {
                nearestPort = firstPort.Position;
            }
            else if (secondPort.Adjustment <= threshold)
            {
                nearestPort = secondPort.Position;
            }
            else if (shipTest.IsMovingToward(firstPort.Position))
            {
                nearestPort = firstPort.Position;
            }

            return(nearestPort == Ports.Duluth);
        }
 /// <summary>
 /// If the a ship's bearing to a given position is less than 90 degrees away from exact heading needed to get to the port,
 /// Then we says that a ship is moving toward that port
 /// </summary>
 /// <param name="shipTest">shipTest object</param>
 /// <returns>true or false</returns>
 public static bool IsMovingTowardDuluth(this ShipTest shipTest)
 {
     return(shipTest.IsMovingToward(Ports.Duluth));
 }