| 104 | } |
| 105 | |
| 106 | rect<u16> bounds_pixels() const { |
| 107 | u16 min_x = 0; |
| 108 | bool min_x_set = false; |
| 109 | u16 min_y = 0; |
| 110 | bool min_y_set = false; |
| 111 | u16 max_x = 0; |
| 112 | bool max_x_set = false; |
| 113 | u16 max_y = 0; |
| 114 | bool max_y_set = false; |
| 115 | for (const auto &it : mSparseGrid) { |
| 116 | const vec2<u16> &pt = it.first; |
| 117 | if (!min_x_set || pt.x < min_x) { |
| 118 | min_x = pt.x; |
| 119 | min_x_set = true; |
| 120 | } |
| 121 | if (!min_y_set || pt.y < min_y) { |
| 122 | min_y = pt.y; |
| 123 | min_y_set = true; |
| 124 | } |
| 125 | if (!max_x_set || pt.x > max_x) { |
| 126 | max_x = pt.x; |
| 127 | max_x_set = true; |
| 128 | } |
| 129 | if (!max_y_set || pt.y > max_y) { |
| 130 | max_y = pt.y; |
| 131 | max_y_set = true; |
| 132 | } |
| 133 | } |
| 134 | return rect<u16>(min_x, min_y, max_x + 1, max_y + 1); |
| 135 | } |
| 136 | |
| 137 | // Warning! - SLOW. |
| 138 | u16 width() const { return bounds().width(); } |