diff --git a/Modelica_ResultCompare/CurveCompare/Algorithms/Rectangle.cs b/Modelica_ResultCompare/CurveCompare/Algorithms/Rectangle.cs index ae5d28c..999b41b 100644 --- a/Modelica_ResultCompare/CurveCompare/Algorithms/Rectangle.cs +++ b/Modelica_ResultCompare/CurveCompare/Algorithms/Rectangle.cs @@ -4,8 +4,6 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; // for visualization with ChartControl #if GUI @@ -64,7 +62,6 @@ public override TubeReport Calculate(Curve reference, TubeSize size) /// Lower tube curve. private static Curve CalculateLower(Curve reference, TubeSize size) { - Curve lower; // lower tube curve List LX = new List(2 * reference.Count); // x-values of lower tube curve List LY = new List(2 * reference.Count); // y-values of lower tube curve @@ -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); @@ -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()); } /// @@ -221,7 +217,6 @@ private static Curve CalculateLower(Curve reference, TubeSize size) /// Upper tube curve. private static Curve CalculateUpper(Curve reference, TubeSize size) { - Curve upper; // upper tube curve List UX = new List(2 * reference.Count); // x-values of upper tube curve List UY = new List(2 * reference.Count); // y-values of upper tube curve @@ -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()); } /// /// Remove points and add intersection points in case of backward order @@ -376,7 +371,7 @@ private static Curve CalculateUpper(Curve reference, TubeSize size) /// if true, algorithm for lower tube curve is used; /// if false, algorithm for upper tube curve is used /// Number of loops, that are removed. - private static int removeLoop(List X, List Y, bool lower) + private static int RemoveLoop(List X, List Y, bool lower) { // Visualization of working of removeLoop #if GUI @@ -555,5 +550,41 @@ private static int removeLoop(List X, List Y, bool lower) #endif return countLoops; } + /// + /// Fix the boundary values of the tube curve. + /// + /// x values of curve + /// y values of curve + /// Reference curve. + private static void FixBoundaries(List X, List 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); + } + } + + } } }