diff options
Diffstat (limited to 'src/Math/Grid.cpp')
| -rw-r--r-- | src/Math/Grid.cpp | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/src/Math/Grid.cpp b/src/Math/Grid.cpp index 422cf87..de5fa69 100644 --- a/src/Math/Grid.cpp +++ b/src/Math/Grid.cpp @@ -1,12 +1,18 @@ #include "Grid.hpp" +#include "../Common/Lambda.hpp" + namespace Math { -GridCellBoundaries grid_cell_for_point(Vector<2> point) { - auto x1 = std::trunc(point.x()); - auto y1 = std::trunc(point.y()); - auto x2 = x1 + 1.0f; - auto y2 = y1 + 1.0f; +GridCellBoundaries grid_cell_containing_point(Vec2 point, Vec2 cell_size) { + return grid_cell_from_point(point.map(LAMBDA(std::trunc, 1)), cell_size); +} + +GridCellBoundaries grid_cell_from_point(Vec2 point, Vec2 cell_size) { + auto x1 = point.x(); + auto y1 = point.y(); + auto x2 = x1 + cell_size.x(); + auto y2 = y1 + cell_size.y(); return GridCellBoundaries{x1, x2, y1, y2}; } @@ -27,13 +33,17 @@ Vector<2> GridCellBoundaries::bottom_right() const { return {x2, y2}; } -CubeCellBoundaries cube_cell_for_point(Vector<3> point) { - auto x1 = std::trunc(point.x()); - auto y1 = std::trunc(point.y()); - auto z1 = std::trunc(point.z()); - auto x2 = x1 + 1.0f; - auto y2 = y1 + 1.0f; - auto z2 = z1 + 1.0f; +CubeCellBoundaries cube_cell_containing_point(Vec3 point, Vec3 cell_size) { + return cube_cell_from_point(point.map(LAMBDA(std::trunc, 1)), cell_size); +} + +CubeCellBoundaries cube_cell_from_point(Vec3 point, Vec3 cell_size) { + auto x1 = point.x(); + auto y1 = point.y(); + auto z1 = point.z(); + auto x2 = x1 + cell_size.x(); + auto y2 = y1 + cell_size.y(); + auto z2 = z1 + cell_size.z(); return CubeCellBoundaries{x1, x2, y1, y2, z1, z2}; } @@ -74,4 +84,4 @@ GridCellBoundaries CubeCellBoundaries::grid_cell() const { return {x1, x2, y1, y2}; } -} \ No newline at end of file +} |
