private static List<BoreSection> ParsePositionAndRadiusDimensions(string dimensionString) { List<BoreSection> boreSections; List<PositionAndRadius> dimensions = new List<PositionAndRadius>(); int lineNumber = 0; decimal previousPosition = 0; foreach (string dimensionLine in dimensionString.Replace('\r', '\n').Replace("\n\n", "\n").Split('\n')) { string line = dimensionLine.Trim(); //ignore blank lines if (line.Length == 0) continue; PositionAndRadius positionAndRadius; try { positionAndRadius = new PositionAndRadius(line); } catch (ValidationException ex) { throw new ValidationException("Line {0}: \"{1}\" - {2}", lineNumber, line, ex.Message); } if (positionAndRadius.Position < previousPosition) throw new ValidationException("Line {0}: \"{1}\" - The position \"{2}\" must be greater than or equal to the previous position \"{3}\"", lineNumber, line, positionAndRadius.Position, previousPosition); previousPosition = positionAndRadius.Position; if (positionAndRadius.Radius == 0) throw new ValidationException("Line {0}: \"{1}\" - The radius cannot be 0", lineNumber, line); dimensions.Add(positionAndRadius); lineNumber++; } if (dimensions.Count == 1) throw new ValidationException("There must be at least 2 dimensions entered"); boreSections = new List<BoreSection>(); for (int i = 0; i < dimensions.Count - 1; i++) { if (dimensions[i + 1].Position > dimensions[i].Position) { BoreSection boreSection = new BoreSection(dimensions[i].Radius, dimensions[i + 1].Radius, (dimensions[i + 1].Position - dimensions[i].Position)); boreSections.Add(boreSection); } } return boreSections; }
private static List<BoreSection> ParseRadiusAndLengthDimensions(string dimensionString) { List<BoreSection> boreSections = new List<BoreSection>(); if (dimensionString.Trim().Length == 0) return boreSections; List<RadiusAndLength> dimensions = new List<RadiusAndLength>(); int lineNumber = 0; bool foundLastLine = false; foreach (string dimensionLine in dimensionString.Replace('\r', '\n').Replace("\n\n", "\n").Split('\n')) { string line = dimensionLine.Trim(); //ignore blank lines if (line.Length == 0) continue; if (foundLastLine) throw new ValidationException("Line {0}: \"{1}\" - Not expecting another line. You probably didn't put a length value on the previous line", lineNumber, line); RadiusAndLength radiusAndLength; try { radiusAndLength = new RadiusAndLength(line); } catch (ValidationException ex) { throw new ValidationException("Line {0}: \"{1}\" - {2}", lineNumber, line, ex.Message); } if (radiusAndLength.Length == -1) foundLastLine = true; if (radiusAndLength.Radius == 0) throw new ValidationException("Line {0}: \"{1}\" - The radius cannot be 0", lineNumber, line); dimensions.Add(radiusAndLength); lineNumber++; } if (dimensions.Count == 1) throw new ValidationException("There must be at least 2 lines. The last line must contain a single number, which is the radius at the end of the bore"); if (dimensions[dimensions.Count - 1].Length != -1) throw new ValidationException("The last line cannot contain a length value. It must be a single number, which is the radius at the end of the bore"); boreSections = new List<BoreSection>(); for (int i = 1; i < dimensions.Count; i++) { BoreSection boreSection = new BoreSection(dimensions[i - 1].Radius, dimensions[i].Radius, dimensions[i - 1].Length); boreSections.Add(boreSection); } return boreSections; }
public BoreSectionCalculations(BoreSection boreSection) : base(boreSection.OpeningRadius, boreSection.ClosingRadius, boreSection.Length) { if (!IsCylindrical) { double temp = Math.Sqrt(Math.Pow((double)(Length / (ClosingRadius - OpeningRadius)), 2) + 1); inputXi = (double)OpeningRadius * temp; outputXi = (double)ClosingRadius * temp; sphericalLength = outputXi - inputXi; sphericalArea = Math.PI * Math.Pow(inputXi, 2) * 2 * (1 - (Math.Sqrt(1 - Math.Pow((double)OpeningRadius / inputXi, 2)))); } else { sphericalLength = (double)this.length; sphericalArea = Math.PI * Math.Pow((double)openingRadius, 2); } averageRadius = (double)((openingRadius + closingRadius) / 2.0m); sphericalAreaTimesAverageRadius = sphericalArea * averageRadius; }