From 78b984937977f583eda446957426099badce91d5 Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Sun, 10 Nov 2024 11:28:34 +0800 Subject: [PATCH] feat: toward check of group construction --- src/core/group/internal/group.inl | 40 +++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/src/core/group/internal/group.inl b/src/core/group/internal/group.inl index e091ebb..8fe869a 100644 --- a/src/core/group/internal/group.inl +++ b/src/core/group/internal/group.inl @@ -80,8 +80,44 @@ constexpr std::optional Group::create(const uint_fast8_t type_id, const u if (pattern_id >= GroupUnion::unsafe_create(type_id).pattern_num()) { return std::nullopt; } - // TODO: toward check - return unsafe_create(type_id, pattern_id, toward); + + if (toward == Toward::A) { + return unsafe_create(type_id, pattern_id, toward); + } + + auto mirror_type = PATTERN_DATA[PATTERN_OFFSET[type_id] + pattern_id] & 0b111; + + if (toward == Toward::B) { + switch ((MirrorType)mirror_type) { + case MirrorType::Full: return std::nullopt; + case MirrorType::Horizontal: return std::nullopt; + case MirrorType::Centro: return unsafe_create(type_id, pattern_id, toward); + case MirrorType::Vertical: return unsafe_create(type_id, pattern_id, toward); + case MirrorType::Ordinary: return unsafe_create(type_id, pattern_id, toward); + } + } + + if (toward == Toward::C) { + switch ((MirrorType)mirror_type) { + case MirrorType::Full: return std::nullopt; + case MirrorType::Horizontal: return unsafe_create(type_id, pattern_id, toward); + case MirrorType::Centro: return std::nullopt; + case MirrorType::Vertical: return std::nullopt; + case MirrorType::Ordinary: return unsafe_create(type_id, pattern_id, toward); + } + } + + if (toward == Toward::D) { + switch ((MirrorType)mirror_type) { + case MirrorType::Full: return std::nullopt; + case MirrorType::Horizontal: return std::nullopt; + case MirrorType::Centro: return std::nullopt; + case MirrorType::Vertical: return std::nullopt; + case MirrorType::Ordinary: return unsafe_create(type_id, pattern_id, toward); + } + } + + return std::nullopt; // TODO: never reach } constexpr uint32_t Group::flat_id() const {