@@ -9190,8 +9190,7 @@ TEST_CASE("Test_Additiona_Turns_Bug", "[constructive-model][coil][round-winding-
91909190 auto turns = coil.get_turns_description().value();
91919191 auto layers = coil.get_layers_description().value();
91929192
9193- std::cout << "Number of layers: " << layers.size() << std::endl;
9194-
9193+
91959194 // Check that all turns have additional coordinates
91969195 for (auto& turn : turns) {
91979196 REQUIRE(turn.get_additional_coordinates());
@@ -9203,11 +9202,6 @@ TEST_CASE("Test_Additiona_Turns_Bug", "[constructive-model][coil][round-winding-
92039202 turnsByLayer[turns[i].get_layer().value()].push_back(i);
92049203 }
92059204
9206- std::cout << "Turns per layer:" << std::endl;
9207- for (auto& [layerName, indices] : turnsByLayer) {
9208- std::cout << " " << layerName << ": " << indices.size() << " turns" << std::endl;
9209- }
9210-
92119205 // Collect all additional radii
92129206 std::vector<double> additionalRadii;
92139207 for (size_t i = 0; i < turns.size(); ++i) {
@@ -9222,13 +9216,7 @@ TEST_CASE("Test_Additiona_Turns_Bug", "[constructive-model][coil][round-winding-
92229216 // Round to 0.1mm precision
92239217 uniqueRadii.insert(round(r * 10000) / 10000);
92249218 }
9225-
9226- std::cout << "Unique additional radii: ";
9227- for (auto r : uniqueRadii) {
9228- std::cout << r * 1000 << "mm ";
9229- }
9230- std::cout << std::endl;
9231-
9219+
92329220 // The bug was that additional turns from layer 1 were placed at a different radius
92339221 // than turns from layer 0, even though there was space in the first additional layer.
92349222 // After the fix, all additional turns should be at the same radius (compacted).
@@ -10477,4 +10465,75 @@ TEST_CASE("Test_Toroidal_Delimit_And_Compact_Multilayer", "[toroidal][coil][comp
1047710465 settings.reset();
1047810466}
1047910467
10468+ TEST_CASE("Test_Coil_Compacting_Tertiary_Winding", "[constructive-model][coil][bug][visualization]") {
10469+ auto testDataPath = get_test_data_path(std::source_location::current(), "bug_coil_compacting.json");
10470+ std::ifstream file(testDataPath);
10471+ REQUIRE(file.good());
10472+
10473+ json j;
10474+ file >> j;
10475+
10476+ auto magneticJson = j["magnetic"];
10477+ auto coilJson = magneticJson["coil"];
10478+ auto coreJson = magneticJson["core"];
10479+
10480+ OpenMagnetics::Coil coil(coilJson);
10481+ OpenMagnetics::Core core(coreJson);
10482+
10483+ // Enable compacting and additional coordinates
10484+ settings.set_coil_delimit_and_compact(true);
10485+ settings.set_coil_include_additional_coordinates(true);
10486+
10487+ // Wind the coil
10488+ coil.wind();
10489+
10490+ // Check if we have turns
10491+ REQUIRE(coil.get_turns_description().has_value());
10492+ auto turns = coil.get_turns_description().value();
10493+
10494+ // Create magnetic for visualization
10495+ OpenMagnetics::Magnetic magnetic;
10496+ magnetic.set_coil(coil);
10497+ magnetic.set_core(core);
10498+
10499+ // Paint the coil with core
10500+ auto outputFilePath = std::filesystem::path{std::source_location::current().file_name()}.parent_path().append("..").append("output");
10501+ auto outFile = outputFilePath;
10502+ outFile.append("Test_Coil_Compacting_Tertiary_Winding.svg");
10503+ std::filesystem::remove(outFile);
10504+
10505+ Painter painter(outFile);
10506+ painter.paint_core(magnetic);
10507+ painter.paint_bobbin(magnetic);
10508+ painter.paint_coil_sections(magnetic);
10509+ painter.paint_coil_turns(magnetic);
10510+ painter.export_svg();
10511+
10512+ // Analyze turns by winding
10513+ std::map<std::string, std::vector<Turn>> turnsByWinding;
10514+ for (const auto& turn : turns) {
10515+ turnsByWinding[turn.get_winding()].push_back(turn);
10516+ }
10517+
10518+ // Check each winding has additional coordinates
10519+ for (const auto& [windingName, windingTurns] : turnsByWinding) {
10520+ int withAdditional = 0;
10521+ int withoutAdditional = 0;
10522+
10523+ for (const auto& turn : windingTurns) {
10524+ if (turn.get_additional_coordinates().has_value()) {
10525+ withAdditional++;
10526+ } else {
10527+ withoutAdditional++;
10528+ }
10529+ }
10530+
10531+ // All turns should have additional coordinates
10532+ REQUIRE(withoutAdditional == 0);
10533+ }
10534+
10535+ settings.reset();
10536+ }
10537+
10538+
1048010539} // namespace
0 commit comments