// sc2k/structure/transform.hpp — view rotation for terrain-independent support presentation. #pragma once #include "sc2k/structure/model.hpp" #include #include namespace sc2k::structure { inline std::uint8_t rotate_presentation_clockwise(std::uint8_t presentation) { const std::uint8_t base = xter::base_shape(presentation); if (base == xter::kFlat || base == xter::kCube || base > xter::kSlopeLast) return presentation; const terrain::Shape rotated = terrain::rotate_shape_clockwise(static_cast(base), 1); return static_cast((presentation & 0xF0) | static_cast(rotated)); } inline std::optional rotate_clockwise(const Model& structures, unsigned quarter_turns) { quarter_turns &= 3; terrain::Extent source_extent = structures.extent(); std::vector source(structures.supports().begin(), structures.supports().end()); for (unsigned turn = 0; turn < quarter_turns; ++turn) { const terrain::Extent target_extent{source_extent.height, source_extent.width}; std::vector target(source.size()); for (int row = 0; row < source_extent.height; ++row) { for (int column = 0; column < source_extent.width; ++column) { Support support = source[static_cast(row) * source_extent.width + column]; if (support) support.legacy_presentation = rotate_presentation_clockwise(support.legacy_presentation); const int target_row = source_extent.width - 1 - column; const int target_column = row; target[static_cast(target_row) * target_extent.width + target_column] = support; } } source_extent = target_extent; source = std::move(target); } return Model::create(source_extent, std::move(source)); } } // namespace sc2k::structure