* Utility class representing a cuboid of df::coord. * \ingroup grp_maps */
| 180 | * \ingroup grp_maps |
| 181 | */ |
| 182 | class cuboid { |
| 183 | public: |
| 184 | // Bounds |
| 185 | int16_t x_min = -1; |
| 186 | int16_t x_max = -1; |
| 187 | int16_t y_min = -1; |
| 188 | int16_t y_max = -1; |
| 189 | int16_t z_min = -1; |
| 190 | int16_t z_max = -1; |
| 191 | |
| 192 | // Default constructor. |
| 193 | DFHACK_EXPORT cuboid() {} |
| 194 | |
| 195 | // Construct from two corners. |
| 196 | DFHACK_EXPORT cuboid(int16_t x1, int16_t y1, int16_t z1, int16_t x2, int16_t y2, int16_t z2); |
| 197 | DFHACK_EXPORT cuboid(const df::coord &p1, const df::coord &p2) : cuboid(p1.x, p1.y, p1.z, p2.x, p2.y, p2.z) {} |
| 198 | |
| 199 | // Construct as single tile. |
| 200 | DFHACK_EXPORT cuboid(int16_t x, int16_t y, int16_t z); |
| 201 | DFHACK_EXPORT cuboid(const df::coord &p) : cuboid(p.x, p.y, p.z) {} |
| 202 | |
| 203 | // Construct from map block. |
| 204 | DFHACK_EXPORT cuboid(const df::map_block *block); |
| 205 | |
| 206 | // Valid cuboid? True if all max >= min >= 0. |
| 207 | DFHACK_EXPORT bool isValid() const; |
| 208 | |
| 209 | // Clear cuboid dimensions, making it invalid. |
| 210 | DFHACK_EXPORT void clear() { x_min = x_max = y_min = y_max = z_min = z_max = -1; } |
| 211 | |
| 212 | // Clamp this cuboid within another cuboid. Invalid result implies no intersection or invalid input. |
| 213 | DFHACK_EXPORT cuboid clamp(const cuboid &other); |
| 214 | |
| 215 | // Return a new cuboid representing overlapping volume. Invalid result implies no intersection or invalid input. |
| 216 | DFHACK_EXPORT cuboid clampNew(const cuboid &other) const { return cuboid(*this).clamp(other); } |
| 217 | |
| 218 | /// Clamp this cuboid within map area. Invalid result implies no intersection or invalid input (e.g., no map). |
| 219 | /// Can optionally treat cuboid as map blocks instead of tiles. |
| 220 | /// Note: A point being in map area isn't sufficient to know that a tile block is allocated there! |
| 221 | DFHACK_EXPORT cuboid clampMap(bool block = false); |
| 222 | |
| 223 | // Expand cuboid to include point. Returns true if bounds changed. Fails if x/y/z < 0. |
| 224 | DFHACK_EXPORT bool addPos(int16_t x, int16_t y, int16_t z); |
| 225 | DFHACK_EXPORT bool addPos(const df::coord &pos) { return addPos(pos.x, pos.y, pos.z); } |
| 226 | |
| 227 | // Return true if point inside cuboid. Make sure cuboid is valid first! |
| 228 | DFHACK_EXPORT bool containsPos(int16_t x, int16_t y, int16_t z) const; |
| 229 | DFHACK_EXPORT bool containsPos(const df::coord &pos) const { return containsPos(pos.x, pos.y, pos.z); } |
| 230 | |
| 231 | /// Iterate over every point in the cuboid. Doesn't guarantee valid map tile! |
| 232 | /// "fn" should return true to keep iterating. Won't iterate if cuboid invalid. |
| 233 | /// If row_major is false, iterates from top-down (z), N-S (y), then W-E (x). |
| 234 | /// If row_major is true, iterates from top-down (z), W-E (x), then N-S (y). |
| 235 | DFHACK_EXPORT void forCoord(std::function<bool(df::coord)> fn, bool row_major = false) const; |
| 236 | |
| 237 | /// Iterate over every non-NULL map block intersecting the tile cuboid from top-down, N-S, then W-E. |
| 238 | /// Will also supply the intersection of this cuboid and block to your "fn" for use with cuboid::forCoord. |
| 239 | /// Can optionally attempt to create map blocks if they aren't allocated. |
no outgoing calls
no test coverage detected