diff --git a/pcbnew/autorouter/spread_footprints.cpp b/pcbnew/autorouter/spread_footprints.cpp index 7e573304da..370f38e188 100644 --- a/pcbnew/autorouter/spread_footprints.cpp +++ b/pcbnew/autorouter/spread_footprints.cpp @@ -5,7 +5,7 @@ * Copyright (C) 2013 SoftPLC Corporation, Dick Hollenbeck * Copyright (C) 2013 Wayne Stambaugh * - * Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -35,6 +35,7 @@ */ #include +#include #include #include #include @@ -77,12 +78,13 @@ static bool compareFootprintsbyRef( FOOTPRINT* ref, FOOTPRINT* compare ) // Spread a list of rectangles inside a placement area -rectpack2D::rect_wh spreadRectangles( rect_vector& vecSubRects, int areaSizeX, int areaSizeY ) +std::optional spreadRectangles( rect_vector& vecSubRects, int areaSizeX, + int areaSizeY ) { areaSizeX /= scale; areaSizeY /= scale; - rectpack2D::rect_wh result; + std::optional result; int max_side = std::max( areaSizeX, areaSizeY ); @@ -107,7 +109,7 @@ rectpack2D::rect_wh spreadRectangles( rect_vector& vecSubRects, int areaSizeX, i make_finder_input( max_side, discard_step, report_successful, report_unsuccessful, rectpack2D::flipping_option::DISABLED ) ); - if( anyUnsuccessful ) + if( !result || anyUnsuccessful ) { max_side = (int) ( max_side * 1.2 ); continue; diff --git a/thirdparty/rectpack2d/rectpack2d/best_bin_finder.h b/thirdparty/rectpack2d/rectpack2d/best_bin_finder.h index a76b47d1f6..fe17ca7dcf 100644 --- a/thirdparty/rectpack2d/rectpack2d/best_bin_finder.h +++ b/thirdparty/rectpack2d/rectpack2d/best_bin_finder.h @@ -1,4 +1,5 @@ #pragma once +#include #include #include #include "rect_structs.h" @@ -213,7 +214,7 @@ namespace rectpack2D { class F, class I > - rect_wh find_best_packing_impl(F for_each_order, const I input) { + std::optional find_best_packing_impl(F for_each_order, const I input) { const auto max_bin = rect_wh(input.max_bin_side, input.max_bin_side); OrderType* best_order = nullptr; @@ -258,9 +259,8 @@ namespace rectpack2D { } }); + if( best_order != nullptr ) { - assert(best_order != nullptr); - root.reset(best_bin); for (auto& rr : *best_order) { @@ -281,6 +281,10 @@ namespace rectpack2D { } return root.get_rects_aabb(); - } + } + else + { + return std::nullopt; + } } } diff --git a/thirdparty/rectpack2d/rectpack2d/finders_interface.h b/thirdparty/rectpack2d/rectpack2d/finders_interface.h index c3ef8217db..3bd61e997d 100644 --- a/thirdparty/rectpack2d/rectpack2d/finders_interface.h +++ b/thirdparty/rectpack2d/rectpack2d/finders_interface.h @@ -69,7 +69,7 @@ namespace rectpack2D { */ template - rect_wh find_best_packing( + std::optional find_best_packing( std::vector>& subjects, const finder_input& input, @@ -122,7 +122,7 @@ namespace rectpack2D { */ template - rect_wh find_best_packing( + std::optional find_best_packing( std::vector>& subjects, const finder_input& input ) {