//  private Rectangle inset(Rectangle r) {
        //    //typically inset by 1 (whole numbers are easy to read)
        //    double d = Math.min(1.0, grid.getDistanceForLevel(grid.getMaxLevels()) / 4);
        //    return ctx.makeRectangle(r.getMinX() + d, r.getMaxX() - d, r.getMinY() + d, r.getMaxY() - d);
        //  }

        protected IShape gridSnap(IShape snapMe)
        {
            if (snapMe == null)
            {
                return(null);
            }
            if (snapMe is ShapePair)
            {
                ShapePair me = (ShapePair)snapMe;
                return(new ShapePair(gridSnap(me.shape1), gridSnap(me.shape2), me.biasContainsThenWithin, ctx));
            }
            if (snapMe is IPoint)
            {
                snapMe = snapMe.BoundingBox;
            }
            //The next 4 lines mimic PrefixTreeStrategy.createIndexableFields()
            double       distErrPct  = ((PrefixTreeStrategy)strategy).DistErrPct;
            double       distErr     = SpatialArgs.CalcDistanceFromErrPct(snapMe, distErrPct, ctx);
            int          detailLevel = grid.GetLevelForDistance(distErr);
            IList <Cell> cells       = grid.GetCells(snapMe, detailLevel, false, true);

            //calc bounding box of cells.
            List <IShape> cellShapes = new List <IShape>(cells.size());

            foreach (Cell cell in cells)
            {
                cellShapes.Add(cell.Shape);
            }
            return(new ShapeCollection(cellShapes, ctx).BoundingBox);
        }
Ejemplo n.º 2
0
        public void TestShapePair()
        {
            ctx = SpatialContext.Geo;
            SetupCtx2D(ctx);

            IShape leftShape  = new ShapePair(ctx.MakeRectangle(-74, -56, -8, 1), ctx.MakeRectangle(-180, 134, -90, 90), true, ctx, ctx2D);
            IShape queryShape = ctx.MakeRectangle(-180, 180, -90, 90);

            assertEquals(SpatialRelation.Within, leftShape.Relate(queryShape));
        }