Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Diffing_Engine: reworked the NumericTolerance mechanism #3040

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions Diffing_Engine/Query/NumericalDifferenceInclusion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public static partial class Query
[Input("number2", "Second number to compare.")]
[Input("propertyFullName", "If the numbers are part of an object, full name of the property that owns them. This name will be used to seek matches in the ComparisoConfig named numeric tolerance/significant figures.")]
[Input("comparisonConfig", "Object containing the settings for this numerical comparison.")]
[Output("seenAsDifferent", "Whether the input numbers are seen as different, given the numerical approximations specified in the comparisonConfig.")]
public static bool NumericalDifferenceInclusion(this object number1, object number2, string propertyFullName = null, BaseComparisonConfig comparisonConfig = null)
{
comparisonConfig = comparisonConfig ?? new ComparisonConfig();
Expand All @@ -64,6 +65,7 @@ public static bool NumericalDifferenceInclusion(this object number1, object numb
[Input("globalNumericTolerance", "Fallback numeric tolerance to be used when no named match is found.")]
[Input("namedSignificantFigures", "Custom significant figures associated with a certain name, to be matched with the `fullName` input.")]
[Input("globalSignificantFigures", "Fallback significant figures to be used when no named match is found.")]
[Output("seenAsDifferent", "Whether the input numbers are seen as different, given the numerical approximations specified.")]
public static bool NumericalDifferenceInclusion(this object number1, object number2, string fullName,
HashSet<NamedNumericTolerance> namedNumericTolerances = null,
double globalNumericTolerance = double.MinValue,
Expand All @@ -83,12 +85,13 @@ public static bool NumericalDifferenceInclusion(this object number1, object numb
double toleranceToUse = BH.Engine.Base.Query.NumericTolerance(namedNumericTolerances, globalNumericTolerance, fullName);
if (toleranceToUse != double.MinValue)
{
double value1 = double.Parse(number1.ToString()).RoundWithTolerance(toleranceToUse);
double value2 = double.Parse(number2.ToString()).RoundWithTolerance(toleranceToUse);
double value1 = double.Parse(number1.ToString());
double value2 = double.Parse(number2.ToString());

// If, once rounded, the numbers are the same, it means that we do not want to consider this Difference. Skip.
if (value1 == value2)
return false;
double difference = Math.Abs(value1 - value2);

// If the difference is less than the Tolerance, it means that we do not want to consider this Difference. Skip.
return difference > toleranceToUse;
}
}

Expand All @@ -101,8 +104,7 @@ public static bool NumericalDifferenceInclusion(this object number1, object numb
double value2 = double.Parse(number2.ToString()).RoundToSignificantFigures(significantFiguresToUse);

// If, once rounded, the numbers are the same, it means that we do not want to consider this Difference. Skip.
if (value1 == value2)
return false;
return value1 != value2;
}
}
}
Expand Down