From 6ca27539519d2e00a09d38b712263babb6261342 Mon Sep 17 00:00:00 2001 From: John Colvin Date: Thu, 11 Aug 2022 01:29:59 -0400 Subject: [PATCH] fix (vs): Use precison in terms of actual data for eq comp Bugs (fixed): * The tick up/down buttons have no effect for vol input cells Cause: The cell vm ignores some value updates because the equality comparer incorrectly considers the new value equal to the current one (because it doesn't use enough decimal places in the comparison) --- .../AW2/Grid/VolSurfaceDisplayUtilities.cs | 21 ++++++++++++++++--- .../spark_api/utils/NumericExtensions.cs | 9 ++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/client/spark/AW2/Grid/VolSurfaceDisplayUtilities.cs b/src/client/spark/AW2/Grid/VolSurfaceDisplayUtilities.cs index 9eee43102..ff824058c 100644 --- a/src/client/spark/AW2/Grid/VolSurfaceDisplayUtilities.cs +++ b/src/client/spark/AW2/Grid/VolSurfaceDisplayUtilities.cs @@ -64,8 +64,21 @@ return tick_factors.tick(dbl, is_up ? tick_move : -tick_move); }; - public static IEqualityComparer get_double_comparer(TickFactors tick_factors = null) => - (tick_factors ?? new(10^7, 1)).tick_equality_comparer(); + public static IEqualityComparer get_double_comparer( + TickFactors tick_factors = null, double display_mult = double.NaN) { + if (tick_factors is null) { + return new TickFactors(10^7, 1).tick_equality_comparer(); + } + // This equality comparer is used to compare actual values (not multiplied by + // 'display_mult'), while the TickFactors are used to format the display value (multiplied + // by 'display_mult'). Multiply the tick base by 'display_mult' so the equality comparison + // is done with the correct number of decimal places. + if (display_mult > 0 && Math.Log10(display_mult).is_int()) { + tick_factors = tick_factors.with( + tick_base: tick_factors.tick_base * display_mult); + } + return tick_factors.tick_equality_comparer(); + } public static VolSurfaceDisplayGridColumn get_double_output_col( string group, @@ -128,7 +141,9 @@ format: get_double_tostring(col_config.tick_factors, col_config.tick_display), parse: get_parse_double(col_config.tick_factors, col_config.tick_display), tick_move: get_double_tickmove(col_config.tick_factors, col_config.tick_move), - comparer: get_double_comparer(col_config.tick_factors).cast()); + comparer: get_double_comparer( + col_config.tick_factors, col_config.tick_display.display_multiplier) + .cast()); } } } diff --git a/src/client/spark_api/utils/NumericExtensions.cs b/src/client/spark_api/utils/NumericExtensions.cs index da6ee175b..6423a33cf 100644 --- a/src/client/spark_api/utils/NumericExtensions.cs +++ b/src/client/spark_api/utils/NumericExtensions.cs @@ -43,6 +43,15 @@ namespace bts.utils { public static T if_nan(this T d, T if_nan) where T : IFloatingPoint => d.is_nan() ? if_nan : d; + public static bool is_int(this T value) where T : IFloatingPoint => + MathUtils.is_int(value); + + public static bool is_int(this T value, T epsilon) where T : IFloatingPoint => + MathUtils.is_int(value, epsilon); + + public static bool is_int(this T value, out T with_int_value) where T : IFloatingPoint => + MathUtils.is_int(value, out with_int_value); + public static T get_if(this T i, Func get, T comparand) where T : INumber => i == comparand ? get() : i;