public ZoneInfoGrid(int zoneWidthAndHeight, ILandValueCalculator landValueCalculator)
        {
            ZoneWidthAndHeight = zoneWidthAndHeight;
            ZoneInfos          = (from x in Enumerable.Range(0, zoneWidthAndHeight)
                                  from y in Enumerable.Range(0, zoneWidthAndHeight)
                                  let localX = x
                                               let localY = y
                                                            select new ZoneInfo(
                                      zonePoint: new ZonePoint
            {
                X = localX,
                Y = localY
            },
                                      getRelativeZoneInfo: (query) =>
            {
                var point = new ZonePoint
                {
                    X = (localX + query.RelativeX),
                    Y = (localY + query.RelativeY)
                };

                ZoneInfo matchingZoneInfo;
                if (ZoneInfos.TryGetValue(point, out matchingZoneInfo))
                {
                    return(new QueryResult <IZoneInfo, RelativeZoneInfoQuery>(query, matchingZoneInfo));
                }
                return(new QueryResult <IZoneInfo, RelativeZoneInfoQuery>(query));
            },
                                      landValueCalculator: landValueCalculator
                                      )
                                  ).ToDictionary(x => x.Point, x => x);
        }
        public static Orientation OrientationTo(this ZonePoint x, ZonePoint y)
        {
            Orientation?orientation = null;

            if (x.X < y.X)
            {
                orientation = Orientation.East;
            }
            if (x.X > y.X)
            {
                orientation = orientation ^ Orientation.West ?? Orientation.West;
            }
            if (x.Y > y.Y)
            {
                orientation = orientation ^ Orientation.North ?? Orientation.North;
            }
            if (x.Y < y.Y)
            {
                orientation = orientation ^ Orientation.South ?? Orientation.South;
            }

            if (orientation.HasValue)
            {
                return(orientation.Value);
            }

            throw new InvalidOperationException();
        }
Beispiel #3
0
 public ZoneInfo(
     ZonePoint zonePoint,
     GetRelativeZoneInfoDelegate getRelativeZoneInfo,
     ILandValueCalculator landValueCalculator
     )
 {
     Point = zonePoint;
     _getRelativeZoneInfo = getRelativeZoneInfo ?? throw new ArgumentNullException(nameof(getRelativeZoneInfo));
     _landValueCalculator = landValueCalculator ?? throw new ArgumentNullException(nameof(landValueCalculator));
 }
 public ZoneInfoSnapshot(
     ZonePoint point,
     IAreaZoneConsumption areaZoneConsumption,
     Func <IEnumerable <QueryResult <IZoneInfo, RelativeZoneInfoQuery> > > getNorthEastSouthWestFunc,
     TrafficDensity trafficDensity)
 {
     Point = point;
     AreaZoneConsumption        = areaZoneConsumption;
     _getNorthEastSouthWestFunc = getNorthEastSouthWestFunc;
     TrafficDensity             = trafficDensity;
 }
Beispiel #5
0
        public ZoneInfo(
            ZonePoint zonePoint,
            GetRelativeZoneInfoDelegate getRelativeZoneInfo,
            ILandValueCalculator landValueCalculator
            )
        {
            if (zonePoint == null)
            {
                throw new ArgumentNullException(nameof(zonePoint));
            }
            if (getRelativeZoneInfo == null)
            {
                throw new ArgumentNullException(nameof(getRelativeZoneInfo));
            }
            if (landValueCalculator == null)
            {
                throw new ArgumentNullException(nameof(landValueCalculator));
            }

            Point = zonePoint;
            _getRelativeZoneInfo = getRelativeZoneInfo;
            _landValueCalculator = landValueCalculator;
        }
 public static QueryResult <ZoneInfo> GetZoneInfoOn(this ZonePoint zonePoint, Area area)
 {
     return(QueryResult <ZoneInfo> .Create(area.EnumerateZoneInfos().Single(x => x.Point == zonePoint)));
 }