diff --git a/go.mod b/go.mod index e59b4c3a7..41096000d 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/Nerzal/gocloak/v13 v13.9.0 github.com/bbalet/stopwords v1.0.0 github.com/beevik/etree v1.5.1 - github.com/blevesearch/bleve/v2 v2.5.2 + github.com/blevesearch/bleve/v2 v2.5.3 github.com/cenkalti/backoff v2.2.1+incompatible github.com/coreos/go-oidc/v3 v3.15.0 github.com/cs3org/go-cs3apis v0.0.0-20250725064958-2d9caef4db2a @@ -140,7 +140,7 @@ require ( github.com/bitly/go-simplejson v0.5.0 // indirect github.com/bits-and-blooms/bitset v1.22.0 // indirect github.com/blevesearch/bleve_index_api v1.2.8 // indirect - github.com/blevesearch/geo v0.2.3 // indirect + github.com/blevesearch/geo v0.2.4 // indirect github.com/blevesearch/go-faiss v1.0.25 // indirect github.com/blevesearch/go-porterstemmer v1.0.3 // indirect github.com/blevesearch/gtreap v0.1.1 // indirect diff --git a/go.sum b/go.sum index 04eddbc68..b364e89b1 100644 --- a/go.sum +++ b/go.sum @@ -151,12 +151,12 @@ github.com/bits-and-blooms/bitset v1.12.0/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6 github.com/bits-and-blooms/bitset v1.22.0 h1:Tquv9S8+SGaS3EhyA+up3FXzmkhxPGjQQCkcs2uw7w4= github.com/bits-and-blooms/bitset v1.22.0/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8= github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84= -github.com/blevesearch/bleve/v2 v2.5.2 h1:Ab0r0MODV2C5A6BEL87GqLBySqp/s9xFgceCju6BQk8= -github.com/blevesearch/bleve/v2 v2.5.2/go.mod h1:5Dj6dUQxZM6aqYT3eutTD/GpWKGFSsV8f7LDidFbwXo= +github.com/blevesearch/bleve/v2 v2.5.3 h1:9l1xtKaETv64SZc1jc4Sy0N804laSa/LeMbYddq1YEM= +github.com/blevesearch/bleve/v2 v2.5.3/go.mod h1:Z/e8aWjiq8HeX+nW8qROSxiE0830yQA071dwR3yoMzw= github.com/blevesearch/bleve_index_api v1.2.8 h1:Y98Pu5/MdlkRyLM0qDHostYo7i+Vv1cDNhqTeR4Sy6Y= github.com/blevesearch/bleve_index_api v1.2.8/go.mod h1:rKQDl4u51uwafZxFrPD1R7xFOwKnzZW7s/LSeK4lgo0= -github.com/blevesearch/geo v0.2.3 h1:K9/vbGI9ehlXdxjxDRJtoAMt7zGAsMIzc6n8zWcwnhg= -github.com/blevesearch/geo v0.2.3/go.mod h1:K56Q33AzXt2YExVHGObtmRSFYZKYGv0JEN5mdacJJR8= +github.com/blevesearch/geo v0.2.4 h1:ECIGQhw+QALCZaDcogRTNSJYQXRtC8/m8IKiA706cqk= +github.com/blevesearch/geo v0.2.4/go.mod h1:K56Q33AzXt2YExVHGObtmRSFYZKYGv0JEN5mdacJJR8= github.com/blevesearch/go-faiss v1.0.25 h1:lel1rkOUGbT1CJ0YgzKwC7k+XH0XVBHnCVWahdCXk4U= github.com/blevesearch/go-faiss v1.0.25/go.mod h1:OMGQwOaRRYxrmeNdMrXJPvVx8gBnvE5RYrr0BahNnkk= github.com/blevesearch/go-porterstemmer v1.0.3 h1:GtmsqID0aZdCSNiY8SkuPJ12pD4jI+DdXTAn4YRcHCo= diff --git a/vendor/github.com/blevesearch/geo/geojson/geojson_s2_util.go b/vendor/github.com/blevesearch/geo/geojson/geojson_s2_util.go index 5c5806431..91ad975e3 100644 --- a/vendor/github.com/blevesearch/geo/geojson/geojson_s2_util.go +++ b/vendor/github.com/blevesearch/geo/geojson/geojson_s2_util.go @@ -25,19 +25,6 @@ import ( // ------------------------------------------------------------------------ -// creates a shape index with all of the given polygons -// and queries it with vertex model closed which considers -// polygon edges and vertices to be part of the polygon. -func polygonsContainsPoint(s2pgns []*s2.Polygon, - point *s2.Point) bool { - idx := s2.NewShapeIndex() - for _, s2pgn := range s2pgns { - idx.Add(s2pgn) - } - - return s2.NewContainsPointQuery(idx, s2.VertexModelClosed).Contains(*point) -} - // project the point to all of the linestrings and check if // any of the projections are equal to the point. func polylineIntersectsPoint(pls []*s2.Polyline, @@ -66,6 +53,21 @@ func polylineIntersectsPolygons(pls []*s2.Polyline, containsQuery := s2.NewContainsPointQuery(idx, s2.VertexModelClosed) for _, pl := range pls { for _, point := range *pl { + + // Precheck points within the bounds of the polygon + // and for small polygons, check if the point is contained + for _, s2pgn := range s2pgns { + if !s2pgn.PointWithinBound(point) { + continue + } + + if small, inside := s2pgn.SmallPolygonContainsPoint(point); small { + if inside { + return true + } + } + } + if containsQuery.Contains(point) { return true } @@ -95,12 +97,29 @@ func polylineIntersectsPolygons(pls []*s2.Polyline, // so we create a shape index and query it instead // s2.VertexModelClosed will not consider points on the edges, so // behaviour there is arbitrary -func polygonIntersectsPoint(s2pgns []*s2.Polygon, +func polygonsIntersectsPoint(s2pgns []*s2.Polygon, point *s2.Point) bool { idx := s2.NewShapeIndex() for _, pgn := range s2pgns { + if !pgn.PointWithinBound(*point) { + continue + } + + // We don't early exit here because the point may be contained + // on the vertices of the polygon, which is not considered + if small, inside := pgn.SmallPolygonContainsPoint(*point); small { + if inside { + return true + } + } + idx.Add(pgn) } + + if idx.Len() == 0 { + return false + } + return s2.NewContainsPointQuery(idx, s2.VertexModelClosed).Contains(*point) } diff --git a/vendor/github.com/blevesearch/geo/geojson/geojson_shapes_impl.go b/vendor/github.com/blevesearch/geo/geojson/geojson_shapes_impl.go index 38751abfc..7d8e09673 100644 --- a/vendor/github.com/blevesearch/geo/geojson/geojson_shapes_impl.go +++ b/vendor/github.com/blevesearch/geo/geojson/geojson_shapes_impl.go @@ -933,7 +933,7 @@ func checkPointIntersectsShape(point *s2.Point, shapeIn, other index.GeoJSON) (b // check if the other shape is a polygon. if p2, ok := other.(*Polygon); ok { // check if the point is contained within the polygon. - if polygonsContainsPoint([]*s2.Polygon{p2.s2pgn}, point) { + if polygonsIntersectsPoint([]*s2.Polygon{p2.s2pgn}, point) { return true, nil } @@ -943,7 +943,7 @@ func checkPointIntersectsShape(point *s2.Point, shapeIn, other index.GeoJSON) (b // check if the other shape is a multipolygon. if p2, ok := other.(*MultiPolygon); ok { // check if the point is contained within any of the polygons - if polygonsContainsPoint(p2.s2pgns, point) { + if polygonsIntersectsPoint(p2.s2pgns, point) { return true, nil } @@ -1195,7 +1195,7 @@ func checkPolygonIntersectsShape(s2pgn *s2.Polygon, shapeIn, other index.GeoJSON) (bool, error) { // check if the other shape is a point. if p2, ok := other.(*Point); ok { - if polygonIntersectsPoint([]*s2.Polygon{s2pgn}, p2.s2point) { + if polygonsIntersectsPoint([]*s2.Polygon{s2pgn}, p2.s2point) { return true, nil } @@ -1205,7 +1205,7 @@ func checkPolygonIntersectsShape(s2pgn *s2.Polygon, shapeIn, // check if the other shape is a multipoint. if p2, ok := other.(*MultiPoint); ok { for _, s2point := range p2.s2points { - if polygonIntersectsPoint([]*s2.Polygon{s2pgn}, s2point) { + if polygonsIntersectsPoint([]*s2.Polygon{s2pgn}, s2point) { return true, nil } } @@ -1293,10 +1293,8 @@ func checkMultiPolygonContainsShape(s2pgns []*s2.Polygon, shapeIn, other index.GeoJSON) (bool, error) { // check if the other shape is a point. if p2, ok := other.(*Point); ok { - for _, s2pgn := range s2pgns { - if polygonIntersectsPoint([]*s2.Polygon{s2pgn}, p2.s2point) { - return true, nil - } + if polygonsIntersectsPoint(s2pgns, p2.s2point) { + return true, nil } return false, nil diff --git a/vendor/github.com/blevesearch/geo/s2/polygon.go b/vendor/github.com/blevesearch/geo/s2/polygon.go index 7c24805dc..94771253a 100644 --- a/vendor/github.com/blevesearch/geo/s2/polygon.go +++ b/vendor/github.com/blevesearch/geo/s2/polygon.go @@ -613,6 +613,27 @@ func (p *Polygon) ContainsPoint(point Point) bool { return NewContainsPointQuery(p.index, VertexModelSemiOpen).Contains(point) } +// Check whether the point is within the bounds of the polygon. +func (p *Polygon) PointWithinBound(point Point) bool { + return p.bound.ContainsPoint(point) +} + +// SmallPolygonContainsPoint checks if the polygon is small enough to use brute force +// returns whether the check is possible and whether the point is contained +// Does not consider vertices of the polygon +func (p *Polygon) SmallPolygonContainsPoint(point Point) (bool, bool) { + const maxBruteForceVertices = 32 + if p.numVertices < maxBruteForceVertices || p.index == nil { + inside := false + for _, l := range p.loops { + inside = inside != l.bruteForceContainsPoint(point) + } + return true, inside + } + + return false, false +} + // ContainsCell reports whether the polygon contains the given cell. func (p *Polygon) ContainsCell(cell Cell) bool { it := p.index.Iterator() diff --git a/vendor/modules.txt b/vendor/modules.txt index f4bf8fd3b..cac220fc0 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -113,7 +113,7 @@ github.com/bitly/go-simplejson # github.com/bits-and-blooms/bitset v1.22.0 ## explicit; go 1.16 github.com/bits-and-blooms/bitset -# github.com/blevesearch/bleve/v2 v2.5.2 +# github.com/blevesearch/bleve/v2 v2.5.3 ## explicit; go 1.23 github.com/blevesearch/bleve/v2 github.com/blevesearch/bleve/v2/analysis @@ -158,7 +158,7 @@ github.com/blevesearch/bleve/v2/util # github.com/blevesearch/bleve_index_api v1.2.8 ## explicit; go 1.21 github.com/blevesearch/bleve_index_api -# github.com/blevesearch/geo v0.2.3 +# github.com/blevesearch/geo v0.2.4 ## explicit; go 1.21.0 github.com/blevesearch/geo/geojson github.com/blevesearch/geo/r1