/// <summary> /// Check passability of the parcel via given corner. /// </summary> /// <param name="parcel">The size of parcel</param> /// <param name="corner">Corner parameters</param> /// <returns>Whether parcel could pass the pipeline elbow</returns> public bool IsSuitableCorner(ParcelSize parcel, PipeCorner corner) { double width = parcel.Width; double length = parcel.Length; var inlet = corner.Inlet; var outlet = corner.Outlet; if (width > inlet || width > outlet) { return(false); } if (corner.Inlet == corner.Outlet) { var side = corner.Inlet; var hypotenuse = Math.Sqrt(side * side * 2); return(width < hypotenuse - length / 2); } var maxSuitableLength = Math.Sqrt(inlet * inlet + width * width) + Math.Sqrt(outlet * outlet + width * width); return(length < maxSuitableLength); }
private static List <bool> ProcessValues(string[] values) { if (values == null) { throw new ArgumentNullException(); } if (values.Length < Constants.Dimensions.ParcelDimensionCount + Constants.Dimensions.CornerDimensionCount) { throw new ArgumentException("Insufficient arguments"); } var parcelSize = new ParcelSize { Length = int.Parse(values[0]), Width = int.Parse(values[1]) }; var inspector = new CornerInspector(); var pipeCorners = inspector.ParseCorners(values); return(inspector.InspectPipeCorners(parcelSize, pipeCorners)); }
/// <summary> /// Inspect every given corner in the list of <paramref name="corners"/> /// in appliance to the size of <paramref name="parcel"/> /// </summary> /// <param name="parcel">Size of parcel</param> /// <param name="corners">List of corner dimensions</param> /// <returns>The array of boolean results for each corner</returns> public List <bool> InspectPipeCorners(ParcelSize parcel, List <PipeCorner> corners) { var firstElbow = corners.FirstOrDefault(); if (_calc.IsSuitableCorner(parcel, firstElbow)) { return(corners .Select(x => _calc.IsSuitableCorner(parcel, x)) .ToList()); } var len = parcel.Length; var wid = parcel.Width; parcel.Length = wid; parcel.Width = len; return(corners .Select(x => _calc.IsSuitableCorner(parcel, x)) .ToList()); }