/// <summary> /// Calculates the time range covering all the cell passes within the given sub grid segment /// </summary> /// <param name="segment"></param> /// <param name="startTime"></param> /// <param name="endTime"></param> public static void CalculateTimeRange(ISubGridCellSegmentPassesDataWrapper segment, out DateTime startTime, out DateTime endTime) { startTime = Consts.MAX_DATETIME_AS_UTC; endTime = Consts.MIN_DATETIME_AS_UTC; for (int i = 0; i < SubGridTreeConsts.SubGridTreeDimension; i++) { for (int j = 0; j < SubGridTreeConsts.SubGridTreeDimension; j++) { int ThePassCount = segment.PassCount(i, j); if (ThePassCount == 0) { continue; } for (int PassIndex = 0; PassIndex < ThePassCount; PassIndex++) { var theTime = segment.PassTime(i, j, PassIndex); if (theTime > endTime) { endTime = theTime; } if (theTime < startTime) { startTime = theTime; } } } } }
/// <summary> /// Calculate the total number of passes from all the cells present in the given sub grid segment /// </summary> /// <param name="segment"></param> /// <param name="TotalPasses"></param> /// <param name="MinPassCount"></param> /// <param name="MaxPassCount"></param> public static void CalculateTotalPasses(ISubGridCellSegmentPassesDataWrapper segment, out int TotalPasses, out int MinPassCount, out int MaxPassCount) { TotalPasses = 0; MaxPassCount = 0; MinPassCount = int.MaxValue; // Todo: Push this down to the segment to avoid the PassCount abstraction if (segment.HasPassData()) { for (int i = 0; i < SubGridTreeConsts.SubGridTreeDimension; i++) { for (int j = 0; j < SubGridTreeConsts.SubGridTreeDimension; j++) { int ThePassCount = segment.PassCount(i, j); if (ThePassCount > MaxPassCount) { MaxPassCount = ThePassCount; } if (ThePassCount < MinPassCount) { MinPassCount = ThePassCount; } TotalPasses += ThePassCount; } } } }
/// <summary> /// Calculates the elevation range that all the passes within the given segment span. /// </summary> /// <param name="segment"></param> /// <param name="minElevation"></param> /// <param name="maxElevation"></param> /// <returns>True if the result of the calculation yields a valid elevation range</returns> public static bool CalculateElevationRangeOfPasses(ISubGridCellSegmentPassesDataWrapper segment, out double minElevation, out double maxElevation) { minElevation = 1E10; maxElevation = -1E10; double min = minElevation; double max = maxElevation; for (int i = 0; i < SubGridTreeConsts.SubGridTreeDimension; i++) { for (int j = 0; j < SubGridTreeConsts.SubGridTreeDimension; j++) { int _PassCount = segment.PassCount(i, j); for (int PassIndex = 0; PassIndex < _PassCount; PassIndex++) { // Todo: Delegate this down to the segment to avoid the PassHeight() abstraction float _height = segment.PassHeight(i, j, PassIndex); if (_height > max) { max = _height; } if (_height < min) { min = _height; } } } } if (min <= max) { minElevation = min; maxElevation = max; } return(minElevation <= maxElevation); }
/// <summary> /// Calculates the number of passes in the segment that occur before searchTime /// </summary> /// <param name="segment"></param> /// <param name="searchTime"></param> /// <param name="totalPasses"></param> /// <param name="maxPassCount"></param> public static void CalculatePassesBeforeTime(ISubGridCellSegmentPassesDataWrapper segment, DateTime searchTime, out int totalPasses, out int maxPassCount) { totalPasses = 0; maxPassCount = 0; for (int i = 0; i < SubGridTreeConsts.SubGridTreeDimension; i++) { for (int j = 0; j < SubGridTreeConsts.SubGridTreeDimension; j++) { int thePassCount = segment.PassCount(i, j); if (thePassCount == 0) { continue; } int countInCell = 0; for (int PassIndex = 0; PassIndex < thePassCount; PassIndex++) { var theTime = segment.PassTime(i, j, PassIndex); if (theTime < searchTime) { countInCell++; } } totalPasses += countInCell; if (countInCell > maxPassCount) { maxPassCount = countInCell; } } } }