From e6c2f64c7333d6cafc615c2d1e7c4b59a06e7ff4 Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Mon, 12 Jan 2026 20:22:51 +0100 Subject: [PATCH] style: pre-commit --- docs/tutorials/tutorial_11.md | 42 +++++++++---------- .../framework_basics/systems_of_quantities.md | 6 +-- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/docs/tutorials/tutorial_11.md b/docs/tutorials/tutorial_11.md index 5acf27d55..91fe27dcd 100644 --- a/docs/tutorials/tutorial_11.md +++ b/docs/tutorials/tutorial_11.md @@ -61,7 +61,7 @@ Here's how different approaches handle (or fail to handle) this scenario: // Correct calculation requires manual tracking: double h_mercury_as_water = h_mercury_m * sg_mercury; // 27.2 m - + // Compare system requirement vs pump capacity if (h_mercury_as_water > h_pump_rating_m) { std::cout << "Pump is undersized!\n"; // This will trigger! @@ -72,27 +72,27 @@ Here's how different approaches handle (or fail to handle) this scenario: ```cpp #include - + using namespace boost::units; using namespace boost::units::si; - + quantity h_mercury = 2.0 * meters; quantity h_pump_rating = 10.0 * meters; double sg_mercury = 13.6; - + // Direct addition - compiles but physically wrong! quantity total_head = h_mercury + h_pump_rating; // WRONG! // Both are lengths, so Boost.Units allows this - + // Correct calculation still requires manual tracking: quantity h_mercury_as_water = h_mercury * sg_mercury; - + // Compare system requirement vs pump capacity if (h_mercury_as_water > h_pump_rating) { std::cout << "Pump is undersized!\n"; // This will trigger! } ``` - + **Problem**: Boost.Units checks dimensional compatibility (both are lengths), but cannot distinguish between physically incompatible types of length. @@ -101,23 +101,23 @@ Here's how different approaches handle (or fail to handle) this scenario: ```python import pint ureg = pint.UnitRegistry() - + h_mercury = 2.0 * ureg.meter h_pump_rating = 10.0 * ureg.meter sg_mercury = 13.6 - + # Direct addition - works but physically wrong! total_head = h_mercury + h_pump_rating # WRONG! # Both have dimension [length], so Pint allows this - + # Correct calculation still requires manual tracking: h_mercury_as_water = h_mercury * sg_mercury - + # Compare system requirement vs pump capacity if h_mercury_as_water > h_pump_rating: print("Pump is undersized!") # This will trigger! ``` - + **Problem**: Pint prevents dimensional errors but cannot distinguish between different physical meanings of the same dimension. @@ -215,12 +215,12 @@ int main() // Convert mercury fluid head to equivalent water head quantity h_mercury_as_water = to_water_head(h_mercury, sg_mercury); - + std::cout << "Mercury equivalent (water head): " << h_mercury_as_water << "\n\n"; // Verify pump capacity against system requirement if (h_mercury_as_water > h_pump_rating) { - std::cout << "WARNING: System requirement (" << h_mercury_as_water + std::cout << "WARNING: System requirement (" << h_mercury_as_water << ") exceeds pump rating (" << h_pump_rating << ")!\n"; std::cout << "Pump is UNDERSIZED for this application.\n"; } @@ -253,7 +253,7 @@ int main() // 3. Define Conversion Helpers // Formula: H_water = H_fluid * SG - constexpr QuantityOf auto to_water_head(QuantityOf auto h_fluid, + constexpr QuantityOf auto to_water_head(QuantityOf auto h_fluid, QuantityOf auto sg) { // We explicitly cast the result to water_head because we know the physics is correct @@ -261,7 +261,7 @@ int main() } // Formula: H_fluid = H_water / SG - constexpr QuantityOf auto to_fluid_head(QuantityOf auto h_water, + constexpr QuantityOf auto to_fluid_head(QuantityOf auto h_water, QuantityOf auto sg) { return fluid_head(isq::height(h_water) / sg); @@ -290,12 +290,12 @@ int main() // Convert mercury fluid head to equivalent water head quantity h_mercury_as_water = to_water_head(h_mercury, sg_mercury); - + std::cout << "Mercury equivalent (water head): " << h_mercury_as_water << "\n\n"; // Verify pump capacity against system requirement if (h_mercury_as_water > h_pump_rating) { - std::cout << "WARNING: System requirement (" << h_mercury_as_water + std::cout << "WARNING: System requirement (" << h_mercury_as_water << ") exceeds pump rating (" << h_pump_rating << ")!\n"; std::cout << "Pump is UNDERSIZED for this application.\n"; } @@ -318,14 +318,14 @@ int main() - **Compile-time prevention**: Direct addition, comparison, or assignment between fluid head and water head results in a compile error - + - **Explicit conversion required**: The `to_water_head` and `to_fluid_head` functions perform the physics-based conversion through specific gravity, making the conversion visible and intentional in the code - + - **Type safety at boundaries**: Functions accepting `QuantityOf` or `QuantityOf` cannot accidentally receive the wrong type - + - **Base quantity access**: When needed, both can be converted to `isq::height` using `isq::height(h)`, allowing generic height operations while preserving type safety at domain boundaries diff --git a/docs/users_guide/framework_basics/systems_of_quantities.md b/docs/users_guide/framework_basics/systems_of_quantities.md index c9c9326e2..992317bb5 100644 --- a/docs/users_guide/framework_basics/systems_of_quantities.md +++ b/docs/users_guide/framework_basics/systems_of_quantities.md @@ -543,7 +543,7 @@ Quantities marked with `is_kind` behave differently from regular hierarchy membe ```cpp quantity h_fluid = fluid_head(2 * m); quantity h_water = water_head(10 * m); - + // auto sum = h_fluid + h_water; // Compile-time error! // bool cmp = h_fluid < h_water; // Compile-time error! ``` @@ -557,7 +557,7 @@ Quantities marked with `is_kind` behave differently from regular hierarchy membe // Convert to base quantity explicitly quantity h1 = isq::height(h_fluid); // explicit conversion required quantity h2 = isq::height(h_water); // explicit conversion required - + // Now generic operations are possible auto sum = h1 + h2; // OK: both are isq::height ``` @@ -602,7 +602,7 @@ constexpr QuantityOf auto to_water_head(QuantityOf auto return water_head(isq::height(h_fluid) * sg); } -// Physics: H_fluid = H_water / SG +// Physics: H_fluid = H_water / SG constexpr QuantityOf auto to_fluid_head(QuantityOf auto h_water, QuantityOf auto sg) {