From 9f39bf04196f2daa8d8c14cd4896a988f0edd6b1 Mon Sep 17 00:00:00 2001 From: Saumya Jain Date: Fri, 26 Apr 2024 15:45:54 +0200 Subject: [PATCH 1/4] writing debug.html in temp folder writing debug.html in the current folder (in case of build the program data) makes it read only and no write modifications are allowed, hence crash. Now it is written in temp foilder of the computer where writing the file is also allowed. --- src/utils/SVG.cpp | 2 +- src/utils/polygonUtils.cpp | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/utils/SVG.cpp b/src/utils/SVG.cpp index 4da036996a..96899b4a4e 100644 --- a/src/utils/SVG.cpp +++ b/src/utils/SVG.cpp @@ -87,7 +87,7 @@ SVG::SVG(std::string filename, AABB aabb, double scale, Point2LL canvas_size, Co out_ = fopen(filename.c_str(), "w"); if (! out_) { - spdlog::error("The file %s could not be opened for writing.", filename); + spdlog::error("The file {} could not be opened for writing.", filename); } if (output_is_html_) { diff --git a/src/utils/polygonUtils.cpp b/src/utils/polygonUtils.cpp index 7f7bc2466a..dba28c5324 100644 --- a/src/utils/polygonUtils.cpp +++ b/src/utils/polygonUtils.cpp @@ -15,12 +15,15 @@ #include "utils/linearAlg2D.h" #ifdef DEBUG +#include #include #include "utils/AABB.h" #include "utils/SVG.h" #endif +namespace fs = std::filesystem; + namespace cura { @@ -693,12 +696,13 @@ ClosestPolygonPoint PolygonUtils::ensureInsideOrOutside( static bool has_run = false; if (! has_run) { + fs::path const debug_file_name = fs::temp_directory_path() / "debug.html"; try { int offset_performed = offset / 2; AABB aabb(polygons); aabb.expand(std::abs(preferred_dist_inside) * 2); - SVG svg("debug.html", aabb); + SVG svg(debug_file_name.string(), aabb); svg.writeComment("Original polygon in black"); svg.writePolygons(polygons, SVG::Color::BLACK); for (auto poly : polygons) @@ -729,7 +733,7 @@ ClosestPolygonPoint PolygonUtils::ensureInsideOrOutside( catch (...) { } - spdlog::error("Clipper::offset failed. See generated debug.html! Black is original Blue is offsetted polygon"); + spdlog::error("Clipper::offset failed. See generated {}! Black is original Blue is offsetted polygon", debug_file_name.string()); has_run = true; } #endif From d4af3010a364be1f46ca11b8744438ee3c189cba Mon Sep 17 00:00:00 2001 From: saumyaj3 Date: Fri, 26 Apr 2024 13:46:37 +0000 Subject: [PATCH 2/4] Applied clang-format. --- src/utils/polygonUtils.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/utils/polygonUtils.cpp b/src/utils/polygonUtils.cpp index dba28c5324..9d18e82a95 100644 --- a/src/utils/polygonUtils.cpp +++ b/src/utils/polygonUtils.cpp @@ -16,6 +16,7 @@ #ifdef DEBUG #include + #include #include "utils/AABB.h" From 5d4a4f0ebf0fc97fb9bf02289cf41ab7625849ab Mon Sep 17 00:00:00 2001 From: Saumya Jain Date: Fri, 26 Apr 2024 16:52:49 +0200 Subject: [PATCH 3/4] removing debug code as its executing in production Also this code contains svg generation, which is majorly used in debugging application --- src/utils/polygonUtils.cpp | 51 -------------------------------------- 1 file changed, 51 deletions(-) diff --git a/src/utils/polygonUtils.cpp b/src/utils/polygonUtils.cpp index 9d18e82a95..6266b73ce1 100644 --- a/src/utils/polygonUtils.cpp +++ b/src/utils/polygonUtils.cpp @@ -15,16 +15,10 @@ #include "utils/linearAlg2D.h" #ifdef DEBUG -#include - #include - #include "utils/AABB.h" -#include "utils/SVG.h" #endif -namespace fs = std::filesystem; - namespace cura { @@ -693,51 +687,6 @@ ClosestPolygonPoint PolygonUtils::ensureInsideOrOutside( bool overall_is_inside = polygons.inside(overall_inside.location_); if (overall_is_inside != (preferred_dist_inside > 0)) { -#ifdef DEBUG - static bool has_run = false; - if (! has_run) - { - fs::path const debug_file_name = fs::temp_directory_path() / "debug.html"; - try - { - int offset_performed = offset / 2; - AABB aabb(polygons); - aabb.expand(std::abs(preferred_dist_inside) * 2); - SVG svg(debug_file_name.string(), aabb); - svg.writeComment("Original polygon in black"); - svg.writePolygons(polygons, SVG::Color::BLACK); - for (auto poly : polygons) - { - for (auto point : poly) - { - svg.writePoint(point, true, 2); - } - } - std::stringstream ss; - svg.writeComment("Reference polygon in yellow"); - svg.writePolygon(closest_poly, SVG::Color::YELLOW); - ss << "Offsetted polygon in blue with offset " << offset_performed; - svg.writeComment(ss.str()); - svg.writePolygons(insetted, SVG::Color::BLUE); - for (auto poly : insetted) - { - for (auto point : poly) - { - svg.writePoint(point, true, 2); - } - } - svg.writeComment("From location"); - svg.writePoint(from, true, 5, SVG::Color::GREEN); - svg.writeComment("Location computed to be inside the black polygon"); - svg.writePoint(inside.location_, true, 5, SVG::Color::RED); - } - catch (...) - { - } - spdlog::error("Clipper::offset failed. See generated {}! Black is original Blue is offsetted polygon", debug_file_name.string()); - has_run = true; - } -#endif return ClosestPolygonPoint(); } inside = overall_inside; From 38904ea4c533c4a9f6fb2af00a018432465d14c2 Mon Sep 17 00:00:00 2001 From: saumyaj3 Date: Fri, 26 Apr 2024 14:53:23 +0000 Subject: [PATCH 4/4] Applied clang-format. --- src/utils/polygonUtils.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/utils/polygonUtils.cpp b/src/utils/polygonUtils.cpp index 6266b73ce1..fff4f955ba 100644 --- a/src/utils/polygonUtils.cpp +++ b/src/utils/polygonUtils.cpp @@ -16,6 +16,7 @@ #ifdef DEBUG #include + #include "utils/AABB.h" #endif