public static IEnumerable <ZoneClusterMemberConsumption> Generate(BaseZoneClusterConsumption parent, Func <ZoneInfoFinder> createZoneInfoFinderFunc, int widthInZones, int heightInZones, Color color) { if (widthInZones <= 1) { throw new ArgumentOutOfRangeException(nameof(widthInZones)); } if (heightInZones <= 1) { throw new ArgumentOutOfRangeException(nameof(heightInZones)); } int zeroBasedWidth = widthInZones - 1; int zeroBasedHeight = heightInZones - 1; int widthOffset = zeroBasedWidth / 2; int heightOffset = zeroBasedHeight / 2; return (from widthIndex in Enumerable.Range(0, widthInZones) from heightIndex in Enumerable.Range(0, heightInZones) select new ZoneClusterMemberConsumption( createZoneInfoFinderFunc: createZoneInfoFinderFunc, parentBaseZoneClusterConsumption: parent, name: parent.Name, relativeToParentCenterX: (widthIndex - widthOffset), relativeToParentCenterY: (heightIndex - heightOffset), positionInClusterX: widthIndex + 1, positionInClusterY: heightIndex + 1, color: color )); }
public ZoneClusterMemberConsumption( BaseZoneClusterConsumption parentBaseZoneClusterConsumption, Func <ZoneInfoFinder> createZoneInfoFinderFunc, string name, int relativeToParentCenterX, int relativeToParentCenterY, Color color, int positionInClusterX, int positionInClusterY ) { if (name == null) { throw new ArgumentNullException(nameof(name)); } if (parentBaseZoneClusterConsumption == null) { throw new ArgumentNullException(nameof(parentBaseZoneClusterConsumption)); } ParentBaseZoneClusterConsumption = parentBaseZoneClusterConsumption; Name = name; RelativeToParentCenterX = relativeToParentCenterX; RelativeToParentCenterY = relativeToParentCenterY; Color = color; PositionInClusterX = positionInClusterX; PositionInClusterY = positionInClusterY; _zoneInfoFinder = createZoneInfoFinderFunc(); PositionInCluster = new Point(PositionInClusterX - 1, PositionInClusterY - 1); }