refactor IsRealNonZero to is_real_positive (orig name was a typo), add a few more similar extensions to MathUtils
This commit is contained in:
1 parent
f5bda11797
commit
8c9f669e72
4 files changed
+26
-6
No files matched your search
@@ -38,9 +38,6 @@ namespace mbts {
|
||||
public static bool IsNonZero(this double value) =>
|
||||
value != 0 && !double.IsNaN(value) && !double.IsInfinity(value);
|
||||
|
||||
public static bool IsRealNonZero(this double value) =>
|
||||
value > 0 && value != double.PositiveInfinity;
|
||||
|
||||
public static double CoerceNaN(double value) => CoerceNaN(value, 0.0);
|
||||
public static double CoerceNaN(double value, double if_nan) => double.IsNaN(value) ? if_nan : value;
|
||||
public static double CoerceNaNOrInfinity(double value) => CoerceNaNOrInfinity(value, 0.0);
|
||||
|
||||
@@ -183,7 +183,7 @@ namespace mbts.ui.dpi {
|
||||
}
|
||||
|
||||
public static void DrawHorizontalLine(this DrawingContext drawing_context, System.Windows.Media.Pen pen, Point start, double length, bool snap_to_device_pixels) {
|
||||
if (pen == null || !length.IsRealNonZero()) {
|
||||
if (pen == null || !length.is_real_positive()) {
|
||||
// no need to flip out and throw an exception
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using bts.utils;
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Windows.Markup;
|
||||
|
||||
@@ -19,7 +20,7 @@ namespace mbts.ui {
|
||||
public double RoundingUnit { get; set; }
|
||||
|
||||
public override object ProvideValue(IServiceProvider serviceProvider) =>
|
||||
RoundingUnit.IsRealNonZero() ? Math.Round(Value * RoundingUnit) / RoundingUnit : Value;
|
||||
RoundingUnit.is_real_non_zero() ? Math.Round(Value * RoundingUnit) / RoundingUnit : Value;
|
||||
}
|
||||
|
||||
internal class DoubleStringTypeConverter : TypeConverter
|
||||
|
||||
@@ -110,6 +110,28 @@ namespace bts.utils {
|
||||
return epsilon_equals(with_int_value, d);
|
||||
}
|
||||
|
||||
public static bool is_real(this double value) {
|
||||
switch (value) {
|
||||
case double.PositiveInfinity:
|
||||
case double.NegativeInfinity:
|
||||
case double.NaN:
|
||||
return false;
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool is_real_positive(this double value) =>
|
||||
value > 0 && value != double.PositiveInfinity;
|
||||
|
||||
public static bool is_real_negative(this double value) =>
|
||||
value < 0 && value != double.NegativeInfinity;
|
||||
|
||||
public static bool is_real_non_zero(this double value) =>
|
||||
value > 0 ?
|
||||
!double.IsPositiveInfinity(value) :
|
||||
value < 0 && !double.IsNegativeInfinity(value);
|
||||
|
||||
public static double factor_out(double value, params double[] factors) {
|
||||
foreach (double f in factors)
|
||||
value = factor_out(value, f, out int _);
|
||||
|
||||
Reference in new issue
Block a user