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 23, 2024
1 parent f3c399e commit 841c1a2
Showing 1 changed file with 28 additions and 20 deletions.
48 changes: 28 additions & 20 deletions Modelica_ResultCompare/CurveCompare/Algorithms/Rectangle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,27 +204,31 @@ private static Curve CalculateLower(Curve reference, TubeSize size)
// -------------------------------------------------------------------------------------------------------------

RemoveLoop(LX, LY, true);
while (LX.Count > 0 && LX[0] <= reference.X[0])
{
double minY = reference.Y[0] - size.Y;
while (LX.Count > 0 && LX[0] <= reference.X[0])
if (LX.Count > 1 && LX[1] > reference.X[0])
{
LY[0] = LY[0] + (LY[1] - LY[0]) * (reference.X[0] - LX[0]) / (LX[1] - LX[0]);
LX[0] = reference.X[0];
}
else
{
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] >= reference.X[reference.Count - 1])
{
double minY = reference.Y[reference.Count - 1] - size.Y;
while (LX.Count > 0 && LX[LX.Count - 1] >= reference.X[reference.Count - 1])
if (LX.Count > 1 && LX[LX.Count - 2] < reference.X[reference.Count - 1])
{
LY[LY.Count - 1] = LY[LY.Count - 1] - (LY[LY.Count - 1] - LY[LY.Count - 2]) * (LX[LX.Count - 1] - reference.X[reference.Count - 1]) / (LX[LX.Count - 1] - LX[LX.Count - 2]);
LX[LX.Count - 1] = reference.X[reference.Count - 1];
}
else
{
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 Down Expand Up @@ -380,27 +384,31 @@ private static Curve CalculateUpper(Curve reference, TubeSize size)
// ---------------------------------------------------------------------------------------------------------

RemoveLoop(UX, UY, false);
while (UX.Count > 0 && UX[0] <= reference.X[0] + size.X)
{
double maxY = reference.Y[0] + size.Y;
while (UX.Count > 0 && UX[0] <= reference.X[0])
if (UX.Count > 1 && UX[1] > reference.X[0] + size.X)
{
UY[0] = UY[0] + (UY[1] - UY[0]) * (reference.X[0] + size.X - UX[0]) / (UX[1] - UX[0]);
UX[0] = reference.X[0] + size.X;
}
else
{
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] >= reference.X[reference.Count - 1])
{
double maxY = reference.Y[reference.Count - 1] + size.Y;
while (UX.Count > 0 && UX[UX.Count - 1] >= reference.X[reference.Count - 1])
if (UX.Count > 1 && UX[UX.Count - 2] < reference.X[reference.Count - 1])
{
UY[UY.Count - 1] = UY[UY.Count - 1] - (UY[UY.Count - 1] - UY[UY.Count - 2]) * (UX[UX.Count - 1] - reference.X[reference.Count - 1]) / (UX[UX.Count - 1] - UX[UX.Count - 2]);
UX[UX.Count - 1] = reference.X[reference.Count - 1];
}
else
{
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

0 comments on commit 841c1a2

Please sign in to comment.