diff -r 852021f38b66 -r 216f02b50b0a src/polygoncache.cpp --- a/src/polygoncache.cpp Sun Jul 03 12:20:26 2022 +0300 +++ b/src/polygoncache.cpp Sun Jul 03 13:21:49 2022 +0300 @@ -29,6 +29,45 @@ } } +constexpr bool n_xor(bool a) +{ + return a; +} + +template +constexpr bool n_xor(bool a, Args&&... rest) +{ + return a xor n_xor(rest...); +} + +template +static void inlineSubfileReference( + const PolygonCache::vector_type& polygons, + const Colored& ref, + Fn&& add, + Fn2&& reserve) +{ + const bool needInverting = 0 + ^ (glm::determinant(ref.transformation) < 0) + ^ (ref.inverted); + reserve(polygons.size()); + for (const PolygonElement& cacheElement : polygons) { + PolygonElement polygon = transformed(cacheElement, ref.transformation); + if (needInverting) { + gl::invert(polygon); + } + if (polygon.color == MAIN_COLOR) { + polygon.color = ref.color; + } + add(polygon); + } +} + +Model* findDependency(const SubfileReference& ref, GetPolygonsContext* context) +{ + return context->documents->findDependencyByName(context->modelId, ref.name); +} + template static void collectPolygons( const ModelElement& element, @@ -51,25 +90,13 @@ add({cedge, cedge.color}); }, [&add, context, &reserve](const Colored& ref) { - Model* dependency = context->documents->findDependencyByName(context->modelId, ref.name); - PolygonCache* cache = nullptr; - if (dependency != nullptr) { - cache = findPolygonCacheForModel(dependency, context->documents); - } - if (cache != nullptr) { - const bool needInverting = glm::determinant(ref.transformation) < 0; + Model* const dependency = findDependency(ref, context); + if (PolygonCache* cache = (dependency != nullptr) + ? findPolygonCacheForModel(dependency, context->documents) + : nullptr + ) { recacheIfNeeded(cache, dependency, context->documents); - reserve(cache->polygons.size()); - for (const PolygonElement& cacheElement : cache->polygons) { - PolygonElement polygon = transformed(cacheElement, ref.transformation); - if (needInverting != ref.inverted) { - gl::invert(polygon); - } - if (polygon.color == MAIN_COLOR) { - polygon.color = ref.color; - } - add(polygon); - } + inlineSubfileReference(cache->polygons, ref, add, reserve); } }, [&add](const Colored& circ) {