Skip to content

Commit

Permalink
refs #65: Reconsider boundary values of tube
Browse files Browse the repository at this point in the history
  • Loading branch information
beutlich committed Sep 20, 2024
1 parent 1e48a79 commit f3c399e
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 40 deletions.
4 changes: 1 addition & 3 deletions Modelica_ResultCompare/CsvFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -322,9 +322,7 @@ public Report CompareFiles(Log log, CsvFile csvBase, string sReportPath, ref Opt
size = new TubeSize(reference, defaultNominalValue, useLegacyBaseAndRatio);
size.Calculate(_dRangeDelta, Axes.X, Relativity.Relative);
tube = new Tube(size);
double minX = Math.Max(compareCurve.X[0], reference.X[0]);
double maxX = Math.Min(compareCurve.X[compareCurve.X.Length - 1], reference.X[reference.X.Length - 1]);
var calcResult = tube.Calculate(reference, minX, maxX);
var calcResult = tube.Calculate(reference);
bool calcSuccess = calcResult.Item2;
if (!calcSuccess)
{
Expand Down
4 changes: 1 addition & 3 deletions Modelica_ResultCompare/CurveCompare/Algorithms/Algorithm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@ public class Algorithm
/// </summary>
/// <param name="reference">Reference curve with x and y values.</param>
/// <param name="size">Size of tube.</param>
/// <param name="minX">Min abscissa value.</param>
/// <param name="maxX">Max abscissa value.</param>
/// <returns>Collection of return values.</returns>
public virtual TubeReport Calculate(Curve reference, TubeSize size, double minX, double maxX)
public virtual TubeReport Calculate(Curve reference, TubeSize size)
{
return new TubeReport();
}
Expand Down
4 changes: 1 addition & 3 deletions Modelica_ResultCompare/CurveCompare/Algorithms/Ellipse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,8 @@ override public bool Successful
/// </summary>
/// <param name="reference">Reference curve with x and y values..</param>
/// <param name="size">Size of tube.</param>
/// <param name="minX">Min abscissa value.</param>
/// <param name="maxX">Max abscissa value.</param>
/// <returns>Collection of return values.</returns>
public override TubeReport Calculate(Curve reference, TubeSize size, double minX, double maxX)
public override TubeReport Calculate(Curve reference, TubeSize size)
{
/*
///This method generates tubes around a given curve.
Expand Down
68 changes: 41 additions & 27 deletions Modelica_ResultCompare/CurveCompare/Algorithms/Rectangle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,8 @@ override public bool Successful
/// </summary>
/// <param name="reference">Reference curve with x and y values.</param>
/// <param name="size">Size of tube.</param>
/// <param name="minX">Min abscissa value.</param>
/// <param name="maxX">Max abscissa value.</param>
/// <returns>Collection of return values.</returns>
public override TubeReport Calculate(Curve reference, TubeSize size, double minX, double maxX)
public override TubeReport Calculate(Curve reference, TubeSize size)
{
TubeReport report = new TubeReport();
successful = false;
Expand All @@ -49,8 +47,8 @@ public override TubeReport Calculate(Curve reference, TubeSize size, double minX
report.Reference = reference;
report.Size = size;
report.Algorithm = AlgorithmOptions.Rectangle;
report.Lower = CalculateLower(reference, size, minX, maxX);
report.Upper = CalculateUpper(reference, size, minX, maxX);
report.Lower = CalculateLower(reference, size);
report.Upper = CalculateUpper(reference, size);
if (report.Lower.ImportSuccessful && report.Upper.ImportSuccessful)
successful = true;
}
Expand All @@ -61,10 +59,8 @@ public override TubeReport Calculate(Curve reference, TubeSize size, double minX
/// </summary>
/// <param name="reference">Reference curve.</param>
/// <param name="size">Tube size.</param>
/// <param name="minX">Min abscissa value.</param>
/// <param name="maxX">Max abscissa value.</param>
/// <returns>Lower tube curve.</returns>
private static Curve CalculateLower(Curve reference, TubeSize size, double minX, double maxX)
private static Curve CalculateLower(Curve reference, TubeSize size)
{
List<double> LX = new List<double>(2 * reference.Count); // x-values of lower tube curve
List<double> LY = new List<double>(2 * reference.Count); // y-values of lower tube curve
Expand Down Expand Up @@ -208,17 +204,27 @@ private static Curve CalculateLower(Curve reference, TubeSize size, double minX,
// -------------------------------------------------------------------------------------------------------------

RemoveLoop(LX, LY, true);

while (LX.Count > 0 && LX[0] < minX - size.X / 2.0)
{
LX.RemoveAt(0);
LY.RemoveAt(0);
double minY = reference.Y[0] - size.Y;
while (LX.Count > 0 && LX[0] <= reference.X[0])
{
minY = Math.Min(minY, LY[0]);
LX.RemoveAt(0);
LY.RemoveAt(0);
}
LX.Insert(0, reference.X[0]);
LY.Insert(0, minY);
}

while (LX.Count > 0 && LX[LX.Count - 1] > maxX + size.X / 2.0)
{
LX.RemoveAt(LX.Count - 1);
LY.RemoveAt(LY.Count - 1);
double minY = reference.Y[reference.Count - 1] - size.Y;
while (LX.Count > 0 && LX[LX.Count - 1] >= reference.X[reference.Count - 1])
{
minY = Math.Min(minY, LY[LY.Count - 1]);
LX.RemoveAt(LX.Count - 1);
LY.RemoveAt(LY.Count - 1);
}
LX.Add(reference.X[reference.Count - 1]);
LY.Add(minY);
}

return new Curve("Lower", LX.ToArray(), LY.ToArray());
Expand All @@ -229,10 +235,8 @@ private static Curve CalculateLower(Curve reference, TubeSize size, double minX,
/// </summary>
/// <param name="reference">Reference curve.</param>
/// <param name="size">Tube size.</param>
/// <param name="minX">Min abscissa value.</param>
/// <param name="maxX">Max abscissa value.</param>
/// <returns>Upper tube curve.</returns>
private static Curve CalculateUpper(Curve reference, TubeSize size, double minX, double maxX)
private static Curve CalculateUpper(Curve reference, TubeSize size)
{
List<double> UX = new List<double>(2 * reference.Count); // x-values of upper tube curve
List<double> UY = new List<double>(2 * reference.Count); // y-values of upper tube curve
Expand Down Expand Up @@ -376,17 +380,27 @@ private static Curve CalculateUpper(Curve reference, TubeSize size, double minX,
// ---------------------------------------------------------------------------------------------------------

RemoveLoop(UX, UY, false);

while (UX.Count > 0 && UX[0] < minX - size.X / 2.0)
{
UX.RemoveAt(0);
UY.RemoveAt(0);
double maxY = reference.Y[0] + size.Y;
while (UX.Count > 0 && UX[0] <= reference.X[0])
{
maxY = Math.Max(maxY, UY[0]);
UX.RemoveAt(0);
UY.RemoveAt(0);
}
UX.Insert(0, reference.X[0]);
UY.Insert(0, maxY);
}

while (UX.Count > 0 && UX[UX.Count - 1] > maxX + size.X / 2.0)
{
UX.RemoveAt(UX.Count - 1);
UY.RemoveAt(UY.Count - 1);
double maxY = reference.Y[reference.Count - 1] + size.Y;
while (UX.Count > 0 && UX[UX.Count - 1] >= reference.X[reference.Count - 1])
{
maxY = Math.Max(maxY, UY[UY.Count - 1]);
UX.RemoveAt(UX.Count - 1);
UY.RemoveAt(UY.Count - 1);
}
UX.Add(reference.X[reference.Count - 1]);
UY.Add(maxY);
}

return new Curve("Upper", UX.ToArray(), UY.ToArray());
Expand Down
6 changes: 2 additions & 4 deletions Modelica_ResultCompare/CurveCompare/Tube.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,12 @@ public Tube(TubeSize size)
/// Calculates the Tube, that consists of 2 Curves: Lower and Upper.
/// </summary>
/// <param name="reference">Reference curve.</param>
/// <param name="minX">Min abscissa value.</param>
/// <param name="maxX">Max abscissa value.</param>
/// <returns>Tuple consisting of tube calculation and success state.</returns>
public Tuple<TubeReport, bool> Calculate(Curve reference, double minX, double maxX)
public Tuple<TubeReport, bool> Calculate(Curve reference)
{
if (ChooseAlgorithm())
{
TubeReport report = algorithm.Calculate(reference, size, minX, maxX);
TubeReport report = algorithm.Calculate(reference, size);
return Tuple.Create(report, algorithm.Successful);
}
return Tuple.Create(new TubeReport(), false);
Expand Down

0 comments on commit f3c399e

Please sign in to comment.