Beispiel #1
0
        protected void Init(DistanceUnits units, DistanceCalculator calculator, Rectangle worldBounds)
        {
            if (units == null)
                throw new ArgumentException("units can't be null", "units");

            this.units = units;

            if (calculator == null)
            {
                calculator = IsGeo()
                    ? (DistanceCalculator)new GeodesicSphereDistCalc.Haversine(units.EarthRadius())
                    : new CartesianDistCalc();
            }
            this.calculator = calculator;

            if (worldBounds == null)
            {
                worldBounds = IsGeo() ? GEO_WORLDBOUNDS : MAX_WORLDBOUNDS;
            }
            else
            {
                if (IsGeo())
                    Debug.Assert(new RectangleImpl(worldBounds).Equals(GEO_WORLDBOUNDS));
                if (worldBounds.GetCrossesDateLine())
                    throw new ArgumentException("worldBounds shouldn't cross dateline: " + worldBounds, "worldBounds");
            }
            //copy so we can ensure we have the right implementation
            worldBounds = MakeRect(worldBounds.GetMinX(), worldBounds.GetMaxX(), worldBounds.GetMinY(), worldBounds.GetMaxY());
            this.worldBounds = worldBounds;

            shapeReadWriter = MakeShapeReadWriter();

            this.maxCircleDistance = IsGeo() ? calculator.DegreesToDistance(180) : (double?)null;
        }