Hands-on Rust: missing in_bounds implementation of the Algorithm2D trait (page 170)

Hello,

In the current version of the book, beta 3, Map struct is missing in_bounds implementation of the Algorithm2D trait. This leads to default implementation being used , which in turn leads to a subtle bug where tiles with coordinates (0, y) and (x, 0) are not visible.

I have “fixed” it by adding the following, but I am pretty new to Rust and there might be a better way?

impl Algorithm2D for Map {
    fn dimensions(&self) -> Point {
        Point::new(SCREEN_WIDTH, SCREEN_HEIGHT)
    }
   // use Map's in_bounds function that does not exclude 0 coordinates
    fn in_bounds(&self, point: Point) -> bool {
        self.in_bounds(point)
    }
}

P.S.: I’m enjoying the book immensely, thank you for writing it!

1 Like