Example #1
0
        /// <summary>
        /// Determines if a move is within a bounding box.
        /// </summary>
        /// <param name="move">Target move</param>
        /// <param name="nodes">Enumerable of all nodes in the roadmap</param>
        /// <param name="boundingBox">Bounding box.</param>
        /// <returns>True if the move is within the bounding box.</returns>
        public static bool IsWithin(this MoveDto move, IEnumerable <NodeDto> nodes, Rect boundingBox)
        {
            if (move == null)
            {
                throw new ArgumentNullException("move");
            }

            if (nodes == null)
            {
                throw new ArgumentNullException("nodes");
            }

            NodeDto source = nodes.FirstOrDefault(e => e.Id == move.SourceId);

            if (source == null)
            {
                throw new ArgumentOutOfRangeException("Nodes does not contain source node for move");
            }

            NodeDto dest = nodes.FirstOrDefault(e => e.Id == move.DestinationId);

            if (dest == null)
            {
                throw new ArgumentOutOfRangeException("Nodes does not contain destination node for move");
            }

            if (boundingBox.Contains(source.ToPoint()))
            {
                return(true);
            }

            if (boundingBox.Contains(dest.ToPoint()))
            {
                return(true);
            }

            return(false);
        }