1 struct Vec { float x, y; }
2
3 // 5x3 map, rows from 0 to 4, cols from 0 to 2
4 auto tiles = [
5 [ 00, 01, 02, 03, 04, ],
6 [ 10, 11, 12, 13, 14, ],
7 [ 20, 21, 22, 23, 24, ],
8 ];
9 auto map = OrthoMap!int(tiles, 32, 32);
10
11 assert(map.coordAtPoint(Vec(0 , 0 )) == RowCol(0 , 0 ));
12 assert(map.coordAtPoint(Vec(16 , 16 )) == RowCol(0 , 0 ));
13 assert(map.coordAtPoint(Vec(32 , 0 )) == RowCol(0 , 1 ));
14 assert(map.coordAtPoint(Vec(0 , 45 )) == RowCol(1 , 0 ));
15 assert(map.coordAtPoint(Vec(105 , 170)) == RowCol(5 , 3 ));
16 assert(map.coordAtPoint(Vec(-10 , 0 )) == RowCol(0 , -1));
17 assert(map.coordAtPoint(Vec(-32 , -33)) == RowCol(-2 , -1));
Get the grid location corresponding to a given pixel coordinate.
If the point is out of map bounds, the returned coord will also be out of bounds. Use the containsPoint method to check if a point is in bounds.