lmi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [lmi] master e21dd5c 5/6: Refactor: use outward_quotient()


From: Greg Chicares
Subject: [lmi-commits] [lmi] master e21dd5c 5/6: Refactor: use outward_quotient(), asserting equivalence
Date: Fri, 25 May 2018 07:00:58 -0400 (EDT)

branch: master
commit e21dd5cc5b271202d43971716ab55a776bd53343
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>

    Refactor: use outward_quotient(), asserting equivalence
    
    The old code, and the assertions validating the new code against the
    old, will be removed in the next commit.
---
 group_quote_pdf_gen_wx.cpp |  5 ++++-
 miscellany.cpp             |  5 ++++-
 wx_table_generator.cpp     | 11 +++++++++--
 3 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/group_quote_pdf_gen_wx.cpp b/group_quote_pdf_gen_wx.cpp
index a9ac147..dcf727a 100644
--- a/group_quote_pdf_gen_wx.cpp
+++ b/group_quote_pdf_gen_wx.cpp
@@ -33,6 +33,7 @@
 #include "ledger_invariant.hpp"
 #include "ledger_text_formats.hpp"      // ledger_format()
 #include "ledger_variant.hpp"
+#include "math_functions.hpp"           // outward_quotient()
 #include "mc_enum_types_aux.hpp"        // is_subject_to_ill_reg()
 #include "miscellany.hpp"               // split_into_lines()
 #include "oecumenic_enumerations.hpp"   // oenum_format_style
@@ -822,7 +823,9 @@ int 
group_quote_pdf_generator_wx::compute_pages_for_table_rows
         int const first_row_y = pdf_writer.get_vert_margin() + header_height;
         int const page_area_y = last_row_y - first_row_y;
         int const rows_per_page = page_area_y / row_height;
-        total_pages += (remaining_rows + rows_per_page - 1) / rows_per_page;
+        auto total_pagesX = total_pages + (remaining_rows + rows_per_page - 1) 
/ rows_per_page;
+        total_pages += outward_quotient(remaining_rows, rows_per_page);
+LMI_ASSERT(total_pagesX == total_pages);
         *remaining_space = page_area_y;
         remaining_rows %= rows_per_page;
         }
diff --git a/miscellany.cpp b/miscellany.cpp
index 4d723f8..193d544 100644
--- a/miscellany.cpp
+++ b/miscellany.cpp
@@ -25,6 +25,7 @@
 
 #include "alert.hpp"
 #include "assert_lmi.hpp"
+#include "math_functions.hpp"           // outward_quotient()
 
 #include <algorithm>                    // equal(), max()
 #include <cmath>                        // ceil(), floor()
@@ -314,7 +315,9 @@ int page_count
     int const used_per_page = groups_per_page * rows_per_group;
 
     // Finally determine how many pages are needed to show all the rows.
-    int number_of_pages = (total_rows + used_per_page - 1) / used_per_page;
+    int number_of_pagesX = (total_rows + used_per_page - 1) / used_per_page;
+    int number_of_pages = outward_quotient(total_rows, used_per_page);
+LMI_ASSERT(number_of_pagesX == number_of_pages);
 
     // The last page may not be needed if all the rows on it can fit into the
     // remaining space, too small for a full group, but perhaps sufficient for
diff --git a/wx_table_generator.cpp b/wx_table_generator.cpp
index f2a5d82..85e4a42 100644
--- a/wx_table_generator.cpp
+++ b/wx_table_generator.cpp
@@ -25,6 +25,7 @@
 
 #include "alert.hpp"
 #include "assert_lmi.hpp"
+#include "math_functions.hpp"           // outward_quotient()
 #include "miscellany.hpp"               // count_newlines(), split_into_lines()
 
 #include <algorithm>                    // max()
@@ -397,8 +398,11 @@ void wx_table_generator::compute_column_widths()
 // Also calculate the number of pixels by which it overflows for each column
             // We need to round up in division here to be sure that all columns
             // fit into the available width.
-            auto const overflow_per_column =
+            auto const overflow_per_columnX =
                 (overflow + number_of_columns - 1) / number_of_columns;
+            auto const overflow_per_column =
+                outward_quotient(overflow, number_of_columns);
+LMI_ASSERT(overflow_per_columnX == overflow_per_column);
 // Now determine whether reducing the margins will make the table fit.
 // If that works, then do it; else don't do it, and print a warning.
 //
@@ -496,8 +500,11 @@ void wx_table_generator::compute_column_widths()
     // to consume all available space.
     if(number_of_elastic_columns)
         {
-        int const width_of_each_elastic_column
+        int const width_of_each_elastic_columnX
             = (total_width_ - total_inelastic_width + 
number_of_elastic_columns - 1) / number_of_elastic_columns;
+        int const width_of_each_elastic_column
+            = outward_quotient(total_width_ - total_inelastic_width, 
number_of_elastic_columns);
+LMI_ASSERT(width_of_each_elastic_columnX == width_of_each_elastic_column);
 
         for(auto& i : all_columns_)
             {



reply via email to

[Prev in Thread] Current Thread [Next in Thread]