Traverse a grid segment using floating point arithmetic.
Traverse a grid segment using fixed-point 8.8 arithmetic.
Useful for testing.
- Template Parameters
-
- Parameters
-
| start | start point |
| end | end point |
| visitor | called for each cell visited. |
Fully tested.
- Template Parameters
-
- Parameters
-
| start | start point |
| end | end point |
| visitor | called for each cell visited. |
Fully tested.
Definition at line 70 of file traverse_grid.h.
71 {
76
77 int stepX = (x1 > x0) ? 1 : (x1 < x0) ? -1 : 0;
78 int stepY = (y1 > y0) ? 1 : (y1 < y0) ? -1 : 0;
79
80 float dx =
end.x - start.
x;
81 float dy =
end.y - start.
y;
82
85
88
91
92 float maxT = 1.0f;
93
94 int currentX = x0;
95 int currentY = y0;
96
97 while (true) {
98 visitor.visit(currentX, currentY);
101 break;
102
103 if (tMaxX < tMaxY) {
104 tMaxX += tDeltaX;
105 currentX += stepX;
106 } else {
107 tMaxY += tDeltaY;
108 currentY += stepY;
109 }
110 }
111
112
113 if (currentX != x1 || currentY != y1) {
114 visitor.visit(x1, y1);
115 }
116}
FL_DISABLE_WARNING_PUSH U constexpr common_type_t< T, U > min(T a, U b) FL_NOEXCEPT
constexpr T * end(T(&array)[N]) FL_NOEXCEPT
constexpr enable_if< is_fixed_point< T >::value, T >::type floor(T x) FL_NOEXCEPT
constexpr enable_if< is_fixed_point< T >::value, T >::type abs(T x) FL_NOEXCEPT
References abs(), end(), FL_FLT_MAX, floor(), min(), t, fl::vec2< T >::x, and fl::vec2< T >::y.