Skip to content

Commit

Permalink
Handle shorter reference curves (in Rectangle algorithm only) (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
beutlich authored Sep 24, 2024
1 parent 6c456d6 commit c4a1820
Showing 1 changed file with 43 additions and 12 deletions.
55 changes: 43 additions & 12 deletions Modelica_ResultCompare/CurveCompare/Algorithms/Rectangle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

// for visualization with ChartControl
#if GUI
Expand Down Expand Up @@ -64,7 +62,6 @@ public override TubeReport Calculate(Curve reference, TubeSize size)
/// <returns>Lower tube curve.</returns>
private static Curve CalculateLower(Curve reference, TubeSize size)
{
Curve lower; // lower tube curve
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 @@ -148,7 +145,6 @@ private static Curve CalculateLower(Curve reference, TubeSize size)
{
// add point down left
LX.Add(reference.X[i] - size.X);

LY.Add(reference.Y[i] - size.Y);
// add point down right
LX.Add(reference.X[i] + size.X);
Expand Down Expand Up @@ -207,10 +203,10 @@ private static Curve CalculateLower(Curve reference, TubeSize size)
// -------------- 2. Remove points and add intersection points in case of backward order -----------------------
// -------------------------------------------------------------------------------------------------------------

removeLoop(LX, LY, true);
RemoveLoop(LX, LY, true);
FixBoundaries(LX, LY, reference);

lower = new Curve("Lower", LX.ToArray(), LY.ToArray());
return lower;
return new Curve("Lower", LX.ToArray(), LY.ToArray());
}

/// <summary>
Expand All @@ -221,7 +217,6 @@ private static Curve CalculateLower(Curve reference, TubeSize size)
/// <returns>Upper tube curve.</returns>
private static Curve CalculateUpper(Curve reference, TubeSize size)
{
Curve upper; // upper tube curve
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 @@ -363,10 +358,10 @@ private static Curve CalculateUpper(Curve reference, TubeSize size)
// -------------- 2. Remove points and add intersection points in case of backward order -------------------
// ---------------------------------------------------------------------------------------------------------

removeLoop(UX, UY, false);
RemoveLoop(UX, UY, false);
FixBoundaries(UX, UY, reference);

upper = new Curve("Upper", UX.ToArray(), UY.ToArray());
return upper;
return new Curve("Upper", UX.ToArray(), UY.ToArray());
}
/// <summary>
/// Remove points and add intersection points in case of backward order
Expand All @@ -376,7 +371,7 @@ private static Curve CalculateUpper(Curve reference, TubeSize size)
/// <param name="lower">if true, algorithm for lower tube curve is used;<para>
/// if false, algorithm for upper tube curve is used</para></param>
/// <return>Number of loops, that are removed.</return>
private static int removeLoop(List<double> X, List<double> Y, bool lower)
private static int RemoveLoop(List<double> X, List<double> Y, bool lower)
{
// Visualization of working of removeLoop
#if GUI
Expand Down Expand Up @@ -555,5 +550,41 @@ private static int removeLoop(List<double> X, List<double> Y, bool lower)
#endif
return countLoops;
}
/// <summary>
/// Fix the boundary values of the tube curve.
/// </summary>
/// <param name="X">x values of curve</param>
/// <param name="Y">y values of curve</param>
/// <param name="reference">Reference curve.</param>
private static void FixBoundaries(List<double> X, List<double> Y, Curve reference)
{
while (X.Count > 0 && X[0] <= reference.X[0])
{
if (X.Count > 1 && X[1] > reference.X[0])
{
Y[0] = Y[0] + (Y[1] - Y[0]) * (reference.X[0] - X[0]) / (X[1] - X[0]);
X[0] = reference.X[0];
}
else
{
X.RemoveAt(0);
Y.RemoveAt(0);
}
}
while (X.Count > 0 && X[X.Count - 1] >= reference.X[reference.Count - 1])
{
if (X.Count > 1 && X[X.Count - 2] < reference.X[reference.Count - 1])
{
Y[Y.Count - 1] = Y[Y.Count - 1] - (Y[Y.Count - 1] - Y[Y.Count - 2]) * (X[X.Count - 1] - reference.X[reference.Count - 1]) / (X[X.Count - 1] - X[X.Count - 2]);
X[X.Count - 1] = reference.X[reference.Count - 1];
}
else
{
X.RemoveAt(X.Count - 1);
Y.RemoveAt(Y.Count - 1);
}
}

}
}
}

0 comments on commit c4a1820

Please sign in to comment.