/// <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> /// Causes segment to adopt all cell passes from sourceSegment where those cell passes were /// recorded at or later than a specific date /// </summary> /// <param name="segment"></param> /// <param name="sourceSegment"></param> /// <param name="atAndAfterTime"></param> public static void AdoptCellPassesFrom(ISubGridCellSegmentPassesDataWrapper segment, ISubGridCellSegmentPassesDataWrapper sourceSegment, DateTime atAndAfterTime) { Core.Utilities.SubGridUtilities.SubGridDimensionalIterator((i, j) => { var sourceSegmentPasses = sourceSegment.ExtractCellPasses(i, j); var passes = sourceSegmentPasses.Passes; if (passes.Count == 0) { return; } var countInCell = 0; var elements = passes.Elements; for (int cpi = passes.Offset, limit = passes.OffsetPlusCount; cpi < limit; cpi++) { if (elements[cpi].Time < atAndAfterTime) { countInCell++; } else { break; // No more passes in the cell will satisfy the condition } } // countInCell represents the number of cells that should remain in the source segment. // The remainder are to be moved to this segment var adoptedPassCount = passes.Count - countInCell; if (adoptedPassCount > 0) { segment.Integrate(i, j, sourceSegmentPasses, countInCell, passes.Count - 1, out var addedCount, out _); segment.SegmentPassCount += addedCount; sourceSegment.SegmentPassCount -= adoptedPassCount; sourceSegment.TrimPassCount(i, j, countInCell); } }); }
/// <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; } } } }
/// <summary> /// Causes this segment to adopt all cell passes from sourceSegment where those cell passes were /// recorded at or later than a specific date /// </summary> /// <param name="sourceSegment"></param> /// <param name="atAndAfterTime"></param> public void AdoptCellPassesFrom(ISubGridCellSegmentPassesDataWrapper sourceSegment, DateTime atAndAfterTime) { SegmentCellPassAdopter.AdoptCellPassesFrom(this, sourceSegment, atAndAfterTime); }
public SubGridCellPassesDataSegment(ISubGridCellLatestPassDataWrapper latestPasses, ISubGridCellSegmentPassesDataWrapper passesData) { LatestPasses = latestPasses; PassesData = passesData; }