From 3ca99907de99242c55ea4ce00558ccd71d6a6589 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Sat, 25 May 2024 14:24:00 +0200 Subject: [PATCH] Improved OASIS-to-OASIS file size by re-introducing sorting of repetition arrays --- .../oasis/db_plugin/dbOASISWriter.cc | 62 ++++++++++--------- 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/src/plugins/streamers/oasis/db_plugin/dbOASISWriter.cc b/src/plugins/streamers/oasis/db_plugin/dbOASISWriter.cc index fa93a540d..3b6393e38 100644 --- a/src/plugins/streamers/oasis/db_plugin/dbOASISWriter.cc +++ b/src/plugins/streamers/oasis/db_plugin/dbOASISWriter.cc @@ -47,6 +47,36 @@ static const char *s_bounding_box_name = "S_BOUNDING_BOX"; // --------------------------------------------------------------------------------- +/** + * @brief Compare operator for points, distinct x clustered (with same y) + */ +struct vector_cmp_x +{ + bool operator() (const db::Vector &a, const db::Vector &b) const + { + if (a.y () != b.y ()) { + return a.y () < b.y (); + } else { + return a.x () < b.x (); + } + } +}; + +/** + * @brief Compare operator for points, distinct y clustered (with same x) + */ +struct vector_cmp_y +{ + bool operator() (const db::Vector &a, const db::Vector &b) const + { + if (a.x () != b.x ()) { + return a.x () < b.x (); + } else { + return a.y () < b.y (); + } + } +}; + /** * @brief Determines whether a property shall be produced as S_GDS_PROPERTY */ @@ -224,6 +254,7 @@ template void create_repetition_by_type (const db::Shape &array_shap *pw++ = *p - po; } pts.erase (pw, pts.end ()); + std::sort (pts.begin (), pts.end (), vector_cmp_x ()); db::IrregularRepetition *rep_base = new db::IrregularRepetition (); rep_base->points ().swap (pts); @@ -269,36 +300,6 @@ void create_repetition (const db::Shape &array, db::Repetition &rep) } } -/** - * @brief Compare operator for points, distinct x clustered (with same y) - */ -struct vector_cmp_x -{ - bool operator() (const db::Vector &a, const db::Vector &b) const - { - if (a.y () != b.y ()) { - return a.y () < b.y (); - } else { - return a.x () < b.x (); - } - } -}; - -/** - * @brief Compare operator for points, distinct y clustered (with same x) - */ -struct vector_cmp_y -{ - bool operator() (const db::Vector &a, const db::Vector &b) const - { - if (a.x () != b.x ()) { - return a.x () < b.x (); - } else { - return a.y () < b.y (); - } - } -}; - /** * @brief Compare operator for points/abstract repetition pair with configurable point compare operator */ @@ -2030,6 +2031,7 @@ OASISWriter::write (const db::CellInstArray &inst, db::properties_id_type prop_i *pw++ = *p - po; } pts.erase (pw, pts.end ()); + std::sort (pts.begin (), pts.end (), vector_cmp_x ()); db::IrregularRepetition *rep_base = new db::IrregularRepetition (); rep_base->points ().swap (pts);