summary refs log tree commit diff
path: root/src/Math/Grid.cpp
blob: de5fa695accf4102626f9085a54844bf93c97621 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include "Grid.hpp"

#include "../Common/Lambda.hpp"

namespace Math {

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};
}

Vector<2> GridCellBoundaries::top_left() const {
    return {x1, y1};
}

Vector<2> GridCellBoundaries::top_right() const {
    return {x2, y1};
}

Vector<2> GridCellBoundaries::bottom_left() const {
    return {x1, y2};
}

Vector<2> GridCellBoundaries::bottom_right() const {
    return {x2, y2};
}

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};
}

Vector<3> CubeCellBoundaries::front_top_left() const {
    return {x1, y1, z1};
}

Vector<3> CubeCellBoundaries::front_top_right() const {
    return {x2, y1, z1};
}

Vector<3> CubeCellBoundaries::front_bottom_left() const {
    return {x1, y2, z1};
}

Vector<3> CubeCellBoundaries::front_bottom_right() const {
    return {x2, y2, z1};
}

Vector<3> CubeCellBoundaries::back_top_left() const {
    return {x1, y1, z2};
}

Vector<3> CubeCellBoundaries::back_top_right() const {
    return {x2, y1, z2};
}

Vector<3> CubeCellBoundaries::back_bottom_left() const {
    return {x1, y2, z2};
}

Vector<3> CubeCellBoundaries::back_bottom_right() const {
    return {x2, y2, z2};
}

GridCellBoundaries CubeCellBoundaries::grid_cell() const {
    return {x1, x2, y1, y2};
}

}