add two methods to memorize the result of calculate the pos and coord.
add method to memorize the withinGrid function return result.