From e63a7b59409d976b4d4138e0d36407ff231d4a74 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Sun, 23 Jun 2024 18:21:30 +0200 Subject: [PATCH] WIP: optimization of sized_inside - distance can be reduced to 0 if 'inside' is merged --- src/db/db/dbAsIfFlatRegion.cc | 12 +++++++++--- src/db/db/dbDeepRegion.cc | 8 ++++++-- src/db/db/dbRegionLocalOperations.cc | 11 +++++++---- src/db/db/dbRegionLocalOperations.h | 3 ++- 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/db/db/dbAsIfFlatRegion.cc b/src/db/db/dbAsIfFlatRegion.cc index 75fe7a90c..235f8e02c 100644 --- a/src/db/db/dbAsIfFlatRegion.cc +++ b/src/db/db/dbAsIfFlatRegion.cc @@ -1386,15 +1386,21 @@ AsIfFlatRegion::sized_inside (const Region &inside, coord_type d, int steps, uns RegionDelegate * AsIfFlatRegion::sized_inside (const Region &inside, coord_type dx, coord_type dy, int steps, unsigned int mode, const Region *stop_at) const { - if (steps <= 0) { + if (steps <= 0 || empty ()) { + // Nothing to do - NOTE: don't return EmptyRegion because we want to + // maintain "deepness" return clone (); } + if (dx < 0 || dy < 0) { + throw tl::Exception (tl::to_string (tr ("'sized_inside' operation does not make sense with negative sizing"))); + } + std::unique_ptr output (new FlatRegion ()); std::vector results; results.push_back (&output->raw_polygons ()); - db::sized_inside_local_operation op (dx, dy, steps, mode); + db::sized_inside_local_operation op (dx, dy, steps, mode, true /*inside layer is merged*/); db::local_processor proc; proc.set_base_verbosity (base_verbosity ()); @@ -1402,7 +1408,7 @@ AsIfFlatRegion::sized_inside (const Region &inside, coord_type dx, coord_type dy proc.set_report_progress (report_progress ()); std::vector > others; - others.push_back (inside.begin ()); + others.push_back (inside.begin_merged ()); if (stop_at) { others.push_back (stop_at->begin ()); } diff --git a/src/db/db/dbDeepRegion.cc b/src/db/db/dbDeepRegion.cc index 38ebbf9f2..5dbca4150 100644 --- a/src/db/db/dbDeepRegion.cc +++ b/src/db/db/dbDeepRegion.cc @@ -1796,6 +1796,10 @@ DeepRegion::sized_inside (const Region &inside, coord_type dx, coord_type dy, in return clone (); } + if (dx < 0 || dy < 0) { + throw tl::Exception (tl::to_string (tr ("'sized_inside' operation does not make sense with negative sizing"))); + } + const db::DeepRegion *inside_deep = dynamic_cast (inside.delegate ()); if (! inside_deep) { return db::AsIfFlatRegion::sized_inside (inside, dx, dy, steps, mode, stop_at); @@ -1818,9 +1822,9 @@ DeepRegion::sized_inside (const Region &inside, coord_type dx, coord_type dy, in } const db::DeepLayer &polygons = merged_deep_layer (); - const db::DeepLayer &inside_polygons = inside_deep->deep_layer (); + const db::DeepLayer &inside_polygons = inside_deep->merged_deep_layer (); - db::sized_inside_local_operation op (dx, dy, steps, mode); + db::sized_inside_local_operation op (dx, dy, steps, mode, true /*inside layer is merged*/); db::local_processor proc (const_cast (&polygons.layout ()), const_cast (&polygons.initial_cell ()), &inside_polygons.layout (), &inside_polygons.initial_cell (), polygons.breakout_cells (), inside_polygons.breakout_cells ()); configure_proc (proc); diff --git a/src/db/db/dbRegionLocalOperations.cc b/src/db/db/dbRegionLocalOperations.cc index a38b068b4..e0799dbe0 100644 --- a/src/db/db/dbRegionLocalOperations.cc +++ b/src/db/db/dbRegionLocalOperations.cc @@ -1948,17 +1948,20 @@ template class DB_PUBLIC two_bool_and_not_local_operation_with_properties -sized_inside_local_operation::sized_inside_local_operation (db::Coord dx, db::Coord dy, int steps, unsigned int mode) - : m_dx (dx), m_dy (dy), m_steps (steps), m_mode (mode) +sized_inside_local_operation::sized_inside_local_operation (db::Coord dx, db::Coord dy, int steps, unsigned int mode, bool inside_is_merged) + : m_dx (dx), m_dy (dy), m_steps (steps), m_mode (mode), m_dist (0) { - // .. nothing yet .. + m_dist = 0; + if (! inside_is_merged) { + m_dist = std::max (0, std::max (m_dx, m_dy)); + } } template db::Coord sized_inside_local_operation::dist () const { - return std::max (0, std::max (m_dx, m_dy)); + return m_dist; } template diff --git a/src/db/db/dbRegionLocalOperations.h b/src/db/db/dbRegionLocalOperations.h index 76f5ba4b4..46ff57814 100644 --- a/src/db/db/dbRegionLocalOperations.h +++ b/src/db/db/dbRegionLocalOperations.h @@ -471,7 +471,7 @@ class DB_PUBLIC sized_inside_local_operation : public local_operation { public: - sized_inside_local_operation (db::Coord dx, db::Coord dy, int steps, unsigned int mode); + sized_inside_local_operation (db::Coord dx, db::Coord dy, int steps, unsigned int mode, bool inside_is_merged); virtual db::Coord dist () const; virtual OnEmptyIntruderHint on_empty_intruder_hint () const; @@ -486,6 +486,7 @@ public: private: db::Coord m_dx, m_dy; + db::Coord m_dist; int m_steps; unsigned int m_mode; db::MagnificationAndOrientationReducer m_vars_anisotropic;