// Returns true if the given point is contained by the buffered region, // i.e. if it is within the given radius of any original shape. public bool Contains(S2Point p) { var target = new S2ClosestEdgeQuery.PointTarget(p); // Return true if the distance is less than or equal to "radius_". return(query_.IsDistanceLess(target, radius_successor_)); }
// The implementation is approximate but conservative; it always returns // "false" if the cell is not contained by the buffered region, but it may // also return false in some cases where "cell" is in fact contained. public bool Contains(S2Cell cell) { // Return true if the buffered region is guaranteed to cover whole globe. if (radius_successor_ > S1ChordAngle.Straight) { return(true); } // To implement this method perfectly would require computing the directed // Hausdorff distance, which is expensive (and not currently implemented). // However the following heuristic is almost as good in practice and much // cheaper to compute. // Return true if the unbuffered region contains this cell. if (Index().MakeS2ShapeIndexRegion().Contains(cell)) { return(true); } // Otherwise approximate the cell by its bounding cap. // // NOTE(ericv): It would be slightly more accurate to first find the closest // point in the indexed geometry to the cell, and then measure the actual // maximum distance from that point to the cell (a poor man's Hausdorff // distance). But based on actual tests this is not worthwhile. S2Cap cap = cell.GetCapBound(); if (Radius < cap.Radius) { return(false); } // Return true if the distance to the cell center plus the radius of the // cell's bounding cap is less than or equal to "radius_". var target = new S2ClosestEdgeQuery.PointTarget(cell.Center()); return(query_.IsDistanceLess(target, radius_successor_ - cap.Radius)); }