public bool IsWithinCleanZone(double orbit) { if (FormationZones.Any(o => o.WithinRange(orbit))) { return(true); } //Epistellar check. return(orbit < CreationRange.LowerBound && !IsWithinForbiddenZone(orbit)); }
//check -range- function. public double VerifyRange(Range checkRange) { double rangeAvail = 1; var currentPos = checkRange.LowerBound; //escape hatch for this condition if (ForbiddenZones.Count == 0) { return(1); } //Which is.. wat? Still, fixed. if (FormationZones.Any(o => checkRange.LowerBound >= o.LowerBound && checkRange.UpperBound <= o.UpperBound)) { return(1); } foreach (var o in ForbiddenZones) { //CASE 1: The forbidden zone is between here and the end if ((currentPos < checkRange.UpperBound) && (currentPos < o.LowerBound) && (o.UpperBound <= checkRange.UpperBound)) { rangeAvail = rangeAvail - (o.UpperBound - o.LowerBound) / checkRange.Length; if (Math.Abs(rangeAvail) < 0) { return(rangeAvail); } currentPos = o.UpperBound; } //CASE 2: This is within a forbidden zone if ((checkRange.LowerBound >= o.LowerBound) && (checkRange.UpperBound <= o.UpperBound)) { return(0); } //CASE 3: Current Position is within a forbidden zone and it cotnains the end. if ((currentPos < checkRange.UpperBound) && (currentPos > o.LowerBound) && (checkRange.UpperBound <= o.UpperBound)) { rangeAvail = rangeAvail - (o.UpperBound - currentPos) / checkRange.Length; if (Math.Abs(rangeAvail) < 0) { return(rangeAvail); } currentPos = checkRange.UpperBound; } //CASE 4: Current Position is within a forbidden zone and it does not contain the end. if ((currentPos < checkRange.UpperBound) && (currentPos > o.LowerBound) && (checkRange.UpperBound > o.UpperBound)) { rangeAvail = rangeAvail - (o.UpperBound - currentPos) / checkRange.Length; if (rangeAvail == 0) { return(rangeAvail); } currentPos = o.UpperBound; } //CASE 5: The end is within a forbidden zone but the current position is not if (!(currentPos < checkRange.UpperBound) || !(currentPos < o.LowerBound) || !(checkRange.UpperBound >= o.LowerBound) || !(checkRange.UpperBound < o.UpperBound)) { continue; } rangeAvail = rangeAvail - (checkRange.UpperBound - o.LowerBound) / checkRange.Length; if (rangeAvail == 0) { return(rangeAvail); } currentPos = checkRange.UpperBound; //CASE 6: No IF condition if the forbidden zone is entirely to the left or right. } if (rangeAvail >= 0 && rangeAvail <= 1) { return(rangeAvail); } throw new Exception("RangeAvail is " + rangeAvail + " and exceeds 0-100%."); }