From c492b20a7a56bbe0052c7c27b91378299c724d2e Mon Sep 17 00:00:00 2001 From: sfomuseumbot Date: Thu, 8 Dec 2022 12:53:38 -0800 Subject: [PATCH] update to support sort and properties (no-op) request flags; update PointInPolygon to use pip.PointInPolygonQuery --- go.mod | 5 +- go.sum | 10 +- request/request.go | 46 +- server/server.go | 26 +- spatial/spatial.pb.go | 181 +-- spatial/spatial.proto | 2 + spatial/spatial_grpc.pb.go | 4 + .../github.com/dhconnelly/rtreego/.gitignore | 1 - .../github.com/dhconnelly/rtreego/.travis.yml | 1 - vendor/github.com/dhconnelly/rtreego/LICENSE | 29 - .../github.com/dhconnelly/rtreego/README.md | 196 --- .../github.com/dhconnelly/rtreego/filter.go | 32 - vendor/github.com/dhconnelly/rtreego/geom.go | 360 ----- vendor/github.com/dhconnelly/rtreego/rtree.go | 826 ------------ .../patrickmn/go-cache/CONTRIBUTORS | 9 - vendor/github.com/patrickmn/go-cache/LICENSE | 19 - .../github.com/patrickmn/go-cache/README.md | 83 -- vendor/github.com/patrickmn/go-cache/cache.go | 1161 ----------------- .../github.com/patrickmn/go-cache/sharded.go | 192 --- .../paulmach/orb/internal/length/length.go | 71 - .../github.com/paulmach/orb/planar/README.md | 40 - vendor/github.com/paulmach/orb/planar/area.go | 284 ---- .../paulmach/orb/planar/contains.go | 122 -- .../paulmach/orb/planar/distance.go | 21 - .../paulmach/orb/planar/distance_from.go | 173 --- .../github.com/paulmach/orb/planar/length.go | 12 - .../go-whosonfirst-spatial-rtree/.gitignore | 2 - .../go-whosonfirst-spatial-rtree/LICENSE | 27 - .../go-whosonfirst-spatial-rtree/Makefile | 2 - .../go-whosonfirst-spatial-rtree/README.md | 113 -- .../go-whosonfirst-spatial-rtree/database.go | 709 ---------- .../go-whosonfirst-spatial/app/properties.go | 4 +- .../go-whosonfirst-spatial/flags/flags.go | 2 + .../go-whosonfirst-spatial/flags/query.go | 3 + .../go-whosonfirst-spatial/timer/timer.go | 61 - vendor/modules.txt | 14 +- 36 files changed, 169 insertions(+), 4674 deletions(-) delete mode 100644 vendor/github.com/dhconnelly/rtreego/.gitignore delete mode 100644 vendor/github.com/dhconnelly/rtreego/.travis.yml delete mode 100644 vendor/github.com/dhconnelly/rtreego/LICENSE delete mode 100644 vendor/github.com/dhconnelly/rtreego/README.md delete mode 100644 vendor/github.com/dhconnelly/rtreego/filter.go delete mode 100644 vendor/github.com/dhconnelly/rtreego/geom.go delete mode 100644 vendor/github.com/dhconnelly/rtreego/rtree.go delete mode 100644 vendor/github.com/patrickmn/go-cache/CONTRIBUTORS delete mode 100644 vendor/github.com/patrickmn/go-cache/LICENSE delete mode 100644 vendor/github.com/patrickmn/go-cache/README.md delete mode 100644 vendor/github.com/patrickmn/go-cache/cache.go delete mode 100644 vendor/github.com/patrickmn/go-cache/sharded.go delete mode 100644 vendor/github.com/paulmach/orb/internal/length/length.go delete mode 100644 vendor/github.com/paulmach/orb/planar/README.md delete mode 100644 vendor/github.com/paulmach/orb/planar/area.go delete mode 100644 vendor/github.com/paulmach/orb/planar/contains.go delete mode 100644 vendor/github.com/paulmach/orb/planar/distance.go delete mode 100644 vendor/github.com/paulmach/orb/planar/distance_from.go delete mode 100644 vendor/github.com/paulmach/orb/planar/length.go delete mode 100644 vendor/github.com/whosonfirst/go-whosonfirst-spatial-rtree/.gitignore delete mode 100644 vendor/github.com/whosonfirst/go-whosonfirst-spatial-rtree/LICENSE delete mode 100644 vendor/github.com/whosonfirst/go-whosonfirst-spatial-rtree/Makefile delete mode 100644 vendor/github.com/whosonfirst/go-whosonfirst-spatial-rtree/README.md delete mode 100644 vendor/github.com/whosonfirst/go-whosonfirst-spatial-rtree/database.go delete mode 100644 vendor/github.com/whosonfirst/go-whosonfirst-spatial/timer/timer.go diff --git a/go.mod b/go.mod index dc70ce9..393cd6e 100644 --- a/go.mod +++ b/go.mod @@ -6,9 +6,8 @@ require ( github.com/paulmach/orb v0.7.1 github.com/sfomuseum/go-flags v0.10.0 github.com/whosonfirst/go-whosonfirst-flags v0.4.4 - github.com/whosonfirst/go-whosonfirst-spatial v0.5.2 + github.com/whosonfirst/go-whosonfirst-spatial v0.5.3 github.com/whosonfirst/go-whosonfirst-spatial-pip v0.3.1 - github.com/whosonfirst/go-whosonfirst-spatial-rtree v0.2.4 github.com/whosonfirst/go-whosonfirst-spr/v2 v2.3.3 google.golang.org/grpc v1.51.0 google.golang.org/protobuf v1.28.1 @@ -17,13 +16,11 @@ require ( require ( github.com/aaronland/go-json-query v0.1.3 // indirect github.com/aaronland/go-roster v1.0.0 // indirect - github.com/dhconnelly/rtreego v1.1.0 // indirect github.com/g8rswimmer/error-chain v1.0.0 // indirect github.com/golang/protobuf v1.5.2 // indirect github.com/hashicorp/errwrap v1.0.0 // indirect github.com/hashicorp/go-multierror v1.1.1 // indirect github.com/natefinch/atomic v1.0.1 // indirect - github.com/patrickmn/go-cache v2.1.0+incompatible // indirect github.com/sfomuseum/go-edtf v1.1.1 // indirect github.com/sfomuseum/go-timings v1.2.1 // indirect github.com/sfomuseum/iso8601duration v1.1.0 // indirect diff --git a/go.sum b/go.sum index 7e15d74..8288bac 100644 --- a/go.sum +++ b/go.sum @@ -7,8 +7,6 @@ github.com/aaronland/go-roster v1.0.0/go.mod h1:KIsYZgrJlAsyb9LsXSCvlqvbcCBVjCSq github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/dhconnelly/rtreego v1.1.0 h1:ejMaqN03N1s6Bdg6peGkNgBnYYSBHzcK8yhSPCB+rHE= -github.com/dhconnelly/rtreego v1.1.0/go.mod h1:SDozu0Fjy17XH1svEXJgdYq8Tah6Zjfa/4Q33Z80+KM= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/g8rswimmer/error-chain v1.0.0 h1:WnwnunlvqtGPHVHmBfbmUyAgrtag8Y6nNpwLWmtSYOQ= @@ -43,8 +41,6 @@ github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/natefinch/atomic v1.0.1 h1:ZPYKxkqQOx3KZ+RsbnP/YsgvxWQPGxjC0oBt2AhwV0A= github.com/natefinch/atomic v1.0.1/go.mod h1:N/D/ELrljoqDyT3rZrsUmtsuzvHkeB/wWjHV22AZRbM= -github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc= -github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ= github.com/paulmach/orb v0.7.1 h1:Zha++Z5OX/l168sqHK3k4z18LDvr+YAO/VjK0ReQ9rU= github.com/paulmach/orb v0.7.1/go.mod h1:FWRlTgl88VI1RBx/MkrwWDRhQ96ctqMCh8boXhmqB/A= github.com/paulmach/protoscan v0.2.1/go.mod h1:SpcSwydNLrxUGSDvXvO0P7g7AuhJ7lcKfDlhJCDw2gY= @@ -89,12 +85,10 @@ github.com/whosonfirst/go-whosonfirst-placetypes v0.4.2 h1:Sye3ySdkTy5+PPdSLCaZO github.com/whosonfirst/go-whosonfirst-placetypes v0.4.2/go.mod h1:HjxisIp+iZOXoThM9XyvC+GCmnupynE73GD3JxhH3fY= github.com/whosonfirst/go-whosonfirst-sources v0.1.0 h1:JuKLa6KWke22jBfJ1pM9WQHoz1/3pbDv2C+aR+THPPQ= github.com/whosonfirst/go-whosonfirst-sources v0.1.0/go.mod h1:EUMHyGzUmqPPxlMmOp+28BFeoBdxxE0HCKRd67lkqGM= -github.com/whosonfirst/go-whosonfirst-spatial v0.5.2 h1:ZCxiGqxbgafUKZ7Nz0wcS/+yzPsLJJNHYnaLHZd51Ns= -github.com/whosonfirst/go-whosonfirst-spatial v0.5.2/go.mod h1:Q8SCUVV0mcGZpMB3Lq9GiBXkm6ZVS/kor4GuPQGvaCA= +github.com/whosonfirst/go-whosonfirst-spatial v0.5.3 h1:QLmgDJx3O/8e2h2j/uqA+lb5NJHIhgITRm6fkx2BcKc= +github.com/whosonfirst/go-whosonfirst-spatial v0.5.3/go.mod h1:Q8SCUVV0mcGZpMB3Lq9GiBXkm6ZVS/kor4GuPQGvaCA= github.com/whosonfirst/go-whosonfirst-spatial-pip v0.3.1 h1:j2QhDx8t4z0s3RJqvm+Ll4t2zG4c195NZx2XRFRCAtY= github.com/whosonfirst/go-whosonfirst-spatial-pip v0.3.1/go.mod h1:klRSLQeAVdFZd84f0xfKjSmVj1L8JCF8GPdGUiVOqnA= -github.com/whosonfirst/go-whosonfirst-spatial-rtree v0.2.4 h1:3dIRDNU1iwwn/4Xe+yD3FEs1L9x7j1ps/asiRfX+/Ho= -github.com/whosonfirst/go-whosonfirst-spatial-rtree v0.2.4/go.mod h1:yEmuF0q/mR17zRiRSD3E+9Ro9tlv8nxu8GbdpSwk5Hc= github.com/whosonfirst/go-whosonfirst-spr/v2 v2.3.3 h1:dc7BdkGrSKtGyIEO8jW4h6xS0DMdKANwMHFRc1+WcnM= github.com/whosonfirst/go-whosonfirst-spr/v2 v2.3.3/go.mod h1:3Sym68fXOfIAcdJiRkJC+8FO+JuSGZ2NuDpRFzWMDi0= github.com/whosonfirst/go-whosonfirst-uri v1.2.0 h1:lhmRsIhcpTr5HAo+kXKRGsSt76HTh3Ko/oTR2jpCm/o= diff --git a/request/request.go b/request/request.go index 685ebb5..06ae9a7 100644 --- a/request/request.go +++ b/request/request.go @@ -2,16 +2,58 @@ package request import ( "flag" + "fmt" "github.com/whosonfirst/go-whosonfirst-spatial-grpc/spatial" "github.com/whosonfirst/go-whosonfirst-spatial-pip" ) +func PIPRequestFromSpatialRequest(spatial_req *spatial.PointInPolygonRequest) *pip.PointInPolygonRequest { + + asInt64 := func(fl []spatial.ExistentialFlag) []int64 { + + j := make([]int64, len(fl)) + + for idx, f := range fl { + + switch f { + case spatial.ExistentialFlag_FALSE: + j[idx] = int64(0) + case spatial.ExistentialFlag_TRUE: + j[idx] = int64(1) + default: + j[idx] = int64(-1) + } + } + + return j + } + + pip_req := &pip.PointInPolygonRequest{ + Latitude: float64(spatial_req.Latitude), + Longitude: float64(spatial_req.Longitude), + Placetypes: spatial_req.Placetypes, + Geometries: spatial_req.Geometries, + AlternateGeometries: spatial_req.AlternateGeometries, + InceptionDate: spatial_req.InceptionDate, + CessationDate: spatial_req.CessationDate, + Sort: spatial_req.Sort, + Properties: spatial_req.Properties, + IsCurrent: asInt64(spatial_req.IsCurrent), + IsCeased: asInt64(spatial_req.IsCeased), + IsDeprecated: asInt64(spatial_req.IsDeprecated), + IsSuperseded: asInt64(spatial_req.IsSuperseded), + IsSuperseding: asInt64(spatial_req.IsSuperseding), + } + + return pip_req +} + func NewPointInPolygonRequestFromFlagSet(fs *flag.FlagSet) (*spatial.PointInPolygonRequest, error) { pip_req, err := pip.NewPointInPolygonRequestFromFlagSet(fs) if err != nil { - return nil, err + return nil, fmt.Errorf("Failed to create request from flagset, %w", err) } return NewPointInPolygonRequest(pip_req) @@ -43,6 +85,8 @@ func NewPointInPolygonRequest(pip_req *pip.PointInPolygonRequest) (*spatial.Poin IsDeprecated: is_deprecated, IsSuperseded: is_superseded, IsSuperseding: is_superseding, + Sort: pip_req.Sort, + Properties: pip_req.Properties, } return req, nil diff --git a/server/server.go b/server/server.go index bcdb2b5..078456d 100644 --- a/server/server.go +++ b/server/server.go @@ -2,12 +2,13 @@ package server import ( "context" + "fmt" "github.com/whosonfirst/go-whosonfirst-flags" "github.com/whosonfirst/go-whosonfirst-spatial-grpc/request" "github.com/whosonfirst/go-whosonfirst-spatial-grpc/spatial" + "github.com/whosonfirst/go-whosonfirst-spatial-pip" "github.com/whosonfirst/go-whosonfirst-spatial/app" "github.com/whosonfirst/go-whosonfirst-spr/v2" - _ "log" ) type SpatialServer struct { @@ -26,24 +27,11 @@ func NewSpatialServer(app *app.SpatialApplication) (*SpatialServer, error) { func (s *SpatialServer) PointInPolygon(ctx context.Context, req *spatial.PointInPolygonRequest) (*spatial.StandardPlacesResults, error) { - coord, err := request.CoordsFromPointInPolygonRequest(req) - - if err != nil { - return nil, err - } - - f, err := request.SPRFilterFromPointInPolygonRequest(req) - - if err != nil { - return nil, err - } - - spatial_db := s.app.SpatialDatabase - - pip_rsp, err := spatial_db.PointInPolygon(ctx, &coord, f) + pip_req := request.PIPRequestFromSpatialRequest(req) + pip_rsp, err := pip.QueryPointInPolygon(ctx, s.app, pip_req) if err != nil { - return nil, err + return nil, fmt.Errorf("Failed to perform point in polygon operation, %w", err) } results := pip_rsp.Results() @@ -68,13 +56,13 @@ func (s *SpatialServer) PointInPolygonStream(req *spatial.PointInPolygonRequest, coord, err := request.CoordsFromPointInPolygonRequest(req) if err != nil { - return err + return fmt.Errorf("Failed to derive coordinate from request, %w", err) } f, err := request.SPRFilterFromPointInPolygonRequest(req) if err != nil { - return err + return fmt.Errorf("Failed to derive filter from request, %w", err) } ctx := context.Background() diff --git a/spatial/spatial.pb.go b/spatial/spatial.pb.go index ec2e3f8..7241733 100644 --- a/spatial/spatial.pb.go +++ b/spatial/spatial.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.26.0 -// protoc v3.15.6 +// protoc-gen-go v1.27.1 +// protoc v3.21.8 // source: spatial/spatial.proto package spatial @@ -86,6 +86,8 @@ type PointInPolygonRequest struct { IsSuperseded []ExistentialFlag `protobuf:"varint,10,rep,packed,name=is_superseded,json=isSuperseded,proto3,enum=ExistentialFlag" json:"is_superseded,omitempty"` InceptionDate string `protobuf:"bytes,11,opt,name=inception_date,json=inceptionDate,proto3" json:"inception_date,omitempty"` CessationDate string `protobuf:"bytes,12,opt,name=cessation_date,json=cessationDate,proto3" json:"cessation_date,omitempty"` + Sort []string `protobuf:"bytes,13,rep,name=sort,proto3" json:"sort,omitempty"` + Properties []string `protobuf:"bytes,14,rep,name=properties,proto3" json:"properties,omitempty"` } func (x *PointInPolygonRequest) Reset() { @@ -204,6 +206,20 @@ func (x *PointInPolygonRequest) GetCessationDate() string { return "" } +func (x *PointInPolygonRequest) GetSort() []string { + if x != nil { + return x.Sort + } + return nil +} + +func (x *PointInPolygonRequest) GetProperties() []string { + if x != nil { + return x.Properties + } + return nil +} + type StandardPlaceResponse struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -494,7 +510,7 @@ var File_spatial_spatial_proto protoreflect.FileDescriptor var file_spatial_spatial_proto_rawDesc = []byte{ 0x0a, 0x15, 0x73, 0x70, 0x61, 0x74, 0x69, 0x61, 0x6c, 0x2f, 0x73, 0x70, 0x61, 0x74, 0x69, 0x61, - 0x6c, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x99, 0x04, 0x0a, 0x15, 0x50, 0x6f, 0x69, 0x6e, + 0x6c, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xcd, 0x04, 0x0a, 0x15, 0x50, 0x6f, 0x69, 0x6e, 0x74, 0x49, 0x6e, 0x50, 0x6f, 0x6c, 0x79, 0x67, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x6c, 0x61, 0x74, 0x69, 0x74, 0x75, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x02, 0x52, 0x08, 0x6c, 0x61, 0x74, 0x69, 0x74, 0x75, 0x64, 0x65, 0x12, 0x1c, 0x0a, @@ -528,85 +544,88 @@ var file_spatial_spatial_proto_rawDesc = []byte{ 0x6e, 0x63, 0x65, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x44, 0x61, 0x74, 0x65, 0x12, 0x25, 0x0a, 0x0e, 0x63, 0x65, 0x73, 0x73, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x64, 0x61, 0x74, 0x65, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x63, 0x65, 0x73, 0x73, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x44, - 0x61, 0x74, 0x65, 0x22, 0xf2, 0x06, 0x0a, 0x15, 0x53, 0x74, 0x61, 0x6e, 0x64, 0x61, 0x72, 0x64, - 0x50, 0x6c, 0x61, 0x63, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x0e, 0x0a, - 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x1b, 0x0a, - 0x09, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x08, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x70, 0x6c, - 0x61, 0x63, 0x65, 0x74, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x70, - 0x6c, 0x61, 0x63, 0x65, 0x74, 0x79, 0x70, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x75, 0x6e, - 0x74, 0x72, 0x79, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x63, 0x6f, 0x75, 0x6e, 0x74, - 0x72, 0x79, 0x12, 0x12, 0x0a, 0x04, 0x72, 0x65, 0x70, 0x6f, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x04, 0x72, 0x65, 0x70, 0x6f, 0x12, 0x12, 0x0a, 0x04, 0x70, 0x61, 0x74, 0x68, 0x18, 0x06, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x70, 0x61, 0x74, 0x68, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x72, - 0x69, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x72, 0x69, 0x12, 0x1a, 0x0a, 0x08, - 0x6c, 0x61, 0x74, 0x69, 0x74, 0x75, 0x64, 0x65, 0x18, 0x08, 0x20, 0x01, 0x28, 0x02, 0x52, 0x08, - 0x6c, 0x61, 0x74, 0x69, 0x74, 0x75, 0x64, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x6c, 0x6f, 0x6e, 0x67, - 0x69, 0x74, 0x75, 0x64, 0x65, 0x18, 0x09, 0x20, 0x01, 0x28, 0x02, 0x52, 0x09, 0x6c, 0x6f, 0x6e, - 0x67, 0x69, 0x74, 0x75, 0x64, 0x65, 0x12, 0x2f, 0x0a, 0x0a, 0x69, 0x73, 0x5f, 0x63, 0x75, 0x72, - 0x72, 0x65, 0x6e, 0x74, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x10, 0x2e, 0x45, 0x78, 0x69, - 0x73, 0x74, 0x65, 0x6e, 0x74, 0x69, 0x61, 0x6c, 0x46, 0x6c, 0x61, 0x67, 0x52, 0x09, 0x69, 0x73, - 0x43, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x12, 0x2d, 0x0a, 0x09, 0x69, 0x73, 0x5f, 0x63, 0x65, - 0x61, 0x73, 0x65, 0x64, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x10, 0x2e, 0x45, 0x78, 0x69, - 0x73, 0x74, 0x65, 0x6e, 0x74, 0x69, 0x61, 0x6c, 0x46, 0x6c, 0x61, 0x67, 0x52, 0x08, 0x69, 0x73, - 0x43, 0x65, 0x61, 0x73, 0x65, 0x64, 0x12, 0x35, 0x0a, 0x0d, 0x69, 0x73, 0x5f, 0x64, 0x65, 0x70, - 0x72, 0x65, 0x63, 0x61, 0x74, 0x65, 0x64, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x10, 0x2e, - 0x45, 0x78, 0x69, 0x73, 0x74, 0x65, 0x6e, 0x74, 0x69, 0x61, 0x6c, 0x46, 0x6c, 0x61, 0x67, 0x52, - 0x0c, 0x69, 0x73, 0x44, 0x65, 0x70, 0x72, 0x65, 0x63, 0x61, 0x74, 0x65, 0x64, 0x12, 0x35, 0x0a, - 0x0d, 0x69, 0x73, 0x5f, 0x73, 0x75, 0x70, 0x65, 0x72, 0x73, 0x65, 0x64, 0x65, 0x64, 0x18, 0x0d, - 0x20, 0x01, 0x28, 0x0e, 0x32, 0x10, 0x2e, 0x45, 0x78, 0x69, 0x73, 0x74, 0x65, 0x6e, 0x74, 0x69, - 0x61, 0x6c, 0x46, 0x6c, 0x61, 0x67, 0x52, 0x0c, 0x69, 0x73, 0x53, 0x75, 0x70, 0x65, 0x72, 0x73, - 0x65, 0x64, 0x65, 0x64, 0x12, 0x37, 0x0a, 0x0e, 0x69, 0x73, 0x5f, 0x73, 0x75, 0x70, 0x65, 0x72, - 0x73, 0x65, 0x64, 0x69, 0x6e, 0x67, 0x18, 0x0e, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x10, 0x2e, 0x45, - 0x78, 0x69, 0x73, 0x74, 0x65, 0x6e, 0x74, 0x69, 0x61, 0x6c, 0x46, 0x6c, 0x61, 0x67, 0x52, 0x0d, - 0x69, 0x73, 0x53, 0x75, 0x70, 0x65, 0x72, 0x73, 0x65, 0x64, 0x69, 0x6e, 0x67, 0x12, 0x25, 0x0a, - 0x0e, 0x69, 0x6e, 0x63, 0x65, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x64, 0x61, 0x74, 0x65, 0x18, - 0x0f, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x69, 0x6e, 0x63, 0x65, 0x70, 0x74, 0x69, 0x6f, 0x6e, - 0x44, 0x61, 0x74, 0x65, 0x12, 0x25, 0x0a, 0x0e, 0x63, 0x65, 0x73, 0x73, 0x61, 0x74, 0x69, 0x6f, - 0x6e, 0x5f, 0x64, 0x61, 0x74, 0x65, 0x18, 0x10, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x63, 0x65, - 0x73, 0x73, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x44, 0x61, 0x74, 0x65, 0x12, 0x21, 0x0a, 0x0c, 0x6d, - 0x69, 0x6e, 0x5f, 0x6c, 0x61, 0x74, 0x69, 0x74, 0x75, 0x64, 0x65, 0x18, 0x11, 0x20, 0x01, 0x28, - 0x02, 0x52, 0x0b, 0x6d, 0x69, 0x6e, 0x4c, 0x61, 0x74, 0x69, 0x74, 0x75, 0x64, 0x65, 0x12, 0x23, - 0x0a, 0x0d, 0x6d, 0x69, 0x6e, 0x5f, 0x6c, 0x6f, 0x6e, 0x67, 0x69, 0x74, 0x75, 0x64, 0x65, 0x18, - 0x12, 0x20, 0x01, 0x28, 0x02, 0x52, 0x0c, 0x6d, 0x69, 0x6e, 0x4c, 0x6f, 0x6e, 0x67, 0x69, 0x74, - 0x75, 0x64, 0x65, 0x12, 0x21, 0x0a, 0x0c, 0x6d, 0x61, 0x78, 0x5f, 0x6c, 0x61, 0x74, 0x69, 0x74, - 0x75, 0x64, 0x65, 0x18, 0x13, 0x20, 0x01, 0x28, 0x02, 0x52, 0x0b, 0x6d, 0x61, 0x78, 0x4c, 0x61, - 0x74, 0x69, 0x74, 0x75, 0x64, 0x65, 0x12, 0x23, 0x0a, 0x0d, 0x6d, 0x61, 0x78, 0x5f, 0x6c, 0x6f, - 0x6e, 0x67, 0x69, 0x74, 0x75, 0x64, 0x65, 0x18, 0x14, 0x20, 0x01, 0x28, 0x02, 0x52, 0x0c, 0x6d, - 0x61, 0x78, 0x4c, 0x6f, 0x6e, 0x67, 0x69, 0x74, 0x75, 0x64, 0x65, 0x12, 0x23, 0x0a, 0x0d, 0x73, - 0x75, 0x70, 0x65, 0x72, 0x73, 0x65, 0x64, 0x65, 0x64, 0x5f, 0x62, 0x79, 0x18, 0x15, 0x20, 0x03, - 0x28, 0x03, 0x52, 0x0c, 0x73, 0x75, 0x70, 0x65, 0x72, 0x73, 0x65, 0x64, 0x65, 0x64, 0x42, 0x79, - 0x12, 0x1e, 0x0a, 0x0a, 0x73, 0x75, 0x70, 0x65, 0x72, 0x73, 0x65, 0x64, 0x65, 0x73, 0x18, 0x16, - 0x20, 0x03, 0x28, 0x03, 0x52, 0x0a, 0x73, 0x75, 0x70, 0x65, 0x72, 0x73, 0x65, 0x64, 0x65, 0x73, - 0x12, 0x1d, 0x0a, 0x0a, 0x62, 0x65, 0x6c, 0x6f, 0x6e, 0x67, 0x73, 0x5f, 0x74, 0x6f, 0x18, 0x17, - 0x20, 0x03, 0x28, 0x03, 0x52, 0x09, 0x62, 0x65, 0x6c, 0x6f, 0x6e, 0x67, 0x73, 0x54, 0x6f, 0x12, - 0x23, 0x0a, 0x0d, 0x6c, 0x61, 0x73, 0x74, 0x5f, 0x6d, 0x6f, 0x64, 0x69, 0x66, 0x69, 0x65, 0x64, - 0x18, 0x18, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0c, 0x6c, 0x61, 0x73, 0x74, 0x4d, 0x6f, 0x64, 0x69, - 0x66, 0x69, 0x65, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x19, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x47, 0x0a, 0x15, 0x53, 0x74, 0x61, 0x6e, + 0x61, 0x74, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x73, 0x6f, 0x72, 0x74, 0x18, 0x0d, 0x20, 0x03, 0x28, + 0x09, 0x52, 0x04, 0x73, 0x6f, 0x72, 0x74, 0x12, 0x1e, 0x0a, 0x0a, 0x70, 0x72, 0x6f, 0x70, 0x65, + 0x72, 0x74, 0x69, 0x65, 0x73, 0x18, 0x0e, 0x20, 0x03, 0x28, 0x09, 0x52, 0x0a, 0x70, 0x72, 0x6f, + 0x70, 0x65, 0x72, 0x74, 0x69, 0x65, 0x73, 0x22, 0xf2, 0x06, 0x0a, 0x15, 0x53, 0x74, 0x61, 0x6e, + 0x64, 0x61, 0x72, 0x64, 0x50, 0x6c, 0x61, 0x63, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, + 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, + 0x64, 0x12, 0x1b, 0x0a, 0x09, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x12, 0x1c, + 0x0a, 0x09, 0x70, 0x6c, 0x61, 0x63, 0x65, 0x74, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x09, 0x70, 0x6c, 0x61, 0x63, 0x65, 0x74, 0x79, 0x70, 0x65, 0x12, 0x18, 0x0a, 0x07, + 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x72, 0x79, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x63, + 0x6f, 0x75, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x12, 0x0a, 0x04, 0x72, 0x65, 0x70, 0x6f, 0x18, 0x05, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x72, 0x65, 0x70, 0x6f, 0x12, 0x12, 0x0a, 0x04, 0x70, 0x61, + 0x74, 0x68, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x70, 0x61, 0x74, 0x68, 0x12, 0x10, + 0x0a, 0x03, 0x75, 0x72, 0x69, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x72, 0x69, + 0x12, 0x1a, 0x0a, 0x08, 0x6c, 0x61, 0x74, 0x69, 0x74, 0x75, 0x64, 0x65, 0x18, 0x08, 0x20, 0x01, + 0x28, 0x02, 0x52, 0x08, 0x6c, 0x61, 0x74, 0x69, 0x74, 0x75, 0x64, 0x65, 0x12, 0x1c, 0x0a, 0x09, + 0x6c, 0x6f, 0x6e, 0x67, 0x69, 0x74, 0x75, 0x64, 0x65, 0x18, 0x09, 0x20, 0x01, 0x28, 0x02, 0x52, + 0x09, 0x6c, 0x6f, 0x6e, 0x67, 0x69, 0x74, 0x75, 0x64, 0x65, 0x12, 0x2f, 0x0a, 0x0a, 0x69, 0x73, + 0x5f, 0x63, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x10, + 0x2e, 0x45, 0x78, 0x69, 0x73, 0x74, 0x65, 0x6e, 0x74, 0x69, 0x61, 0x6c, 0x46, 0x6c, 0x61, 0x67, + 0x52, 0x09, 0x69, 0x73, 0x43, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x12, 0x2d, 0x0a, 0x09, 0x69, + 0x73, 0x5f, 0x63, 0x65, 0x61, 0x73, 0x65, 0x64, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x10, + 0x2e, 0x45, 0x78, 0x69, 0x73, 0x74, 0x65, 0x6e, 0x74, 0x69, 0x61, 0x6c, 0x46, 0x6c, 0x61, 0x67, + 0x52, 0x08, 0x69, 0x73, 0x43, 0x65, 0x61, 0x73, 0x65, 0x64, 0x12, 0x35, 0x0a, 0x0d, 0x69, 0x73, + 0x5f, 0x64, 0x65, 0x70, 0x72, 0x65, 0x63, 0x61, 0x74, 0x65, 0x64, 0x18, 0x0c, 0x20, 0x01, 0x28, + 0x0e, 0x32, 0x10, 0x2e, 0x45, 0x78, 0x69, 0x73, 0x74, 0x65, 0x6e, 0x74, 0x69, 0x61, 0x6c, 0x46, + 0x6c, 0x61, 0x67, 0x52, 0x0c, 0x69, 0x73, 0x44, 0x65, 0x70, 0x72, 0x65, 0x63, 0x61, 0x74, 0x65, + 0x64, 0x12, 0x35, 0x0a, 0x0d, 0x69, 0x73, 0x5f, 0x73, 0x75, 0x70, 0x65, 0x72, 0x73, 0x65, 0x64, + 0x65, 0x64, 0x18, 0x0d, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x10, 0x2e, 0x45, 0x78, 0x69, 0x73, 0x74, + 0x65, 0x6e, 0x74, 0x69, 0x61, 0x6c, 0x46, 0x6c, 0x61, 0x67, 0x52, 0x0c, 0x69, 0x73, 0x53, 0x75, + 0x70, 0x65, 0x72, 0x73, 0x65, 0x64, 0x65, 0x64, 0x12, 0x37, 0x0a, 0x0e, 0x69, 0x73, 0x5f, 0x73, + 0x75, 0x70, 0x65, 0x72, 0x73, 0x65, 0x64, 0x69, 0x6e, 0x67, 0x18, 0x0e, 0x20, 0x01, 0x28, 0x0e, + 0x32, 0x10, 0x2e, 0x45, 0x78, 0x69, 0x73, 0x74, 0x65, 0x6e, 0x74, 0x69, 0x61, 0x6c, 0x46, 0x6c, + 0x61, 0x67, 0x52, 0x0d, 0x69, 0x73, 0x53, 0x75, 0x70, 0x65, 0x72, 0x73, 0x65, 0x64, 0x69, 0x6e, + 0x67, 0x12, 0x25, 0x0a, 0x0e, 0x69, 0x6e, 0x63, 0x65, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x64, + 0x61, 0x74, 0x65, 0x18, 0x0f, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x69, 0x6e, 0x63, 0x65, 0x70, + 0x74, 0x69, 0x6f, 0x6e, 0x44, 0x61, 0x74, 0x65, 0x12, 0x25, 0x0a, 0x0e, 0x63, 0x65, 0x73, 0x73, + 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x64, 0x61, 0x74, 0x65, 0x18, 0x10, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x0d, 0x63, 0x65, 0x73, 0x73, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x44, 0x61, 0x74, 0x65, 0x12, + 0x21, 0x0a, 0x0c, 0x6d, 0x69, 0x6e, 0x5f, 0x6c, 0x61, 0x74, 0x69, 0x74, 0x75, 0x64, 0x65, 0x18, + 0x11, 0x20, 0x01, 0x28, 0x02, 0x52, 0x0b, 0x6d, 0x69, 0x6e, 0x4c, 0x61, 0x74, 0x69, 0x74, 0x75, + 0x64, 0x65, 0x12, 0x23, 0x0a, 0x0d, 0x6d, 0x69, 0x6e, 0x5f, 0x6c, 0x6f, 0x6e, 0x67, 0x69, 0x74, + 0x75, 0x64, 0x65, 0x18, 0x12, 0x20, 0x01, 0x28, 0x02, 0x52, 0x0c, 0x6d, 0x69, 0x6e, 0x4c, 0x6f, + 0x6e, 0x67, 0x69, 0x74, 0x75, 0x64, 0x65, 0x12, 0x21, 0x0a, 0x0c, 0x6d, 0x61, 0x78, 0x5f, 0x6c, + 0x61, 0x74, 0x69, 0x74, 0x75, 0x64, 0x65, 0x18, 0x13, 0x20, 0x01, 0x28, 0x02, 0x52, 0x0b, 0x6d, + 0x61, 0x78, 0x4c, 0x61, 0x74, 0x69, 0x74, 0x75, 0x64, 0x65, 0x12, 0x23, 0x0a, 0x0d, 0x6d, 0x61, + 0x78, 0x5f, 0x6c, 0x6f, 0x6e, 0x67, 0x69, 0x74, 0x75, 0x64, 0x65, 0x18, 0x14, 0x20, 0x01, 0x28, + 0x02, 0x52, 0x0c, 0x6d, 0x61, 0x78, 0x4c, 0x6f, 0x6e, 0x67, 0x69, 0x74, 0x75, 0x64, 0x65, 0x12, + 0x23, 0x0a, 0x0d, 0x73, 0x75, 0x70, 0x65, 0x72, 0x73, 0x65, 0x64, 0x65, 0x64, 0x5f, 0x62, 0x79, + 0x18, 0x15, 0x20, 0x03, 0x28, 0x03, 0x52, 0x0c, 0x73, 0x75, 0x70, 0x65, 0x72, 0x73, 0x65, 0x64, + 0x65, 0x64, 0x42, 0x79, 0x12, 0x1e, 0x0a, 0x0a, 0x73, 0x75, 0x70, 0x65, 0x72, 0x73, 0x65, 0x64, + 0x65, 0x73, 0x18, 0x16, 0x20, 0x03, 0x28, 0x03, 0x52, 0x0a, 0x73, 0x75, 0x70, 0x65, 0x72, 0x73, + 0x65, 0x64, 0x65, 0x73, 0x12, 0x1d, 0x0a, 0x0a, 0x62, 0x65, 0x6c, 0x6f, 0x6e, 0x67, 0x73, 0x5f, + 0x74, 0x6f, 0x18, 0x17, 0x20, 0x03, 0x28, 0x03, 0x52, 0x09, 0x62, 0x65, 0x6c, 0x6f, 0x6e, 0x67, + 0x73, 0x54, 0x6f, 0x12, 0x23, 0x0a, 0x0d, 0x6c, 0x61, 0x73, 0x74, 0x5f, 0x6d, 0x6f, 0x64, 0x69, + 0x66, 0x69, 0x65, 0x64, 0x18, 0x18, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0c, 0x6c, 0x61, 0x73, 0x74, + 0x4d, 0x6f, 0x64, 0x69, 0x66, 0x69, 0x65, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, + 0x18, 0x19, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x47, 0x0a, 0x15, + 0x53, 0x74, 0x61, 0x6e, 0x64, 0x61, 0x72, 0x64, 0x50, 0x6c, 0x61, 0x63, 0x65, 0x73, 0x52, 0x65, + 0x73, 0x75, 0x6c, 0x74, 0x73, 0x12, 0x2e, 0x0a, 0x06, 0x70, 0x6c, 0x61, 0x63, 0x65, 0x73, 0x18, + 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x16, 0x2e, 0x53, 0x74, 0x61, 0x6e, 0x64, 0x61, 0x72, 0x64, + 0x50, 0x6c, 0x61, 0x63, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x52, 0x06, 0x70, + 0x6c, 0x61, 0x63, 0x65, 0x73, 0x2a, 0x3c, 0x0a, 0x0f, 0x45, 0x78, 0x69, 0x73, 0x74, 0x65, 0x6e, + 0x74, 0x69, 0x61, 0x6c, 0x46, 0x6c, 0x61, 0x67, 0x12, 0x09, 0x0a, 0x05, 0x46, 0x41, 0x4c, 0x53, + 0x45, 0x10, 0x00, 0x12, 0x08, 0x0a, 0x04, 0x54, 0x52, 0x55, 0x45, 0x10, 0x01, 0x12, 0x14, 0x0a, + 0x07, 0x55, 0x4e, 0x4b, 0x4e, 0x4f, 0x57, 0x4e, 0x10, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0x01, 0x32, 0x99, 0x01, 0x0a, 0x07, 0x53, 0x70, 0x61, 0x74, 0x69, 0x61, 0x6c, 0x12, + 0x42, 0x0a, 0x0e, 0x50, 0x6f, 0x69, 0x6e, 0x74, 0x49, 0x6e, 0x50, 0x6f, 0x6c, 0x79, 0x67, 0x6f, + 0x6e, 0x12, 0x16, 0x2e, 0x50, 0x6f, 0x69, 0x6e, 0x74, 0x49, 0x6e, 0x50, 0x6f, 0x6c, 0x79, 0x67, + 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x53, 0x74, 0x61, 0x6e, 0x64, 0x61, 0x72, 0x64, 0x50, 0x6c, 0x61, 0x63, 0x65, 0x73, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, - 0x73, 0x12, 0x2e, 0x0a, 0x06, 0x70, 0x6c, 0x61, 0x63, 0x65, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, - 0x0b, 0x32, 0x16, 0x2e, 0x53, 0x74, 0x61, 0x6e, 0x64, 0x61, 0x72, 0x64, 0x50, 0x6c, 0x61, 0x63, - 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x52, 0x06, 0x70, 0x6c, 0x61, 0x63, 0x65, - 0x73, 0x2a, 0x3c, 0x0a, 0x0f, 0x45, 0x78, 0x69, 0x73, 0x74, 0x65, 0x6e, 0x74, 0x69, 0x61, 0x6c, - 0x46, 0x6c, 0x61, 0x67, 0x12, 0x09, 0x0a, 0x05, 0x46, 0x41, 0x4c, 0x53, 0x45, 0x10, 0x00, 0x12, - 0x08, 0x0a, 0x04, 0x54, 0x52, 0x55, 0x45, 0x10, 0x01, 0x12, 0x14, 0x0a, 0x07, 0x55, 0x4e, 0x4b, - 0x4e, 0x4f, 0x57, 0x4e, 0x10, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0x32, - 0x99, 0x01, 0x0a, 0x07, 0x53, 0x70, 0x61, 0x74, 0x69, 0x61, 0x6c, 0x12, 0x42, 0x0a, 0x0e, 0x50, - 0x6f, 0x69, 0x6e, 0x74, 0x49, 0x6e, 0x50, 0x6f, 0x6c, 0x79, 0x67, 0x6f, 0x6e, 0x12, 0x16, 0x2e, - 0x50, 0x6f, 0x69, 0x6e, 0x74, 0x49, 0x6e, 0x50, 0x6f, 0x6c, 0x79, 0x67, 0x6f, 0x6e, 0x52, 0x65, - 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x53, 0x74, 0x61, 0x6e, 0x64, 0x61, 0x72, 0x64, - 0x50, 0x6c, 0x61, 0x63, 0x65, 0x73, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x73, 0x22, 0x00, 0x12, - 0x4a, 0x0a, 0x14, 0x50, 0x6f, 0x69, 0x6e, 0x74, 0x49, 0x6e, 0x50, 0x6f, 0x6c, 0x79, 0x67, 0x6f, - 0x6e, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x12, 0x16, 0x2e, 0x50, 0x6f, 0x69, 0x6e, 0x74, 0x49, - 0x6e, 0x50, 0x6f, 0x6c, 0x79, 0x67, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, - 0x16, 0x2e, 0x53, 0x74, 0x61, 0x6e, 0x64, 0x61, 0x72, 0x64, 0x50, 0x6c, 0x61, 0x63, 0x65, 0x52, - 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x30, 0x01, 0x42, 0x3c, 0x5a, 0x3a, 0x67, - 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x77, 0x68, 0x6f, 0x73, 0x6f, 0x6e, - 0x66, 0x69, 0x72, 0x73, 0x74, 0x2f, 0x67, 0x6f, 0x2d, 0x77, 0x68, 0x6f, 0x73, 0x6f, 0x6e, 0x66, - 0x69, 0x72, 0x73, 0x74, 0x2d, 0x73, 0x70, 0x61, 0x74, 0x69, 0x61, 0x6c, 0x2d, 0x67, 0x72, 0x70, - 0x63, 0x2f, 0x73, 0x70, 0x61, 0x74, 0x69, 0x61, 0x6c, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x33, + 0x73, 0x22, 0x00, 0x12, 0x4a, 0x0a, 0x14, 0x50, 0x6f, 0x69, 0x6e, 0x74, 0x49, 0x6e, 0x50, 0x6f, + 0x6c, 0x79, 0x67, 0x6f, 0x6e, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x12, 0x16, 0x2e, 0x50, 0x6f, + 0x69, 0x6e, 0x74, 0x49, 0x6e, 0x50, 0x6f, 0x6c, 0x79, 0x67, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x53, 0x74, 0x61, 0x6e, 0x64, 0x61, 0x72, 0x64, 0x50, 0x6c, + 0x61, 0x63, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x30, 0x01, 0x42, + 0x3c, 0x5a, 0x3a, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x77, 0x68, + 0x6f, 0x73, 0x6f, 0x6e, 0x66, 0x69, 0x72, 0x73, 0x74, 0x2f, 0x67, 0x6f, 0x2d, 0x77, 0x68, 0x6f, + 0x73, 0x6f, 0x6e, 0x66, 0x69, 0x72, 0x73, 0x74, 0x2d, 0x73, 0x70, 0x61, 0x74, 0x69, 0x61, 0x6c, + 0x2d, 0x67, 0x72, 0x70, 0x63, 0x2f, 0x73, 0x70, 0x61, 0x74, 0x69, 0x61, 0x6c, 0x62, 0x06, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/spatial/spatial.proto b/spatial/spatial.proto index 8001ad3..468ec58 100644 --- a/spatial/spatial.proto +++ b/spatial/spatial.proto @@ -32,6 +32,8 @@ message PointInPolygonRequest { repeated ExistentialFlag is_superseded = 10; string inception_date = 11; string cessation_date = 12; + repeated string sort = 13; + repeated string properties = 14; } // https://github.com/whosonfirst/go-whosonfirst-spr/blob/main/spr.go diff --git a/spatial/spatial_grpc.pb.go b/spatial/spatial_grpc.pb.go index b9a4936..4fc8430 100644 --- a/spatial/spatial_grpc.pb.go +++ b/spatial/spatial_grpc.pb.go @@ -1,4 +1,8 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.2.0 +// - protoc v3.21.8 +// source: spatial/spatial.proto package spatial diff --git a/vendor/github.com/dhconnelly/rtreego/.gitignore b/vendor/github.com/dhconnelly/rtreego/.gitignore deleted file mode 100644 index b25c15b..0000000 --- a/vendor/github.com/dhconnelly/rtreego/.gitignore +++ /dev/null @@ -1 +0,0 @@ -*~ diff --git a/vendor/github.com/dhconnelly/rtreego/.travis.yml b/vendor/github.com/dhconnelly/rtreego/.travis.yml deleted file mode 100644 index 4f2ee4d..0000000 --- a/vendor/github.com/dhconnelly/rtreego/.travis.yml +++ /dev/null @@ -1 +0,0 @@ -language: go diff --git a/vendor/github.com/dhconnelly/rtreego/LICENSE b/vendor/github.com/dhconnelly/rtreego/LICENSE deleted file mode 100644 index 8145134..0000000 --- a/vendor/github.com/dhconnelly/rtreego/LICENSE +++ /dev/null @@ -1,29 +0,0 @@ -BSD 3-Clause License - -Copyright (c) 2019, Daniel Connelly -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -3. Neither the name of the copyright holder nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/vendor/github.com/dhconnelly/rtreego/README.md b/vendor/github.com/dhconnelly/rtreego/README.md deleted file mode 100644 index 81fec70..0000000 --- a/vendor/github.com/dhconnelly/rtreego/README.md +++ /dev/null @@ -1,196 +0,0 @@ -rtreego -======= - -A library for efficiently storing and querying spatial data -in the Go programming language. - -[![Build Status](https://travis-ci.org/dhconnelly/rtreego.png?branch=master)](https://travis-ci.org/dhconnelly/rtreego) -[![Go Report Card](https://goreportcard.com/badge/github.com/dhconnelly/rtreego)](https://goreportcard.com/report/github.com/dhconnelly/rtreego) -[![GoDoc](https://godoc.org/github.com/dhconnelly/rtreego?status.svg)](https://godoc.org/github.com/dhconnelly/rtreego) - -About ------ - -The R-tree is a popular data structure for efficiently storing and -querying spatial objects; one common use is implementing geospatial -indexes in database management systems. Both bounding-box queries -and k-nearest-neighbor queries are supported. - -R-trees are balanced, so maximum tree height is guaranteed to be -logarithmic in the number of entries; however, good worst-case -performance is not guaranteed. Instead, a number of rebalancing -heuristics are applied that perform well in practice. For more -details please refer to the references. - -This implementation handles the general N-dimensional case; for a more -efficient implementation for the 3-dimensional case, see [Patrick -Higgins' fork](https://github.com/patrick-higgins/rtreego). - -Getting Started ---------------- - -Get the source code from [GitHub](https://github.com/dhconnelly/rtreego) or, -with Go 1 installed, run `go get github.com/dhconnelly/rtreego`. - -Make sure you `import github.com/dhconnelly/rtreego` in your Go source files. - -Documentation -------------- - -### Storing, updating, and deleting objects - -To create a new tree, specify the number of spatial dimensions and the minimum -and maximum branching factor: - - rt := rtreego.NewTree(2, 25, 50) - -You can also bulk-load the tree when creating it by passing the objects as -a parameter. - - rt := rtreego.NewTree(2, 25, 50, objects...) - -Any type that implements the `Spatial` interface can be stored in the tree: - - type Spatial interface { - Bounds() *Rect - } - -`Rect`s are data structures for representing spatial objects, while `Point`s -represent spatial locations. Creating `Point`s is easy--they're just slices -of `float64`s: - - p1 := rtreego.Point{0.4, 0.5} - p2 := rtreego.Point{6.2, -3.4} - -To create a `Rect`, specify a location and the lengths of the sides: - - r1, _ := rtreego.NewRect(p1, []float64{1, 2}) - r2, _ := rtreego.NewRect(p2, []float64{1.7, 2.7}) - -To demonstrate, let's create and store some test data. - - type Thing struct { - where *Rect - name string - } - - func (t *Thing) Bounds() *Rect { - return t.where - } - - rt.Insert(&Thing{r1, "foo"}) - rt.Insert(&Thing{r2, "bar"}) - - size := rt.Size() // returns 2 - -We can insert and delete objects from the tree in any order. - - rt.Delete(thing2) - // do some stuff... - rt.Insert(anotherThing) - -Note that ```Delete``` function does the equality comparison by comparing the -memory addresses of the objects. If you do not have a pointer to the original -object anymore, you can define a custom comparator. - - type Comparator func(obj1, obj2 Spatial) (equal bool) - -You can use a custom comparator with ```DeleteWithComparator``` function. - - cmp := func(obj1, obj2 Spatial) bool { - sp1 := obj1.(*IDRect) - sp2 := obj2.(*IDRect) - - return sp1.ID == sp2.ID - } - - rt.DeleteWithComparator(obj, cmp) - -If you want to store points instead of rectangles, you can easily convert a -point into a rectangle using the `ToRect` method: - - var tol = 0.01 - - type Somewhere struct { - location rtreego.Point - name string - wormhole chan int - } - - func (s *Somewhere) Bounds() *Rect { - // define the bounds of s to be a rectangle centered at s.location - // with side lengths 2 * tol: - return s.location.ToRect(tol) - } - - rt.Insert(&Somewhere{rtreego.Point{0, 0}, "Someplace", nil}) - -If you want to update the location of an object, you must delete it, update it, -and re-insert. Just modifying the object so that the `*Rect` returned by -`Location()` changes, without deleting and re-inserting the object, will -corrupt the tree. - -### Queries - -Bounding-box and k-nearest-neighbors queries are supported. - -Bounding-box queries require a search `*Rect`. It returns all objects that -touch the search rectangle. - - bb, _ := rtreego.NewRect(rtreego.Point{1.7, -3.4}, []float64{3.2, 1.9}) - - // Get a slice of the objects in rt that intersect bb: - results := rt.SearchIntersect(bb) - -### Filters - -You can filter out values during searches by implementing Filter functions. - - type Filter func(results []Spatial, object Spatial) (refuse, abort bool) - -A filter for limiting results by result count is included in the package for -backwards compatibility. - - // maximum of three results will be returned - tree.SearchIntersect(bb, LimitFilter(3)) - -Nearest-neighbor queries find the objects in a tree closest to a specified -query point. - - q := rtreego.Point{6.5, -2.47} - k := 5 - - // Get a slice of the k objects in rt closest to q: - results = rt.NearestNeighbors(k, q) - -### More information - -See [GoDoc](http://godoc.org/github.com/dhconnelly/rtreego) for full API -documentation. - -References ----------- - -- A. Guttman. R-trees: A Dynamic Index Structure for Spatial Searching. - Proceedings of ACM SIGMOD, pages 47-57, 1984. - http://www.cs.jhu.edu/~misha/ReadingSeminar/Papers/Guttman84.pdf - -- N. Beckmann, H .P. Kriegel, R. Schneider and B. Seeger. The R*-tree: An - Efficient and Robust Access Method for Points and Rectangles. Proceedings - of ACM SIGMOD, pages 323-331, May 1990. - http://infolab.usc.edu/csci587/Fall2011/papers/p322-beckmann.pdf - -- N. Roussopoulos, S. Kelley and F. Vincent. Nearest Neighbor Queries. ACM - SIGMOD, pages 71-79, 1995. - http://www.postgis.org/support/nearestneighbor.pdf - -Author ------- - -Written by [Daniel Connelly](http://dhconnelly.com) (). - -License -------- - -rtreego is released under a BSD-style license, described in the `LICENSE` -file. diff --git a/vendor/github.com/dhconnelly/rtreego/filter.go b/vendor/github.com/dhconnelly/rtreego/filter.go deleted file mode 100644 index 3e037bd..0000000 --- a/vendor/github.com/dhconnelly/rtreego/filter.go +++ /dev/null @@ -1,32 +0,0 @@ -package rtreego - -// Filter is an interface for filtering leaves during search. The parameters -// should be treated as read-only. If refuse is true, the current entry will -// not be added to the result set. If abort is true, the search is aborted and -// the current result set will be returned. -type Filter func(results []Spatial, object Spatial) (refuse, abort bool) - -// ApplyFilters applies the given filters and returns whether the entry is -// refused and/or the search should be aborted. If a filter refuses an entry, -// the following filters are not applied for the entry. If a filter aborts, the -// search terminates without further applying any filter. -func applyFilters(results []Spatial, object Spatial, filters []Filter) (bool, bool) { - for _, filter := range filters { - refuse, abort := filter(results, object) - if refuse || abort { - return refuse, abort - } - } - return false, false -} - -// LimitFilter checks if the results have reached the limit size and aborts if so. -func LimitFilter(limit int) Filter { - return func(results []Spatial, object Spatial) (refuse, abort bool) { - if len(results) >= limit { - return true, true - } - - return false, false - } -} diff --git a/vendor/github.com/dhconnelly/rtreego/geom.go b/vendor/github.com/dhconnelly/rtreego/geom.go deleted file mode 100644 index 06e83a3..0000000 --- a/vendor/github.com/dhconnelly/rtreego/geom.go +++ /dev/null @@ -1,360 +0,0 @@ -// Copyright 2012 Daniel Connelly. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package rtreego - -import ( - "fmt" - "math" - "strings" -) - -// DimError represents a failure due to mismatched dimensions. -type DimError struct { - Expected int - Actual int -} - -func (err DimError) Error() string { - return "rtreego: dimension mismatch" -} - -// DistError is an improper distance measurement. It implements the error -// and is generated when a distance-related assertion fails. -type DistError float64 - -func (err DistError) Error() string { - return "rtreego: improper distance" -} - -// Point represents a point in n-dimensional Euclidean space. -type Point []float64 - -// Dist computes the Euclidean distance between two points p and q. -func (p Point) dist(q Point) float64 { - if len(p) != len(q) { - panic(DimError{len(p), len(q)}) - } - sum := 0.0 - for i := range p { - dx := p[i] - q[i] - sum += dx * dx - } - return math.Sqrt(sum) -} - -// minDist computes the square of the distance from a point to a rectangle. -// If the point is contained in the rectangle then the distance is zero. -// -// Implemented per Definition 2 of "Nearest Neighbor Queries" by -// N. Roussopoulos, S. Kelley and F. Vincent, ACM SIGMOD, pages 71-79, 1995. -func (p Point) minDist(r *Rect) float64 { - if len(p) != len(r.p) { - panic(DimError{len(p), len(r.p)}) - } - - sum := 0.0 - for i, pi := range p { - if pi < r.p[i] { - d := pi - r.p[i] - sum += d * d - } else if pi > r.q[i] { - d := pi - r.q[i] - sum += d * d - } else { - sum += 0 - } - } - return sum -} - -// minMaxDist computes the minimum of the maximum distances from p to points -// on r. If r is the bounding box of some geometric objects, then there is -// at least one object contained in r within minMaxDist(p, r) of p. -// -// Implemented per Definition 4 of "Nearest Neighbor Queries" by -// N. Roussopoulos, S. Kelley and F. Vincent, ACM SIGMOD, pages 71-79, 1995. -func (p Point) minMaxDist(r *Rect) float64 { - if len(p) != len(r.p) { - panic(DimError{len(p), len(r.p)}) - } - - // by definition, MinMaxDist(p, r) = - // min{1<=k<=n}(|pk - rmk|^2 + sum{1<=i<=n, i != k}(|pi - rMi|^2)) - // where rmk and rMk are defined as follows: - - rm := func(k int) float64 { - if p[k] <= (r.p[k]+r.q[k])/2 { - return r.p[k] - } - return r.q[k] - } - - rM := func(k int) float64 { - if p[k] >= (r.p[k]+r.q[k])/2 { - return r.p[k] - } - return r.q[k] - } - - // This formula can be computed in linear time by precomputing - // S = sum{1<=i<=n}(|pi - rMi|^2). - - S := 0.0 - for i := range p { - d := p[i] - rM(i) - S += d * d - } - - // Compute MinMaxDist using the precomputed S. - min := math.MaxFloat64 - for k := range p { - d1 := p[k] - rM(k) - d2 := p[k] - rm(k) - d := S - d1*d1 + d2*d2 - if d < min { - min = d - } - } - - return min -} - -// Rect represents a subset of n-dimensional Euclidean space of the form -// [a1, b1] x [a2, b2] x ... x [an, bn], where ai < bi for all 1 <= i <= n. -type Rect struct { - p, q Point // Enforced by NewRect: p[i] <= q[i] for all i. -} - -// PointCoord returns the coordinate of the point of the rectangle at i -func (r *Rect) PointCoord(i int) float64 { - return r.p[i] -} - -// LengthsCoord returns the coordinate of the lengths of the rectangle at i -func (r *Rect) LengthsCoord(i int) float64 { - return r.q[i] - r.p[i] -} - -// Equal returns true if the two rectangles are equal -func (r *Rect) Equal(other *Rect) bool { - for i, e := range r.p { - if e != other.p[i] { - return false - } - } - for i, e := range r.q { - if e != other.q[i] { - return false - } - } - return true -} - -func (r *Rect) String() string { - s := make([]string, len(r.p)) - for i, a := range r.p { - b := r.q[i] - s[i] = fmt.Sprintf("[%.2f, %.2f]", a, b) - } - return strings.Join(s, "x") -} - -// NewRect constructs and returns a pointer to a Rect given a corner point and -// the lengths of each dimension. The point p should be the most-negative point -// on the rectangle (in every dimension) and every length should be positive. -func NewRect(p Point, lengths []float64) (r *Rect, err error) { - r = new(Rect) - r.p = p - if len(p) != len(lengths) { - err = &DimError{len(p), len(lengths)} - return - } - r.q = make([]float64, len(p)) - for i := range p { - if lengths[i] <= 0 { - err = DistError(lengths[i]) - return - } - r.q[i] = p[i] + lengths[i] - } - return -} - -// NewRectFromPoints constructs and returns a pointer to a Rect given a corner points. -func NewRectFromPoints(minPoint, maxPoint Point) (r *Rect, err error) { - if len(minPoint) != len(maxPoint) { - err = &DimError{len(minPoint), len(maxPoint)} - return - } - - //checking that min and max points is swapping - for i, p := range minPoint { - if minPoint[i] > maxPoint[i] { - minPoint[i] = maxPoint[i] - maxPoint[i] = p - } - } - - r = &Rect{p: minPoint, q: maxPoint} - return -} - -// Size computes the measure of a rectangle (the product of its side lengths). -func (r *Rect) Size() float64 { - size := 1.0 - for i, a := range r.p { - b := r.q[i] - size *= b - a - } - return size -} - -// margin computes the sum of the edge lengths of a rectangle. -func (r *Rect) margin() float64 { - // The number of edges in an n-dimensional rectangle is n * 2^(n-1) - // (http://en.wikipedia.org/wiki/Hypercube_graph). Thus the number - // of edges of length (ai - bi), where the rectangle is determined - // by p = (a1, a2, ..., an) and q = (b1, b2, ..., bn), is 2^(n-1). - // - // The margin of the rectangle, then, is given by the formula - // 2^(n-1) * [(b1 - a1) + (b2 - a2) + ... + (bn - an)]. - dim := len(r.p) - sum := 0.0 - for i, a := range r.p { - b := r.q[i] - sum += b - a - } - return math.Pow(2, float64(dim-1)) * sum -} - -// containsPoint tests whether p is located inside or on the boundary of r. -func (r *Rect) containsPoint(p Point) bool { - if len(p) != len(r.p) { - panic(DimError{len(r.p), len(p)}) - } - - for i, a := range p { - // p is contained in (or on) r if and only if p <= a <= q for - // every dimension. - if a < r.p[i] || a > r.q[i] { - return false - } - } - - return true -} - -// containsRect tests whether r2 is is located inside r1. -func (r *Rect) containsRect(r2 *Rect) bool { - if len(r.p) != len(r2.p) { - panic(DimError{len(r.p), len(r2.p)}) - } - - for i, a1 := range r.p { - b1, a2, b2 := r.q[i], r2.p[i], r2.q[i] - // enforced by constructor: a1 <= b1 and a2 <= b2. - // so containment holds if and only if a1 <= a2 <= b2 <= b1 - // for every dimension. - if a1 > a2 || b2 > b1 { - return false - } - } - - return true -} - -// intersect computes the intersection of two rectangles. If no intersection -// exists, the intersection is nil. -func intersect(r1, r2 *Rect) bool { - dim := len(r1.p) - if len(r2.p) != dim { - panic(DimError{dim, len(r2.p)}) - } - - // There are four cases of overlap: - // - // 1. a1------------b1 - // a2------------b2 - // p--------q - // - // 2. a1------------b1 - // a2------------b2 - // p--------q - // - // 3. a1-----------------b1 - // a2-------b2 - // p--------q - // - // 4. a1-------b1 - // a2-----------------b2 - // p--------q - // - // Thus there are only two cases of non-overlap: - // - // 1. a1------b1 - // a2------b2 - // - // 2. a1------b1 - // a2------b2 - // - // Enforced by constructor: a1 <= b1 and a2 <= b2. So we can just - // check the endpoints. - - for i := range r1.p { - a1, b1, a2, b2 := r1.p[i], r1.q[i], r2.p[i], r2.q[i] - if b2 <= a1 || b1 <= a2 { - return false - } - } - return true -} - -// ToRect constructs a rectangle containing p with side lengths 2*tol. -func (p Point) ToRect(tol float64) *Rect { - dim := len(p) - a, b := make([]float64, dim), make([]float64, dim) - for i := range p { - a[i] = p[i] - tol - b[i] = p[i] + tol - } - return &Rect{a, b} -} - -// boundingBox constructs the smallest rectangle containing both r1 and r2. -func boundingBox(r1, r2 *Rect) (bb *Rect) { - bb = new(Rect) - dim := len(r1.p) - bb.p = make([]float64, dim) - bb.q = make([]float64, dim) - if len(r2.p) != dim { - panic(DimError{dim, len(r2.p)}) - } - for i := 0; i < dim; i++ { - if r1.p[i] <= r2.p[i] { - bb.p[i] = r1.p[i] - } else { - bb.p[i] = r2.p[i] - } - if r1.q[i] <= r2.q[i] { - bb.q[i] = r2.q[i] - } else { - bb.q[i] = r1.q[i] - } - } - return -} - -// boundingBoxN constructs the smallest rectangle containing all of r... -func boundingBoxN(rects ...*Rect) (bb *Rect) { - if len(rects) == 1 { - bb = rects[0] - return - } - bb = boundingBox(rects[0], rects[1]) - for _, rect := range rects[2:] { - bb = boundingBox(bb, rect) - } - return -} diff --git a/vendor/github.com/dhconnelly/rtreego/rtree.go b/vendor/github.com/dhconnelly/rtreego/rtree.go deleted file mode 100644 index 8727545..0000000 --- a/vendor/github.com/dhconnelly/rtreego/rtree.go +++ /dev/null @@ -1,826 +0,0 @@ -// Copyright 2012 Daniel Connelly. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// Package rtreego is a library for efficiently storing and querying spatial data. -package rtreego - -import ( - "fmt" - "math" - "sort" -) - -// Comparator compares two spatials and returns whether they are equal. -type Comparator func(obj1, obj2 Spatial) (equal bool) - -func defaultComparator(obj1, obj2 Spatial) bool { - return obj1 == obj2 -} - -// Rtree represents an R-tree, a balanced search tree for storing and querying -// spatial objects. Dim specifies the number of spatial dimensions and -// MinChildren/MaxChildren specify the minimum/maximum branching factors. -type Rtree struct { - Dim int - MinChildren int - MaxChildren int - root *node - size int - height int -} - -// NewTree returns an Rtree. If the number of objects given on initialization -// is larger than max, the Rtree will be initialized using the Overlap -// Minimizing Top-down bulk-loading algorithm. -func NewTree(dim, min, max int, objs ...Spatial) *Rtree { - rt := &Rtree{ - Dim: dim, - MinChildren: min, - MaxChildren: max, - height: 1, - root: &node{ - entries: []entry{}, - leaf: true, - level: 1, - }, - } - - if len(objs) <= rt.MaxChildren { - for _, obj := range objs { - rt.Insert(obj) - } - } else { - rt.bulkLoad(objs) - } - - return rt -} - -// Size returns the number of objects currently stored in tree. -func (tree *Rtree) Size() int { - return tree.size -} - -func (tree *Rtree) String() string { - return "foo" -} - -// Depth returns the maximum depth of tree. -func (tree *Rtree) Depth() int { - return tree.height -} - -type dimSorter struct { - dim int - objs []entry -} - -func (s *dimSorter) Len() int { - return len(s.objs) -} - -func (s *dimSorter) Swap(i, j int) { - s.objs[i], s.objs[j] = s.objs[j], s.objs[i] -} - -func (s *dimSorter) Less(i, j int) bool { - return s.objs[i].bb.p[s.dim] < s.objs[j].bb.p[s.dim] -} - -// walkPartitions splits objs into slices of maximum k elements and -// iterates over these partitions. -func walkPartitions(k int, objs []entry, iter func(parts []entry)) { - n := (len(objs) + k - 1) / k // ceil(len(objs) / k) - - for i := 1; i < n; i++ { - iter(objs[(i-1)*k : i*k]) - } - iter(objs[(n-1)*k:]) -} - -func sortByDim(dim int, objs []entry) { - sort.Sort(&dimSorter{dim, objs}) -} - -// bulkLoad bulk loads the Rtree using OMT algorithm. bulkLoad contains special -// handling for the root node. -func (tree *Rtree) bulkLoad(objs []Spatial) { - n := len(objs) - - // create entries for all the objects - entries := make([]entry, n) - for i := range objs { - entries[i] = entry{ - bb: objs[i].Bounds(), - obj: objs[i], - } - } - - // following equations are defined in the paper describing OMT - var ( - N = float64(n) - M = float64(tree.MaxChildren) - ) - // Eq1: height of the tree - // use log2 instead of log due to rounding errors with log, - // eg, math.Log(9) / math.Log(3) > 2 - h := math.Ceil(math.Log2(N) / math.Log2(M)) - - // Eq2: size of subtrees at the root - nsub := math.Pow(M, h-1) - - // Inner Eq3: number of subtrees at the root - s := math.Ceil(N / nsub) - - // Eq3: number of slices - S := math.Floor(math.Sqrt(s)) - - // sort all entries by first dimension - sortByDim(0, entries) - - tree.height = int(h) - tree.size = n - tree.root = tree.omt(int(h), int(S), entries, int(s)) -} - -// omt is the recursive part of the Overlap Minimizing Top-loading bulk- -// load approach. Returns the root node of a subtree. -func (tree *Rtree) omt(level, nSlices int, objs []entry, m int) *node { - // if number of objects is less than or equal than max children per leaf, - // we need to create a leaf node - if len(objs) <= m { - // as long as the recursion is not at the leaf, call it again - if level > 1 { - child := tree.omt(level-1, nSlices, objs, m) - n := &node{ - level: level, - entries: []entry{{ - bb: child.computeBoundingBox(), - child: child, - }}, - } - child.parent = n - return n - } - return &node{ - leaf: true, - entries: objs, - level: level, - } - } - - n := &node{ - level: level, - entries: make([]entry, 0, m), - } - - // maximum node size given at most M nodes at this level - k := (len(objs) + m - 1) / m // = ceil(N / M) - - // In the root level, split objs in nSlices. In all other levels, - // we use a single slice. - vertSize := len(objs) - if nSlices > 1 { - vertSize = nSlices * k - } - - // create sub trees - walkPartitions(vertSize, objs, func(vert []entry) { - // sort vertical slice by a different dimension on every level - sortByDim((tree.height-level+1)%tree.Dim, vert) - - // split slice into groups of size k - walkPartitions(k, vert, func(part []entry) { - child := tree.omt(level-1, 1, part, tree.MaxChildren) - child.parent = n - - n.entries = append(n.entries, entry{ - bb: child.computeBoundingBox(), - child: child, - }) - }) - }) - return n -} - -// node represents a tree node of an Rtree. -type node struct { - parent *node - leaf bool - entries []entry - level int // node depth in the Rtree -} - -func (n *node) String() string { - return fmt.Sprintf("node{leaf: %v, entries: %v}", n.leaf, n.entries) -} - -// entry represents a spatial index record stored in a tree node. -type entry struct { - bb *Rect // bounding-box of all children of this entry - child *node - obj Spatial -} - -func (e entry) String() string { - if e.child != nil { - return fmt.Sprintf("entry{bb: %v, child: %v}", e.bb, e.child) - } - return fmt.Sprintf("entry{bb: %v, obj: %v}", e.bb, e.obj) -} - -// Spatial is an interface for objects that can be stored in an Rtree and queried. -type Spatial interface { - Bounds() *Rect -} - -// Insertion - -// Insert inserts a spatial object into the tree. If insertion -// causes a leaf node to overflow, the tree is rebalanced automatically. -// -// Implemented per Section 3.2 of "R-trees: A Dynamic Index Structure for -// Spatial Searching" by A. Guttman, Proceedings of ACM SIGMOD, p. 47-57, 1984. -func (tree *Rtree) Insert(obj Spatial) { - e := entry{obj.Bounds(), nil, obj} - tree.insert(e, 1) - tree.size++ -} - -// insert adds the specified entry to the tree at the specified level. -func (tree *Rtree) insert(e entry, level int) { - leaf := tree.chooseNode(tree.root, e, level) - leaf.entries = append(leaf.entries, e) - - // update parent pointer if necessary - if e.child != nil { - e.child.parent = leaf - } - - // split leaf if overflows - var split *node - if len(leaf.entries) > tree.MaxChildren { - leaf, split = leaf.split(tree.MinChildren) - } - root, splitRoot := tree.adjustTree(leaf, split) - if splitRoot != nil { - oldRoot := root - tree.height++ - tree.root = &node{ - parent: nil, - level: tree.height, - entries: []entry{ - {bb: oldRoot.computeBoundingBox(), child: oldRoot}, - {bb: splitRoot.computeBoundingBox(), child: splitRoot}, - }, - } - oldRoot.parent = tree.root - splitRoot.parent = tree.root - } -} - -// chooseNode finds the node at the specified level to which e should be added. -func (tree *Rtree) chooseNode(n *node, e entry, level int) *node { - if n.leaf || n.level == level { - return n - } - - // find the entry whose bb needs least enlargement to include obj - diff := math.MaxFloat64 - var chosen entry - for _, en := range n.entries { - bb := boundingBox(en.bb, e.bb) - d := bb.Size() - en.bb.Size() - if d < diff || (d == diff && en.bb.Size() < chosen.bb.Size()) { - diff = d - chosen = en - } - } - - return tree.chooseNode(chosen.child, e, level) -} - -// adjustTree splits overflowing nodes and propagates the changes upwards. -func (tree *Rtree) adjustTree(n, nn *node) (*node, *node) { - // Let the caller handle root adjustments. - if n == tree.root { - return n, nn - } - - // Re-size the bounding box of n to account for lower-level changes. - en := n.getEntry() - en.bb = n.computeBoundingBox() - - // If nn is nil, then we're just propagating changes upwards. - if nn == nil { - return tree.adjustTree(n.parent, nil) - } - - // Otherwise, these are two nodes resulting from a split. - // n was reused as the "left" node, but we need to add nn to n.parent. - enn := entry{nn.computeBoundingBox(), nn, nil} - n.parent.entries = append(n.parent.entries, enn) - - // If the new entry overflows the parent, split the parent and propagate. - if len(n.parent.entries) > tree.MaxChildren { - return tree.adjustTree(n.parent.split(tree.MinChildren)) - } - - // Otherwise keep propagating changes upwards. - return tree.adjustTree(n.parent, nil) -} - -// getEntry returns a pointer to the entry for the node n from n's parent. -func (n *node) getEntry() *entry { - var e *entry - for i := range n.parent.entries { - if n.parent.entries[i].child == n { - e = &n.parent.entries[i] - break - } - } - return e -} - -// computeBoundingBox finds the MBR of the children of n. -func (n *node) computeBoundingBox() (bb *Rect) { - childBoxes := make([]*Rect, len(n.entries)) - for i, e := range n.entries { - childBoxes[i] = e.bb - } - bb = boundingBoxN(childBoxes...) - return -} - -// split splits a node into two groups while attempting to minimize the -// bounding-box area of the resulting groups. -func (n *node) split(minGroupSize int) (left, right *node) { - // find the initial split - l, r := n.pickSeeds() - leftSeed, rightSeed := n.entries[l], n.entries[r] - - // get the entries to be divided between left and right - remaining := append(n.entries[:l], n.entries[l+1:r]...) - remaining = append(remaining, n.entries[r+1:]...) - - // setup the new split nodes, but re-use n as the left node - left = n - left.entries = []entry{leftSeed} - right = &node{ - parent: n.parent, - leaf: n.leaf, - level: n.level, - entries: []entry{rightSeed}, - } - - // TODO - if rightSeed.child != nil { - rightSeed.child.parent = right - } - if leftSeed.child != nil { - leftSeed.child.parent = left - } - - // distribute all of n's old entries into left and right. - for len(remaining) > 0 { - next := pickNext(left, right, remaining) - e := remaining[next] - - if len(remaining)+len(left.entries) <= minGroupSize { - assign(e, left) - } else if len(remaining)+len(right.entries) <= minGroupSize { - assign(e, right) - } else { - assignGroup(e, left, right) - } - - remaining = append(remaining[:next], remaining[next+1:]...) - } - - return -} - -// getAllBoundingBoxes traverses tree populating slice of bounding boxes of non-leaf nodes. -func (n *node) getAllBoundingBoxes() []*Rect { - var rects []*Rect - if n.leaf { - return rects - } - for _, e := range n.entries { - if e.child == nil { - return rects - } - rectsInter := append(e.child.getAllBoundingBoxes(), e.bb) - rects = append(rects, rectsInter...) - } - return rects -} - -func assign(e entry, group *node) { - if e.child != nil { - e.child.parent = group - } - group.entries = append(group.entries, e) -} - -// assignGroup chooses one of two groups to which a node should be added. -func assignGroup(e entry, left, right *node) { - leftBB := left.computeBoundingBox() - rightBB := right.computeBoundingBox() - leftEnlarged := boundingBox(leftBB, e.bb) - rightEnlarged := boundingBox(rightBB, e.bb) - - // first, choose the group that needs the least enlargement - leftDiff := leftEnlarged.Size() - leftBB.Size() - rightDiff := rightEnlarged.Size() - rightBB.Size() - if diff := leftDiff - rightDiff; diff < 0 { - assign(e, left) - return - } else if diff > 0 { - assign(e, right) - return - } - - // next, choose the group that has smaller area - if diff := leftBB.Size() - rightBB.Size(); diff < 0 { - assign(e, left) - return - } else if diff > 0 { - assign(e, right) - return - } - - // next, choose the group with fewer entries - if diff := len(left.entries) - len(right.entries); diff <= 0 { - assign(e, left) - return - } - assign(e, right) -} - -// pickSeeds chooses two child entries of n to start a split. -func (n *node) pickSeeds() (int, int) { - left, right := 0, 1 - maxWastedSpace := -1.0 - for i, e1 := range n.entries { - for j, e2 := range n.entries[i+1:] { - d := boundingBox(e1.bb, e2.bb).Size() - e1.bb.Size() - e2.bb.Size() - if d > maxWastedSpace { - maxWastedSpace = d - left, right = i, j+i+1 - } - } - } - return left, right -} - -// pickNext chooses an entry to be added to an entry group. -func pickNext(left, right *node, entries []entry) (next int) { - maxDiff := -1.0 - leftBB := left.computeBoundingBox() - rightBB := right.computeBoundingBox() - for i, e := range entries { - d1 := boundingBox(leftBB, e.bb).Size() - leftBB.Size() - d2 := boundingBox(rightBB, e.bb).Size() - rightBB.Size() - d := math.Abs(d1 - d2) - if d > maxDiff { - maxDiff = d - next = i - } - } - return -} - -// Deletion - -// Delete removes an object from the tree. If the object is not found, returns -// false, otherwise returns true. Uses the default comparator when checking -// equality. -// -// Implemented per Section 3.3 of "R-trees: A Dynamic Index Structure for -// Spatial Searching" by A. Guttman, Proceedings of ACM SIGMOD, p. 47-57, 1984. -func (tree *Rtree) Delete(obj Spatial) bool { - return tree.DeleteWithComparator(obj, defaultComparator) -} - -// DeleteWithComparator removes an object from the tree using a custom -// comparator for evaluating equalness. This is useful when you want to remove -// an object from a tree but don't have a pointer to the original object -// anymore. -func (tree *Rtree) DeleteWithComparator(obj Spatial, cmp Comparator) bool { - n := tree.findLeaf(tree.root, obj, cmp) - if n == nil { - return false - } - - ind := -1 - for i, e := range n.entries { - if cmp(e.obj, obj) { - ind = i - } - } - if ind < 0 { - return false - } - - n.entries = append(n.entries[:ind], n.entries[ind+1:]...) - - tree.condenseTree(n) - tree.size-- - - if !tree.root.leaf && len(tree.root.entries) == 1 { - tree.root = tree.root.entries[0].child - } - - tree.height = tree.root.level - - return true -} - -// findLeaf finds the leaf node containing obj. -func (tree *Rtree) findLeaf(n *node, obj Spatial, cmp Comparator) *node { - if n.leaf { - return n - } - // if not leaf, search all candidate subtrees - for _, e := range n.entries { - if e.bb.containsRect(obj.Bounds()) { - leaf := tree.findLeaf(e.child, obj, cmp) - if leaf == nil { - continue - } - // check if the leaf actually contains the object - for _, leafEntry := range leaf.entries { - if cmp(leafEntry.obj, obj) { - return leaf - } - } - } - } - return nil -} - -// condenseTree deletes underflowing nodes and propagates the changes upwards. -func (tree *Rtree) condenseTree(n *node) { - deleted := []*node{} - - for n != tree.root { - if len(n.entries) < tree.MinChildren { - // remove n from parent entries - entries := []entry{} - for _, e := range n.parent.entries { - if e.child != n { - entries = append(entries, e) - } - } - if len(n.parent.entries) == len(entries) { - panic(fmt.Errorf("Failed to remove entry from parent")) - } - n.parent.entries = entries - - // only add n to deleted if it still has children - if len(n.entries) > 0 { - deleted = append(deleted, n) - } - } else { - // just a child entry deletion, no underflow - n.getEntry().bb = n.computeBoundingBox() - } - n = n.parent - } - - for _, n := range deleted { - // reinsert entry so that it will remain at the same level as before - e := entry{n.computeBoundingBox(), n, nil} - tree.insert(e, n.level+1) - } -} - -// Searching - -// SearchIntersect returns all objects that intersect the specified rectangle. -// Implemented per Section 3.1 of "R-trees: A Dynamic Index Structure for -// Spatial Searching" by A. Guttman, Proceedings of ACM SIGMOD, p. 47-57, 1984. -func (tree *Rtree) SearchIntersect(bb *Rect, filters ...Filter) []Spatial { - return tree.searchIntersect([]Spatial{}, tree.root, bb, filters) -} - -// SearchIntersectWithLimit is similar to SearchIntersect, but returns -// immediately when the first k results are found. A negative k behaves exactly -// like SearchIntersect and returns all the results. -// -// Kept for backwards compatibility, please use SearchIntersect with a -// LimitFilter. -func (tree *Rtree) SearchIntersectWithLimit(k int, bb *Rect) []Spatial { - // backwards compatibility, previous implementation didn't limit results if - // k was negative. - if k < 0 { - return tree.SearchIntersect(bb) - } - return tree.SearchIntersect(bb, LimitFilter(k)) -} - -func (tree *Rtree) searchIntersect(results []Spatial, n *node, bb *Rect, filters []Filter) []Spatial { - for _, e := range n.entries { - if !intersect(e.bb, bb) { - continue - } - - if !n.leaf { - results = tree.searchIntersect(results, e.child, bb, filters) - continue - } - - refuse, abort := applyFilters(results, e.obj, filters) - if !refuse { - results = append(results, e.obj) - } - - if abort { - break - } - } - return results -} - -// NearestNeighbor returns the closest object to the specified point. -// Implemented per "Nearest Neighbor Queries" by Roussopoulos et al -func (tree *Rtree) NearestNeighbor(p Point) Spatial { - obj, _ := tree.nearestNeighbor(p, tree.root, math.MaxFloat64, nil) - return obj -} - -// GetAllBoundingBoxes returning slice of bounding boxes by traversing tree. Slice -// includes bounding boxes from all non-leaf nodes. -func (tree *Rtree) GetAllBoundingBoxes() []*Rect { - var rects []*Rect - if tree.root != nil { - rects = tree.root.getAllBoundingBoxes() - } - return rects -} - -// utilities for sorting slices of entries - -type entrySlice struct { - entries []entry - dists []float64 -} - -func (s entrySlice) Len() int { return len(s.entries) } - -func (s entrySlice) Swap(i, j int) { - s.entries[i], s.entries[j] = s.entries[j], s.entries[i] - s.dists[i], s.dists[j] = s.dists[j], s.dists[i] -} - -func (s entrySlice) Less(i, j int) bool { - return s.dists[i] < s.dists[j] -} - -func sortEntries(p Point, entries []entry) ([]entry, []float64) { - sorted := make([]entry, len(entries)) - dists := make([]float64, len(entries)) - return sortPreallocEntries(p, entries, sorted, dists) -} - -func sortPreallocEntries(p Point, entries, sorted []entry, dists []float64) ([]entry, []float64) { - // use preallocated slices - sorted = sorted[:len(entries)] - dists = dists[:len(entries)] - - for i := 0; i < len(entries); i++ { - sorted[i] = entries[i] - dists[i] = p.minDist(entries[i].bb) - } - sort.Sort(entrySlice{sorted, dists}) - return sorted, dists -} - -func pruneEntries(p Point, entries []entry, minDists []float64) []entry { - minMinMaxDist := math.MaxFloat64 - for i := range entries { - minMaxDist := p.minMaxDist(entries[i].bb) - if minMaxDist < minMinMaxDist { - minMinMaxDist = minMaxDist - } - } - // remove all entries with minDist > minMinMaxDist - pruned := []entry{} - for i := range entries { - if minDists[i] <= minMinMaxDist { - pruned = append(pruned, entries[i]) - } - } - return pruned -} - -func pruneEntriesMinDist(d float64, entries []entry, minDists []float64) []entry { - var i int - for ; i < len(entries); i++ { - if minDists[i] > d { - break - } - } - return entries[:i] -} - -func (tree *Rtree) nearestNeighbor(p Point, n *node, d float64, nearest Spatial) (Spatial, float64) { - if n.leaf { - for _, e := range n.entries { - dist := math.Sqrt(p.minDist(e.bb)) - if dist < d { - d = dist - nearest = e.obj - } - } - } else { - branches, dists := sortEntries(p, n.entries) - branches = pruneEntries(p, branches, dists) - for _, e := range branches { - subNearest, dist := tree.nearestNeighbor(p, e.child, d, nearest) - if dist < d { - d = dist - nearest = subNearest - } - } - } - - return nearest, d -} - -// NearestNeighbors gets the closest Spatials to the Point. -func (tree *Rtree) NearestNeighbors(k int, p Point, filters ...Filter) []Spatial { - // preallocate the buffers for sortings the branches. At each level of the - // tree, we slide the buffer by the number of entries in the node. - maxBufSize := tree.MaxChildren * tree.Depth() - branches := make([]entry, maxBufSize) - branchDists := make([]float64, maxBufSize) - - // allocate the buffers for the results - dists := make([]float64, 0, k) - objs := make([]Spatial, 0, k) - - objs, _, _ = tree.nearestNeighbors(k, p, tree.root, dists, objs, filters, branches, branchDists) - return objs -} - -// insert obj into nearest and return the first k elements in increasing order. -func insertNearest(k int, dists []float64, nearest []Spatial, dist float64, obj Spatial, filters []Filter) ([]float64, []Spatial, bool) { - i := sort.SearchFloat64s(dists, dist) - for i < len(nearest) && dist >= dists[i] { - i++ - } - if i >= k { - return dists, nearest, false - } - - if refuse, abort := applyFilters(nearest, obj, filters); refuse || abort { - return dists, nearest, abort - } - - // no resize since cap = k - if len(nearest) < k { - dists = append(dists, 0) - nearest = append(nearest, nil) - } - - left, right := dists[:i], dists[i:len(dists)-1] - copy(dists, left) - copy(dists[i+1:], right) - dists[i] = dist - - leftObjs, rightObjs := nearest[:i], nearest[i:len(nearest)-1] - copy(nearest, leftObjs) - copy(nearest[i+1:], rightObjs) - nearest[i] = obj - - return dists, nearest, false -} - -func (tree *Rtree) nearestNeighbors(k int, p Point, n *node, dists []float64, nearest []Spatial, filters []Filter, b []entry, bd []float64) ([]Spatial, []float64, bool) { - var abort bool - if n.leaf { - for _, e := range n.entries { - dist := p.minDist(e.bb) - dists, nearest, abort = insertNearest(k, dists, nearest, dist, e.obj, filters) - if abort { - break - } - } - } else { - branches, branchDists := sortPreallocEntries(p, n.entries, b, bd) - // only prune if buffer has k elements - if l := len(dists); l >= k { - branches = pruneEntriesMinDist(dists[l-1], branches, branchDists) - } - for _, e := range branches { - nearest, dists, abort = tree.nearestNeighbors(k, p, e.child, dists, nearest, filters, b[len(n.entries):], bd[len(n.entries):]) - if abort { - break - } - } - } - return nearest, dists, abort -} diff --git a/vendor/github.com/patrickmn/go-cache/CONTRIBUTORS b/vendor/github.com/patrickmn/go-cache/CONTRIBUTORS deleted file mode 100644 index 2b16e99..0000000 --- a/vendor/github.com/patrickmn/go-cache/CONTRIBUTORS +++ /dev/null @@ -1,9 +0,0 @@ -This is a list of people who have contributed code to go-cache. They, or their -employers, are the copyright holders of the contributed code. Contributed code -is subject to the license restrictions listed in LICENSE (as they were when the -code was contributed.) - -Dustin Sallings -Jason Mooberry -Sergey Shepelev -Alex Edwards diff --git a/vendor/github.com/patrickmn/go-cache/LICENSE b/vendor/github.com/patrickmn/go-cache/LICENSE deleted file mode 100644 index db9903c..0000000 --- a/vendor/github.com/patrickmn/go-cache/LICENSE +++ /dev/null @@ -1,19 +0,0 @@ -Copyright (c) 2012-2017 Patrick Mylund Nielsen and the go-cache contributors - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. diff --git a/vendor/github.com/patrickmn/go-cache/README.md b/vendor/github.com/patrickmn/go-cache/README.md deleted file mode 100644 index c5789cc..0000000 --- a/vendor/github.com/patrickmn/go-cache/README.md +++ /dev/null @@ -1,83 +0,0 @@ -# go-cache - -go-cache is an in-memory key:value store/cache similar to memcached that is -suitable for applications running on a single machine. Its major advantage is -that, being essentially a thread-safe `map[string]interface{}` with expiration -times, it doesn't need to serialize or transmit its contents over the network. - -Any object can be stored, for a given duration or forever, and the cache can be -safely used by multiple goroutines. - -Although go-cache isn't meant to be used as a persistent datastore, the entire -cache can be saved to and loaded from a file (using `c.Items()` to retrieve the -items map to serialize, and `NewFrom()` to create a cache from a deserialized -one) to recover from downtime quickly. (See the docs for `NewFrom()` for caveats.) - -### Installation - -`go get github.com/patrickmn/go-cache` - -### Usage - -```go -import ( - "fmt" - "github.com/patrickmn/go-cache" - "time" -) - -func main() { - // Create a cache with a default expiration time of 5 minutes, and which - // purges expired items every 10 minutes - c := cache.New(5*time.Minute, 10*time.Minute) - - // Set the value of the key "foo" to "bar", with the default expiration time - c.Set("foo", "bar", cache.DefaultExpiration) - - // Set the value of the key "baz" to 42, with no expiration time - // (the item won't be removed until it is re-set, or removed using - // c.Delete("baz") - c.Set("baz", 42, cache.NoExpiration) - - // Get the string associated with the key "foo" from the cache - foo, found := c.Get("foo") - if found { - fmt.Println(foo) - } - - // Since Go is statically typed, and cache values can be anything, type - // assertion is needed when values are being passed to functions that don't - // take arbitrary types, (i.e. interface{}). The simplest way to do this for - // values which will only be used once--e.g. for passing to another - // function--is: - foo, found := c.Get("foo") - if found { - MyFunction(foo.(string)) - } - - // This gets tedious if the value is used several times in the same function. - // You might do either of the following instead: - if x, found := c.Get("foo"); found { - foo := x.(string) - // ... - } - // or - var foo string - if x, found := c.Get("foo"); found { - foo = x.(string) - } - // ... - // foo can then be passed around freely as a string - - // Want performance? Store pointers! - c.Set("foo", &MyStruct, cache.DefaultExpiration) - if x, found := c.Get("foo"); found { - foo := x.(*MyStruct) - // ... - } -} -``` - -### Reference - -`godoc` or [http://godoc.org/github.com/patrickmn/go-cache](http://godoc.org/github.com/patrickmn/go-cache) diff --git a/vendor/github.com/patrickmn/go-cache/cache.go b/vendor/github.com/patrickmn/go-cache/cache.go deleted file mode 100644 index db88d2f..0000000 --- a/vendor/github.com/patrickmn/go-cache/cache.go +++ /dev/null @@ -1,1161 +0,0 @@ -package cache - -import ( - "encoding/gob" - "fmt" - "io" - "os" - "runtime" - "sync" - "time" -) - -type Item struct { - Object interface{} - Expiration int64 -} - -// Returns true if the item has expired. -func (item Item) Expired() bool { - if item.Expiration == 0 { - return false - } - return time.Now().UnixNano() > item.Expiration -} - -const ( - // For use with functions that take an expiration time. - NoExpiration time.Duration = -1 - // For use with functions that take an expiration time. Equivalent to - // passing in the same expiration duration as was given to New() or - // NewFrom() when the cache was created (e.g. 5 minutes.) - DefaultExpiration time.Duration = 0 -) - -type Cache struct { - *cache - // If this is confusing, see the comment at the bottom of New() -} - -type cache struct { - defaultExpiration time.Duration - items map[string]Item - mu sync.RWMutex - onEvicted func(string, interface{}) - janitor *janitor -} - -// Add an item to the cache, replacing any existing item. If the duration is 0 -// (DefaultExpiration), the cache's default expiration time is used. If it is -1 -// (NoExpiration), the item never expires. -func (c *cache) Set(k string, x interface{}, d time.Duration) { - // "Inlining" of set - var e int64 - if d == DefaultExpiration { - d = c.defaultExpiration - } - if d > 0 { - e = time.Now().Add(d).UnixNano() - } - c.mu.Lock() - c.items[k] = Item{ - Object: x, - Expiration: e, - } - // TODO: Calls to mu.Unlock are currently not deferred because defer - // adds ~200 ns (as of go1.) - c.mu.Unlock() -} - -func (c *cache) set(k string, x interface{}, d time.Duration) { - var e int64 - if d == DefaultExpiration { - d = c.defaultExpiration - } - if d > 0 { - e = time.Now().Add(d).UnixNano() - } - c.items[k] = Item{ - Object: x, - Expiration: e, - } -} - -// Add an item to the cache, replacing any existing item, using the default -// expiration. -func (c *cache) SetDefault(k string, x interface{}) { - c.Set(k, x, DefaultExpiration) -} - -// Add an item to the cache only if an item doesn't already exist for the given -// key, or if the existing item has expired. Returns an error otherwise. -func (c *cache) Add(k string, x interface{}, d time.Duration) error { - c.mu.Lock() - _, found := c.get(k) - if found { - c.mu.Unlock() - return fmt.Errorf("Item %s already exists", k) - } - c.set(k, x, d) - c.mu.Unlock() - return nil -} - -// Set a new value for the cache key only if it already exists, and the existing -// item hasn't expired. Returns an error otherwise. -func (c *cache) Replace(k string, x interface{}, d time.Duration) error { - c.mu.Lock() - _, found := c.get(k) - if !found { - c.mu.Unlock() - return fmt.Errorf("Item %s doesn't exist", k) - } - c.set(k, x, d) - c.mu.Unlock() - return nil -} - -// Get an item from the cache. Returns the item or nil, and a bool indicating -// whether the key was found. -func (c *cache) Get(k string) (interface{}, bool) { - c.mu.RLock() - // "Inlining" of get and Expired - item, found := c.items[k] - if !found { - c.mu.RUnlock() - return nil, false - } - if item.Expiration > 0 { - if time.Now().UnixNano() > item.Expiration { - c.mu.RUnlock() - return nil, false - } - } - c.mu.RUnlock() - return item.Object, true -} - -// GetWithExpiration returns an item and its expiration time from the cache. -// It returns the item or nil, the expiration time if one is set (if the item -// never expires a zero value for time.Time is returned), and a bool indicating -// whether the key was found. -func (c *cache) GetWithExpiration(k string) (interface{}, time.Time, bool) { - c.mu.RLock() - // "Inlining" of get and Expired - item, found := c.items[k] - if !found { - c.mu.RUnlock() - return nil, time.Time{}, false - } - - if item.Expiration > 0 { - if time.Now().UnixNano() > item.Expiration { - c.mu.RUnlock() - return nil, time.Time{}, false - } - - // Return the item and the expiration time - c.mu.RUnlock() - return item.Object, time.Unix(0, item.Expiration), true - } - - // If expiration <= 0 (i.e. no expiration time set) then return the item - // and a zeroed time.Time - c.mu.RUnlock() - return item.Object, time.Time{}, true -} - -func (c *cache) get(k string) (interface{}, bool) { - item, found := c.items[k] - if !found { - return nil, false - } - // "Inlining" of Expired - if item.Expiration > 0 { - if time.Now().UnixNano() > item.Expiration { - return nil, false - } - } - return item.Object, true -} - -// Increment an item of type int, int8, int16, int32, int64, uintptr, uint, -// uint8, uint32, or uint64, float32 or float64 by n. Returns an error if the -// item's value is not an integer, if it was not found, or if it is not -// possible to increment it by n. To retrieve the incremented value, use one -// of the specialized methods, e.g. IncrementInt64. -func (c *cache) Increment(k string, n int64) error { - c.mu.Lock() - v, found := c.items[k] - if !found || v.Expired() { - c.mu.Unlock() - return fmt.Errorf("Item %s not found", k) - } - switch v.Object.(type) { - case int: - v.Object = v.Object.(int) + int(n) - case int8: - v.Object = v.Object.(int8) + int8(n) - case int16: - v.Object = v.Object.(int16) + int16(n) - case int32: - v.Object = v.Object.(int32) + int32(n) - case int64: - v.Object = v.Object.(int64) + n - case uint: - v.Object = v.Object.(uint) + uint(n) - case uintptr: - v.Object = v.Object.(uintptr) + uintptr(n) - case uint8: - v.Object = v.Object.(uint8) + uint8(n) - case uint16: - v.Object = v.Object.(uint16) + uint16(n) - case uint32: - v.Object = v.Object.(uint32) + uint32(n) - case uint64: - v.Object = v.Object.(uint64) + uint64(n) - case float32: - v.Object = v.Object.(float32) + float32(n) - case float64: - v.Object = v.Object.(float64) + float64(n) - default: - c.mu.Unlock() - return fmt.Errorf("The value for %s is not an integer", k) - } - c.items[k] = v - c.mu.Unlock() - return nil -} - -// Increment an item of type float32 or float64 by n. Returns an error if the -// item's value is not floating point, if it was not found, or if it is not -// possible to increment it by n. Pass a negative number to decrement the -// value. To retrieve the incremented value, use one of the specialized methods, -// e.g. IncrementFloat64. -func (c *cache) IncrementFloat(k string, n float64) error { - c.mu.Lock() - v, found := c.items[k] - if !found || v.Expired() { - c.mu.Unlock() - return fmt.Errorf("Item %s not found", k) - } - switch v.Object.(type) { - case float32: - v.Object = v.Object.(float32) + float32(n) - case float64: - v.Object = v.Object.(float64) + n - default: - c.mu.Unlock() - return fmt.Errorf("The value for %s does not have type float32 or float64", k) - } - c.items[k] = v - c.mu.Unlock() - return nil -} - -// Increment an item of type int by n. Returns an error if the item's value is -// not an int, or if it was not found. If there is no error, the incremented -// value is returned. -func (c *cache) IncrementInt(k string, n int) (int, error) { - c.mu.Lock() - v, found := c.items[k] - if !found || v.Expired() { - c.mu.Unlock() - return 0, fmt.Errorf("Item %s not found", k) - } - rv, ok := v.Object.(int) - if !ok { - c.mu.Unlock() - return 0, fmt.Errorf("The value for %s is not an int", k) - } - nv := rv + n - v.Object = nv - c.items[k] = v - c.mu.Unlock() - return nv, nil -} - -// Increment an item of type int8 by n. Returns an error if the item's value is -// not an int8, or if it was not found. If there is no error, the incremented -// value is returned. -func (c *cache) IncrementInt8(k string, n int8) (int8, error) { - c.mu.Lock() - v, found := c.items[k] - if !found || v.Expired() { - c.mu.Unlock() - return 0, fmt.Errorf("Item %s not found", k) - } - rv, ok := v.Object.(int8) - if !ok { - c.mu.Unlock() - return 0, fmt.Errorf("The value for %s is not an int8", k) - } - nv := rv + n - v.Object = nv - c.items[k] = v - c.mu.Unlock() - return nv, nil -} - -// Increment an item of type int16 by n. Returns an error if the item's value is -// not an int16, or if it was not found. If there is no error, the incremented -// value is returned. -func (c *cache) IncrementInt16(k string, n int16) (int16, error) { - c.mu.Lock() - v, found := c.items[k] - if !found || v.Expired() { - c.mu.Unlock() - return 0, fmt.Errorf("Item %s not found", k) - } - rv, ok := v.Object.(int16) - if !ok { - c.mu.Unlock() - return 0, fmt.Errorf("The value for %s is not an int16", k) - } - nv := rv + n - v.Object = nv - c.items[k] = v - c.mu.Unlock() - return nv, nil -} - -// Increment an item of type int32 by n. Returns an error if the item's value is -// not an int32, or if it was not found. If there is no error, the incremented -// value is returned. -func (c *cache) IncrementInt32(k string, n int32) (int32, error) { - c.mu.Lock() - v, found := c.items[k] - if !found || v.Expired() { - c.mu.Unlock() - return 0, fmt.Errorf("Item %s not found", k) - } - rv, ok := v.Object.(int32) - if !ok { - c.mu.Unlock() - return 0, fmt.Errorf("The value for %s is not an int32", k) - } - nv := rv + n - v.Object = nv - c.items[k] = v - c.mu.Unlock() - return nv, nil -} - -// Increment an item of type int64 by n. Returns an error if the item's value is -// not an int64, or if it was not found. If there is no error, the incremented -// value is returned. -func (c *cache) IncrementInt64(k string, n int64) (int64, error) { - c.mu.Lock() - v, found := c.items[k] - if !found || v.Expired() { - c.mu.Unlock() - return 0, fmt.Errorf("Item %s not found", k) - } - rv, ok := v.Object.(int64) - if !ok { - c.mu.Unlock() - return 0, fmt.Errorf("The value for %s is not an int64", k) - } - nv := rv + n - v.Object = nv - c.items[k] = v - c.mu.Unlock() - return nv, nil -} - -// Increment an item of type uint by n. Returns an error if the item's value is -// not an uint, or if it was not found. If there is no error, the incremented -// value is returned. -func (c *cache) IncrementUint(k string, n uint) (uint, error) { - c.mu.Lock() - v, found := c.items[k] - if !found || v.Expired() { - c.mu.Unlock() - return 0, fmt.Errorf("Item %s not found", k) - } - rv, ok := v.Object.(uint) - if !ok { - c.mu.Unlock() - return 0, fmt.Errorf("The value for %s is not an uint", k) - } - nv := rv + n - v.Object = nv - c.items[k] = v - c.mu.Unlock() - return nv, nil -} - -// Increment an item of type uintptr by n. Returns an error if the item's value -// is not an uintptr, or if it was not found. If there is no error, the -// incremented value is returned. -func (c *cache) IncrementUintptr(k string, n uintptr) (uintptr, error) { - c.mu.Lock() - v, found := c.items[k] - if !found || v.Expired() { - c.mu.Unlock() - return 0, fmt.Errorf("Item %s not found", k) - } - rv, ok := v.Object.(uintptr) - if !ok { - c.mu.Unlock() - return 0, fmt.Errorf("The value for %s is not an uintptr", k) - } - nv := rv + n - v.Object = nv - c.items[k] = v - c.mu.Unlock() - return nv, nil -} - -// Increment an item of type uint8 by n. Returns an error if the item's value -// is not an uint8, or if it was not found. If there is no error, the -// incremented value is returned. -func (c *cache) IncrementUint8(k string, n uint8) (uint8, error) { - c.mu.Lock() - v, found := c.items[k] - if !found || v.Expired() { - c.mu.Unlock() - return 0, fmt.Errorf("Item %s not found", k) - } - rv, ok := v.Object.(uint8) - if !ok { - c.mu.Unlock() - return 0, fmt.Errorf("The value for %s is not an uint8", k) - } - nv := rv + n - v.Object = nv - c.items[k] = v - c.mu.Unlock() - return nv, nil -} - -// Increment an item of type uint16 by n. Returns an error if the item's value -// is not an uint16, or if it was not found. If there is no error, the -// incremented value is returned. -func (c *cache) IncrementUint16(k string, n uint16) (uint16, error) { - c.mu.Lock() - v, found := c.items[k] - if !found || v.Expired() { - c.mu.Unlock() - return 0, fmt.Errorf("Item %s not found", k) - } - rv, ok := v.Object.(uint16) - if !ok { - c.mu.Unlock() - return 0, fmt.Errorf("The value for %s is not an uint16", k) - } - nv := rv + n - v.Object = nv - c.items[k] = v - c.mu.Unlock() - return nv, nil -} - -// Increment an item of type uint32 by n. Returns an error if the item's value -// is not an uint32, or if it was not found. If there is no error, the -// incremented value is returned. -func (c *cache) IncrementUint32(k string, n uint32) (uint32, error) { - c.mu.Lock() - v, found := c.items[k] - if !found || v.Expired() { - c.mu.Unlock() - return 0, fmt.Errorf("Item %s not found", k) - } - rv, ok := v.Object.(uint32) - if !ok { - c.mu.Unlock() - return 0, fmt.Errorf("The value for %s is not an uint32", k) - } - nv := rv + n - v.Object = nv - c.items[k] = v - c.mu.Unlock() - return nv, nil -} - -// Increment an item of type uint64 by n. Returns an error if the item's value -// is not an uint64, or if it was not found. If there is no error, the -// incremented value is returned. -func (c *cache) IncrementUint64(k string, n uint64) (uint64, error) { - c.mu.Lock() - v, found := c.items[k] - if !found || v.Expired() { - c.mu.Unlock() - return 0, fmt.Errorf("Item %s not found", k) - } - rv, ok := v.Object.(uint64) - if !ok { - c.mu.Unlock() - return 0, fmt.Errorf("The value for %s is not an uint64", k) - } - nv := rv + n - v.Object = nv - c.items[k] = v - c.mu.Unlock() - return nv, nil -} - -// Increment an item of type float32 by n. Returns an error if the item's value -// is not an float32, or if it was not found. If there is no error, the -// incremented value is returned. -func (c *cache) IncrementFloat32(k string, n float32) (float32, error) { - c.mu.Lock() - v, found := c.items[k] - if !found || v.Expired() { - c.mu.Unlock() - return 0, fmt.Errorf("Item %s not found", k) - } - rv, ok := v.Object.(float32) - if !ok { - c.mu.Unlock() - return 0, fmt.Errorf("The value for %s is not an float32", k) - } - nv := rv + n - v.Object = nv - c.items[k] = v - c.mu.Unlock() - return nv, nil -} - -// Increment an item of type float64 by n. Returns an error if the item's value -// is not an float64, or if it was not found. If there is no error, the -// incremented value is returned. -func (c *cache) IncrementFloat64(k string, n float64) (float64, error) { - c.mu.Lock() - v, found := c.items[k] - if !found || v.Expired() { - c.mu.Unlock() - return 0, fmt.Errorf("Item %s not found", k) - } - rv, ok := v.Object.(float64) - if !ok { - c.mu.Unlock() - return 0, fmt.Errorf("The value for %s is not an float64", k) - } - nv := rv + n - v.Object = nv - c.items[k] = v - c.mu.Unlock() - return nv, nil -} - -// Decrement an item of type int, int8, int16, int32, int64, uintptr, uint, -// uint8, uint32, or uint64, float32 or float64 by n. Returns an error if the -// item's value is not an integer, if it was not found, or if it is not -// possible to decrement it by n. To retrieve the decremented value, use one -// of the specialized methods, e.g. DecrementInt64. -func (c *cache) Decrement(k string, n int64) error { - // TODO: Implement Increment and Decrement more cleanly. - // (Cannot do Increment(k, n*-1) for uints.) - c.mu.Lock() - v, found := c.items[k] - if !found || v.Expired() { - c.mu.Unlock() - return fmt.Errorf("Item not found") - } - switch v.Object.(type) { - case int: - v.Object = v.Object.(int) - int(n) - case int8: - v.Object = v.Object.(int8) - int8(n) - case int16: - v.Object = v.Object.(int16) - int16(n) - case int32: - v.Object = v.Object.(int32) - int32(n) - case int64: - v.Object = v.Object.(int64) - n - case uint: - v.Object = v.Object.(uint) - uint(n) - case uintptr: - v.Object = v.Object.(uintptr) - uintptr(n) - case uint8: - v.Object = v.Object.(uint8) - uint8(n) - case uint16: - v.Object = v.Object.(uint16) - uint16(n) - case uint32: - v.Object = v.Object.(uint32) - uint32(n) - case uint64: - v.Object = v.Object.(uint64) - uint64(n) - case float32: - v.Object = v.Object.(float32) - float32(n) - case float64: - v.Object = v.Object.(float64) - float64(n) - default: - c.mu.Unlock() - return fmt.Errorf("The value for %s is not an integer", k) - } - c.items[k] = v - c.mu.Unlock() - return nil -} - -// Decrement an item of type float32 or float64 by n. Returns an error if the -// item's value is not floating point, if it was not found, or if it is not -// possible to decrement it by n. Pass a negative number to decrement the -// value. To retrieve the decremented value, use one of the specialized methods, -// e.g. DecrementFloat64. -func (c *cache) DecrementFloat(k string, n float64) error { - c.mu.Lock() - v, found := c.items[k] - if !found || v.Expired() { - c.mu.Unlock() - return fmt.Errorf("Item %s not found", k) - } - switch v.Object.(type) { - case float32: - v.Object = v.Object.(float32) - float32(n) - case float64: - v.Object = v.Object.(float64) - n - default: - c.mu.Unlock() - return fmt.Errorf("The value for %s does not have type float32 or float64", k) - } - c.items[k] = v - c.mu.Unlock() - return nil -} - -// Decrement an item of type int by n. Returns an error if the item's value is -// not an int, or if it was not found. If there is no error, the decremented -// value is returned. -func (c *cache) DecrementInt(k string, n int) (int, error) { - c.mu.Lock() - v, found := c.items[k] - if !found || v.Expired() { - c.mu.Unlock() - return 0, fmt.Errorf("Item %s not found", k) - } - rv, ok := v.Object.(int) - if !ok { - c.mu.Unlock() - return 0, fmt.Errorf("The value for %s is not an int", k) - } - nv := rv - n - v.Object = nv - c.items[k] = v - c.mu.Unlock() - return nv, nil -} - -// Decrement an item of type int8 by n. Returns an error if the item's value is -// not an int8, or if it was not found. If there is no error, the decremented -// value is returned. -func (c *cache) DecrementInt8(k string, n int8) (int8, error) { - c.mu.Lock() - v, found := c.items[k] - if !found || v.Expired() { - c.mu.Unlock() - return 0, fmt.Errorf("Item %s not found", k) - } - rv, ok := v.Object.(int8) - if !ok { - c.mu.Unlock() - return 0, fmt.Errorf("The value for %s is not an int8", k) - } - nv := rv - n - v.Object = nv - c.items[k] = v - c.mu.Unlock() - return nv, nil -} - -// Decrement an item of type int16 by n. Returns an error if the item's value is -// not an int16, or if it was not found. If there is no error, the decremented -// value is returned. -func (c *cache) DecrementInt16(k string, n int16) (int16, error) { - c.mu.Lock() - v, found := c.items[k] - if !found || v.Expired() { - c.mu.Unlock() - return 0, fmt.Errorf("Item %s not found", k) - } - rv, ok := v.Object.(int16) - if !ok { - c.mu.Unlock() - return 0, fmt.Errorf("The value for %s is not an int16", k) - } - nv := rv - n - v.Object = nv - c.items[k] = v - c.mu.Unlock() - return nv, nil -} - -// Decrement an item of type int32 by n. Returns an error if the item's value is -// not an int32, or if it was not found. If there is no error, the decremented -// value is returned. -func (c *cache) DecrementInt32(k string, n int32) (int32, error) { - c.mu.Lock() - v, found := c.items[k] - if !found || v.Expired() { - c.mu.Unlock() - return 0, fmt.Errorf("Item %s not found", k) - } - rv, ok := v.Object.(int32) - if !ok { - c.mu.Unlock() - return 0, fmt.Errorf("The value for %s is not an int32", k) - } - nv := rv - n - v.Object = nv - c.items[k] = v - c.mu.Unlock() - return nv, nil -} - -// Decrement an item of type int64 by n. Returns an error if the item's value is -// not an int64, or if it was not found. If there is no error, the decremented -// value is returned. -func (c *cache) DecrementInt64(k string, n int64) (int64, error) { - c.mu.Lock() - v, found := c.items[k] - if !found || v.Expired() { - c.mu.Unlock() - return 0, fmt.Errorf("Item %s not found", k) - } - rv, ok := v.Object.(int64) - if !ok { - c.mu.Unlock() - return 0, fmt.Errorf("The value for %s is not an int64", k) - } - nv := rv - n - v.Object = nv - c.items[k] = v - c.mu.Unlock() - return nv, nil -} - -// Decrement an item of type uint by n. Returns an error if the item's value is -// not an uint, or if it was not found. If there is no error, the decremented -// value is returned. -func (c *cache) DecrementUint(k string, n uint) (uint, error) { - c.mu.Lock() - v, found := c.items[k] - if !found || v.Expired() { - c.mu.Unlock() - return 0, fmt.Errorf("Item %s not found", k) - } - rv, ok := v.Object.(uint) - if !ok { - c.mu.Unlock() - return 0, fmt.Errorf("The value for %s is not an uint", k) - } - nv := rv - n - v.Object = nv - c.items[k] = v - c.mu.Unlock() - return nv, nil -} - -// Decrement an item of type uintptr by n. Returns an error if the item's value -// is not an uintptr, or if it was not found. If there is no error, the -// decremented value is returned. -func (c *cache) DecrementUintptr(k string, n uintptr) (uintptr, error) { - c.mu.Lock() - v, found := c.items[k] - if !found || v.Expired() { - c.mu.Unlock() - return 0, fmt.Errorf("Item %s not found", k) - } - rv, ok := v.Object.(uintptr) - if !ok { - c.mu.Unlock() - return 0, fmt.Errorf("The value for %s is not an uintptr", k) - } - nv := rv - n - v.Object = nv - c.items[k] = v - c.mu.Unlock() - return nv, nil -} - -// Decrement an item of type uint8 by n. Returns an error if the item's value is -// not an uint8, or if it was not found. If there is no error, the decremented -// value is returned. -func (c *cache) DecrementUint8(k string, n uint8) (uint8, error) { - c.mu.Lock() - v, found := c.items[k] - if !found || v.Expired() { - c.mu.Unlock() - return 0, fmt.Errorf("Item %s not found", k) - } - rv, ok := v.Object.(uint8) - if !ok { - c.mu.Unlock() - return 0, fmt.Errorf("The value for %s is not an uint8", k) - } - nv := rv - n - v.Object = nv - c.items[k] = v - c.mu.Unlock() - return nv, nil -} - -// Decrement an item of type uint16 by n. Returns an error if the item's value -// is not an uint16, or if it was not found. If there is no error, the -// decremented value is returned. -func (c *cache) DecrementUint16(k string, n uint16) (uint16, error) { - c.mu.Lock() - v, found := c.items[k] - if !found || v.Expired() { - c.mu.Unlock() - return 0, fmt.Errorf("Item %s not found", k) - } - rv, ok := v.Object.(uint16) - if !ok { - c.mu.Unlock() - return 0, fmt.Errorf("The value for %s is not an uint16", k) - } - nv := rv - n - v.Object = nv - c.items[k] = v - c.mu.Unlock() - return nv, nil -} - -// Decrement an item of type uint32 by n. Returns an error if the item's value -// is not an uint32, or if it was not found. If there is no error, the -// decremented value is returned. -func (c *cache) DecrementUint32(k string, n uint32) (uint32, error) { - c.mu.Lock() - v, found := c.items[k] - if !found || v.Expired() { - c.mu.Unlock() - return 0, fmt.Errorf("Item %s not found", k) - } - rv, ok := v.Object.(uint32) - if !ok { - c.mu.Unlock() - return 0, fmt.Errorf("The value for %s is not an uint32", k) - } - nv := rv - n - v.Object = nv - c.items[k] = v - c.mu.Unlock() - return nv, nil -} - -// Decrement an item of type uint64 by n. Returns an error if the item's value -// is not an uint64, or if it was not found. If there is no error, the -// decremented value is returned. -func (c *cache) DecrementUint64(k string, n uint64) (uint64, error) { - c.mu.Lock() - v, found := c.items[k] - if !found || v.Expired() { - c.mu.Unlock() - return 0, fmt.Errorf("Item %s not found", k) - } - rv, ok := v.Object.(uint64) - if !ok { - c.mu.Unlock() - return 0, fmt.Errorf("The value for %s is not an uint64", k) - } - nv := rv - n - v.Object = nv - c.items[k] = v - c.mu.Unlock() - return nv, nil -} - -// Decrement an item of type float32 by n. Returns an error if the item's value -// is not an float32, or if it was not found. If there is no error, the -// decremented value is returned. -func (c *cache) DecrementFloat32(k string, n float32) (float32, error) { - c.mu.Lock() - v, found := c.items[k] - if !found || v.Expired() { - c.mu.Unlock() - return 0, fmt.Errorf("Item %s not found", k) - } - rv, ok := v.Object.(float32) - if !ok { - c.mu.Unlock() - return 0, fmt.Errorf("The value for %s is not an float32", k) - } - nv := rv - n - v.Object = nv - c.items[k] = v - c.mu.Unlock() - return nv, nil -} - -// Decrement an item of type float64 by n. Returns an error if the item's value -// is not an float64, or if it was not found. If there is no error, the -// decremented value is returned. -func (c *cache) DecrementFloat64(k string, n float64) (float64, error) { - c.mu.Lock() - v, found := c.items[k] - if !found || v.Expired() { - c.mu.Unlock() - return 0, fmt.Errorf("Item %s not found", k) - } - rv, ok := v.Object.(float64) - if !ok { - c.mu.Unlock() - return 0, fmt.Errorf("The value for %s is not an float64", k) - } - nv := rv - n - v.Object = nv - c.items[k] = v - c.mu.Unlock() - return nv, nil -} - -// Delete an item from the cache. Does nothing if the key is not in the cache. -func (c *cache) Delete(k string) { - c.mu.Lock() - v, evicted := c.delete(k) - c.mu.Unlock() - if evicted { - c.onEvicted(k, v) - } -} - -func (c *cache) delete(k string) (interface{}, bool) { - if c.onEvicted != nil { - if v, found := c.items[k]; found { - delete(c.items, k) - return v.Object, true - } - } - delete(c.items, k) - return nil, false -} - -type keyAndValue struct { - key string - value interface{} -} - -// Delete all expired items from the cache. -func (c *cache) DeleteExpired() { - var evictedItems []keyAndValue - now := time.Now().UnixNano() - c.mu.Lock() - for k, v := range c.items { - // "Inlining" of expired - if v.Expiration > 0 && now > v.Expiration { - ov, evicted := c.delete(k) - if evicted { - evictedItems = append(evictedItems, keyAndValue{k, ov}) - } - } - } - c.mu.Unlock() - for _, v := range evictedItems { - c.onEvicted(v.key, v.value) - } -} - -// Sets an (optional) function that is called with the key and value when an -// item is evicted from the cache. (Including when it is deleted manually, but -// not when it is overwritten.) Set to nil to disable. -func (c *cache) OnEvicted(f func(string, interface{})) { - c.mu.Lock() - c.onEvicted = f - c.mu.Unlock() -} - -// Write the cache's items (using Gob) to an io.Writer. -// -// NOTE: This method is deprecated in favor of c.Items() and NewFrom() (see the -// documentation for NewFrom().) -func (c *cache) Save(w io.Writer) (err error) { - enc := gob.NewEncoder(w) - defer func() { - if x := recover(); x != nil { - err = fmt.Errorf("Error registering item types with Gob library") - } - }() - c.mu.RLock() - defer c.mu.RUnlock() - for _, v := range c.items { - gob.Register(v.Object) - } - err = enc.Encode(&c.items) - return -} - -// Save the cache's items to the given filename, creating the file if it -// doesn't exist, and overwriting it if it does. -// -// NOTE: This method is deprecated in favor of c.Items() and NewFrom() (see the -// documentation for NewFrom().) -func (c *cache) SaveFile(fname string) error { - fp, err := os.Create(fname) - if err != nil { - return err - } - err = c.Save(fp) - if err != nil { - fp.Close() - return err - } - return fp.Close() -} - -// Add (Gob-serialized) cache items from an io.Reader, excluding any items with -// keys that already exist (and haven't expired) in the current cache. -// -// NOTE: This method is deprecated in favor of c.Items() and NewFrom() (see the -// documentation for NewFrom().) -func (c *cache) Load(r io.Reader) error { - dec := gob.NewDecoder(r) - items := map[string]Item{} - err := dec.Decode(&items) - if err == nil { - c.mu.Lock() - defer c.mu.Unlock() - for k, v := range items { - ov, found := c.items[k] - if !found || ov.Expired() { - c.items[k] = v - } - } - } - return err -} - -// Load and add cache items from the given filename, excluding any items with -// keys that already exist in the current cache. -// -// NOTE: This method is deprecated in favor of c.Items() and NewFrom() (see the -// documentation for NewFrom().) -func (c *cache) LoadFile(fname string) error { - fp, err := os.Open(fname) - if err != nil { - return err - } - err = c.Load(fp) - if err != nil { - fp.Close() - return err - } - return fp.Close() -} - -// Copies all unexpired items in the cache into a new map and returns it. -func (c *cache) Items() map[string]Item { - c.mu.RLock() - defer c.mu.RUnlock() - m := make(map[string]Item, len(c.items)) - now := time.Now().UnixNano() - for k, v := range c.items { - // "Inlining" of Expired - if v.Expiration > 0 { - if now > v.Expiration { - continue - } - } - m[k] = v - } - return m -} - -// Returns the number of items in the cache. This may include items that have -// expired, but have not yet been cleaned up. -func (c *cache) ItemCount() int { - c.mu.RLock() - n := len(c.items) - c.mu.RUnlock() - return n -} - -// Delete all items from the cache. -func (c *cache) Flush() { - c.mu.Lock() - c.items = map[string]Item{} - c.mu.Unlock() -} - -type janitor struct { - Interval time.Duration - stop chan bool -} - -func (j *janitor) Run(c *cache) { - ticker := time.NewTicker(j.Interval) - for { - select { - case <-ticker.C: - c.DeleteExpired() - case <-j.stop: - ticker.Stop() - return - } - } -} - -func stopJanitor(c *Cache) { - c.janitor.stop <- true -} - -func runJanitor(c *cache, ci time.Duration) { - j := &janitor{ - Interval: ci, - stop: make(chan bool), - } - c.janitor = j - go j.Run(c) -} - -func newCache(de time.Duration, m map[string]Item) *cache { - if de == 0 { - de = -1 - } - c := &cache{ - defaultExpiration: de, - items: m, - } - return c -} - -func newCacheWithJanitor(de time.Duration, ci time.Duration, m map[string]Item) *Cache { - c := newCache(de, m) - // This trick ensures that the janitor goroutine (which--granted it - // was enabled--is running DeleteExpired on c forever) does not keep - // the returned C object from being garbage collected. When it is - // garbage collected, the finalizer stops the janitor goroutine, after - // which c can be collected. - C := &Cache{c} - if ci > 0 { - runJanitor(c, ci) - runtime.SetFinalizer(C, stopJanitor) - } - return C -} - -// Return a new cache with a given default expiration duration and cleanup -// interval. If the expiration duration is less than one (or NoExpiration), -// the items in the cache never expire (by default), and must be deleted -// manually. If the cleanup interval is less than one, expired items are not -// deleted from the cache before calling c.DeleteExpired(). -func New(defaultExpiration, cleanupInterval time.Duration) *Cache { - items := make(map[string]Item) - return newCacheWithJanitor(defaultExpiration, cleanupInterval, items) -} - -// Return a new cache with a given default expiration duration and cleanup -// interval. If the expiration duration is less than one (or NoExpiration), -// the items in the cache never expire (by default), and must be deleted -// manually. If the cleanup interval is less than one, expired items are not -// deleted from the cache before calling c.DeleteExpired(). -// -// NewFrom() also accepts an items map which will serve as the underlying map -// for the cache. This is useful for starting from a deserialized cache -// (serialized using e.g. gob.Encode() on c.Items()), or passing in e.g. -// make(map[string]Item, 500) to improve startup performance when the cache -// is expected to reach a certain minimum size. -// -// Only the cache's methods synchronize access to this map, so it is not -// recommended to keep any references to the map around after creating a cache. -// If need be, the map can be accessed at a later point using c.Items() (subject -// to the same caveat.) -// -// Note regarding serialization: When using e.g. gob, make sure to -// gob.Register() the individual types stored in the cache before encoding a -// map retrieved with c.Items(), and to register those same types before -// decoding a blob containing an items map. -func NewFrom(defaultExpiration, cleanupInterval time.Duration, items map[string]Item) *Cache { - return newCacheWithJanitor(defaultExpiration, cleanupInterval, items) -} diff --git a/vendor/github.com/patrickmn/go-cache/sharded.go b/vendor/github.com/patrickmn/go-cache/sharded.go deleted file mode 100644 index bcc0538..0000000 --- a/vendor/github.com/patrickmn/go-cache/sharded.go +++ /dev/null @@ -1,192 +0,0 @@ -package cache - -import ( - "crypto/rand" - "math" - "math/big" - insecurerand "math/rand" - "os" - "runtime" - "time" -) - -// This is an experimental and unexported (for now) attempt at making a cache -// with better algorithmic complexity than the standard one, namely by -// preventing write locks of the entire cache when an item is added. As of the -// time of writing, the overhead of selecting buckets results in cache -// operations being about twice as slow as for the standard cache with small -// total cache sizes, and faster for larger ones. -// -// See cache_test.go for a few benchmarks. - -type unexportedShardedCache struct { - *shardedCache -} - -type shardedCache struct { - seed uint32 - m uint32 - cs []*cache - janitor *shardedJanitor -} - -// djb2 with better shuffling. 5x faster than FNV with the hash.Hash overhead. -func djb33(seed uint32, k string) uint32 { - var ( - l = uint32(len(k)) - d = 5381 + seed + l - i = uint32(0) - ) - // Why is all this 5x faster than a for loop? - if l >= 4 { - for i < l-4 { - d = (d * 33) ^ uint32(k[i]) - d = (d * 33) ^ uint32(k[i+1]) - d = (d * 33) ^ uint32(k[i+2]) - d = (d * 33) ^ uint32(k[i+3]) - i += 4 - } - } - switch l - i { - case 1: - case 2: - d = (d * 33) ^ uint32(k[i]) - case 3: - d = (d * 33) ^ uint32(k[i]) - d = (d * 33) ^ uint32(k[i+1]) - case 4: - d = (d * 33) ^ uint32(k[i]) - d = (d * 33) ^ uint32(k[i+1]) - d = (d * 33) ^ uint32(k[i+2]) - } - return d ^ (d >> 16) -} - -func (sc *shardedCache) bucket(k string) *cache { - return sc.cs[djb33(sc.seed, k)%sc.m] -} - -func (sc *shardedCache) Set(k string, x interface{}, d time.Duration) { - sc.bucket(k).Set(k, x, d) -} - -func (sc *shardedCache) Add(k string, x interface{}, d time.Duration) error { - return sc.bucket(k).Add(k, x, d) -} - -func (sc *shardedCache) Replace(k string, x interface{}, d time.Duration) error { - return sc.bucket(k).Replace(k, x, d) -} - -func (sc *shardedCache) Get(k string) (interface{}, bool) { - return sc.bucket(k).Get(k) -} - -func (sc *shardedCache) Increment(k string, n int64) error { - return sc.bucket(k).Increment(k, n) -} - -func (sc *shardedCache) IncrementFloat(k string, n float64) error { - return sc.bucket(k).IncrementFloat(k, n) -} - -func (sc *shardedCache) Decrement(k string, n int64) error { - return sc.bucket(k).Decrement(k, n) -} - -func (sc *shardedCache) Delete(k string) { - sc.bucket(k).Delete(k) -} - -func (sc *shardedCache) DeleteExpired() { - for _, v := range sc.cs { - v.DeleteExpired() - } -} - -// Returns the items in the cache. This may include items that have expired, -// but have not yet been cleaned up. If this is significant, the Expiration -// fields of the items should be checked. Note that explicit synchronization -// is needed to use a cache and its corresponding Items() return values at -// the same time, as the maps are shared. -func (sc *shardedCache) Items() []map[string]Item { - res := make([]map[string]Item, len(sc.cs)) - for i, v := range sc.cs { - res[i] = v.Items() - } - return res -} - -func (sc *shardedCache) Flush() { - for _, v := range sc.cs { - v.Flush() - } -} - -type shardedJanitor struct { - Interval time.Duration - stop chan bool -} - -func (j *shardedJanitor) Run(sc *shardedCache) { - j.stop = make(chan bool) - tick := time.Tick(j.Interval) - for { - select { - case <-tick: - sc.DeleteExpired() - case <-j.stop: - return - } - } -} - -func stopShardedJanitor(sc *unexportedShardedCache) { - sc.janitor.stop <- true -} - -func runShardedJanitor(sc *shardedCache, ci time.Duration) { - j := &shardedJanitor{ - Interval: ci, - } - sc.janitor = j - go j.Run(sc) -} - -func newShardedCache(n int, de time.Duration) *shardedCache { - max := big.NewInt(0).SetUint64(uint64(math.MaxUint32)) - rnd, err := rand.Int(rand.Reader, max) - var seed uint32 - if err != nil { - os.Stderr.Write([]byte("WARNING: go-cache's newShardedCache failed to read from the system CSPRNG (/dev/urandom or equivalent.) Your system's security may be compromised. Continuing with an insecure seed.\n")) - seed = insecurerand.Uint32() - } else { - seed = uint32(rnd.Uint64()) - } - sc := &shardedCache{ - seed: seed, - m: uint32(n), - cs: make([]*cache, n), - } - for i := 0; i < n; i++ { - c := &cache{ - defaultExpiration: de, - items: map[string]Item{}, - } - sc.cs[i] = c - } - return sc -} - -func unexportedNewSharded(defaultExpiration, cleanupInterval time.Duration, shards int) *unexportedShardedCache { - if defaultExpiration == 0 { - defaultExpiration = -1 - } - sc := newShardedCache(shards, defaultExpiration) - SC := &unexportedShardedCache{sc} - if cleanupInterval > 0 { - runShardedJanitor(sc, cleanupInterval) - runtime.SetFinalizer(SC, stopShardedJanitor) - } - return SC -} diff --git a/vendor/github.com/paulmach/orb/internal/length/length.go b/vendor/github.com/paulmach/orb/internal/length/length.go deleted file mode 100644 index 62e5f50..0000000 --- a/vendor/github.com/paulmach/orb/internal/length/length.go +++ /dev/null @@ -1,71 +0,0 @@ -package length - -import ( - "fmt" - - "github.com/paulmach/orb" -) - -// Length returns the length of the boundary of the geometry -// using 2d euclidean geometry. -func Length(g orb.Geometry, df orb.DistanceFunc) float64 { - if g == nil { - return 0 - } - - switch g := g.(type) { - case orb.Point: - return 0 - case orb.MultiPoint: - return 0 - case orb.LineString: - return lineStringLength(g, df) - case orb.MultiLineString: - sum := 0.0 - for _, ls := range g { - sum += lineStringLength(ls, df) - } - - return sum - case orb.Ring: - return lineStringLength(orb.LineString(g), df) - case orb.Polygon: - return polygonLength(g, df) - case orb.MultiPolygon: - sum := 0.0 - for _, p := range g { - sum += polygonLength(p, df) - } - - return sum - case orb.Collection: - sum := 0.0 - for _, c := range g { - sum += Length(c, df) - } - - return sum - case orb.Bound: - return Length(g.ToRing(), df) - } - - panic(fmt.Sprintf("geometry type not supported: %T", g)) -} - -func lineStringLength(ls orb.LineString, df orb.DistanceFunc) float64 { - sum := 0.0 - for i := 1; i < len(ls); i++ { - sum += df(ls[i], ls[i-1]) - } - - return sum -} - -func polygonLength(p orb.Polygon, df orb.DistanceFunc) float64 { - sum := 0.0 - for _, r := range p { - sum += lineStringLength(orb.LineString(r), df) - } - - return sum -} diff --git a/vendor/github.com/paulmach/orb/planar/README.md b/vendor/github.com/paulmach/orb/planar/README.md deleted file mode 100644 index b62a215..0000000 --- a/vendor/github.com/paulmach/orb/planar/README.md +++ /dev/null @@ -1,40 +0,0 @@ -# orb/planar [![Godoc Reference](https://pkg.go.dev/badge/github.com/paulmach/orb)](https://pkg.go.dev/github.com/paulmach/orb/planar) - -The geometries defined in the `orb` package are generic 2d geometries. -Depending on what projection they're in, e.g. lon/lat or flat on the plane, -area and distance calculations are different. This package implements methods -that assume the planar or Euclidean context. - -## Examples - -Area of 3-4-5 triangle: - -```go -r := orb.Ring{{0, 0}, {3, 0}, {0, 4}, {0, 0}} -a := planar.Area(r) - -fmt.Println(a) -// Output: -// 6 -``` - -Distance between two points: - -```go -d := planar.Distance(orb.Point{0, 0}, orb.Point{3, 4}) - -fmt.Println(d) -// Output: -// 5 -``` - -Length/circumference of a 3-4-5 triangle: - -```go -r := orb.Ring{{0, 0}, {3, 0}, {0, 4}, {0, 0}} -l := planar.Length(r) - -fmt.Println(l) -// Output: -// 12 -``` diff --git a/vendor/github.com/paulmach/orb/planar/area.go b/vendor/github.com/paulmach/orb/planar/area.go deleted file mode 100644 index 0482bbd..0000000 --- a/vendor/github.com/paulmach/orb/planar/area.go +++ /dev/null @@ -1,284 +0,0 @@ -// Package planar computes properties on geometries assuming they are -// in 2d euclidean space. -package planar - -import ( - "fmt" - "math" - - "github.com/paulmach/orb" -) - -// Area returns the area of the geometry in the 2d plane. -func Area(g orb.Geometry) float64 { - // TODO: make faster non-centroid version. - _, a := CentroidArea(g) - return a -} - -// CentroidArea returns both the centroid and the area in the 2d plane. -// Since the area is need for the centroid, return both. -// Polygon area will always be >= zero. Ring area my be negative if it has -// a clockwise winding orider. -func CentroidArea(g orb.Geometry) (orb.Point, float64) { - if g == nil { - return orb.Point{}, 0 - } - - switch g := g.(type) { - case orb.Point: - return multiPointCentroid(orb.MultiPoint{g}), 0 - case orb.MultiPoint: - return multiPointCentroid(g), 0 - case orb.LineString: - return multiLineStringCentroid(orb.MultiLineString{g}), 0 - case orb.MultiLineString: - return multiLineStringCentroid(g), 0 - case orb.Ring: - return ringCentroidArea(g) - case orb.Polygon: - return polygonCentroidArea(g) - case orb.MultiPolygon: - return multiPolygonCentroidArea(g) - case orb.Collection: - return collectionCentroidArea(g) - case orb.Bound: - return CentroidArea(g.ToRing()) - } - - panic(fmt.Sprintf("geometry type not supported: %T", g)) -} - -func multiPointCentroid(mp orb.MultiPoint) orb.Point { - if len(mp) == 0 { - return orb.Point{} - } - - x, y := 0.0, 0.0 - for _, p := range mp { - x += p[0] - y += p[1] - } - - num := float64(len(mp)) - return orb.Point{x / num, y / num} -} - -func multiLineStringCentroid(mls orb.MultiLineString) orb.Point { - point := orb.Point{} - dist := 0.0 - - if len(mls) == 0 { - return orb.Point{} - } - - validCount := 0 - for _, ls := range mls { - c, d := lineStringCentroidDist(ls) - if d == math.Inf(1) { - continue - } - - dist += d - validCount++ - - if d == 0 { - d = 1.0 - } - - point[0] += c[0] * d - point[1] += c[1] * d - } - - if validCount == 0 { - return orb.Point{} - } - - if dist == math.Inf(1) || dist == 0.0 { - point[0] /= float64(validCount) - point[1] /= float64(validCount) - return point - } - - point[0] /= dist - point[1] /= dist - - return point -} - -func lineStringCentroidDist(ls orb.LineString) (orb.Point, float64) { - dist := 0.0 - point := orb.Point{} - - if len(ls) == 0 { - return orb.Point{}, math.Inf(1) - } - - // implicitly move everything to near the origin to help with roundoff - offset := ls[0] - for i := 0; i < len(ls)-1; i++ { - p1 := orb.Point{ - ls[i][0] - offset[0], - ls[i][1] - offset[1], - } - - p2 := orb.Point{ - ls[i+1][0] - offset[0], - ls[i+1][1] - offset[1], - } - - d := Distance(p1, p2) - - point[0] += (p1[0] + p2[0]) / 2.0 * d - point[1] += (p1[1] + p2[1]) / 2.0 * d - dist += d - } - - if dist == 0 { - return ls[0], 0 - } - - point[0] /= dist - point[1] /= dist - - point[0] += ls[0][0] - point[1] += ls[0][1] - return point, dist -} - -func ringCentroidArea(r orb.Ring) (orb.Point, float64) { - centroid := orb.Point{} - area := 0.0 - - if len(r) == 0 { - return orb.Point{}, 0 - } - - // implicitly move everything to near the origin to help with roundoff - offsetX := r[0][0] - offsetY := r[0][1] - for i := 1; i < len(r)-1; i++ { - a := (r[i][0]-offsetX)*(r[i+1][1]-offsetY) - - (r[i+1][0]-offsetX)*(r[i][1]-offsetY) - area += a - - centroid[0] += (r[i][0] + r[i+1][0] - 2*offsetX) * a - centroid[1] += (r[i][1] + r[i+1][1] - 2*offsetY) * a - } - - if area == 0 { - return r[0], 0 - } - - // no need to deal with first and last vertex since we "moved" - // that point the origin (multiply by 0 == 0) - - area /= 2 - centroid[0] /= 6 * area - centroid[1] /= 6 * area - - centroid[0] += offsetX - centroid[1] += offsetY - - return centroid, area -} - -func polygonCentroidArea(p orb.Polygon) (orb.Point, float64) { - if len(p) == 0 { - return orb.Point{}, 0 - } - - centroid, area := ringCentroidArea(p[0]) - area = math.Abs(area) - if len(p) == 1 { - if area == 0 { - c, _ := lineStringCentroidDist(orb.LineString(p[0])) - return c, 0 - } - return centroid, area - } - - holeArea := 0.0 - weightedHoleCentroid := orb.Point{} - for i := 1; i < len(p); i++ { - hc, ha := ringCentroidArea(p[i]) - ha = math.Abs(ha) - - holeArea += ha - weightedHoleCentroid[0] += hc[0] * ha - weightedHoleCentroid[1] += hc[1] * ha - } - - totalArea := area - holeArea - if totalArea == 0 { - c, _ := lineStringCentroidDist(orb.LineString(p[0])) - return c, 0 - } - - centroid[0] = (area*centroid[0] - weightedHoleCentroid[0]) / totalArea - centroid[1] = (area*centroid[1] - weightedHoleCentroid[1]) / totalArea - - return centroid, totalArea -} - -func multiPolygonCentroidArea(mp orb.MultiPolygon) (orb.Point, float64) { - point := orb.Point{} - area := 0.0 - - for _, p := range mp { - c, a := polygonCentroidArea(p) - - point[0] += c[0] * a - point[1] += c[1] * a - - area += a - } - - if area == 0 { - return orb.Point{}, 0 - } - - point[0] /= area - point[1] /= area - - return point, area -} - -func collectionCentroidArea(c orb.Collection) (orb.Point, float64) { - point := orb.Point{} - area := 0.0 - - max := maxDim(c) - for _, g := range c { - if g.Dimensions() != max { - continue - } - - c, a := CentroidArea(g) - - point[0] += c[0] * a - point[1] += c[1] * a - - area += a - } - - if area == 0 { - return orb.Point{}, 0 - } - - point[0] /= area - point[1] /= area - - return point, area -} - -func maxDim(c orb.Collection) int { - max := 0 - for _, g := range c { - if d := g.Dimensions(); d > max { - max = d - } - } - - return max -} diff --git a/vendor/github.com/paulmach/orb/planar/contains.go b/vendor/github.com/paulmach/orb/planar/contains.go deleted file mode 100644 index fbfc455..0000000 --- a/vendor/github.com/paulmach/orb/planar/contains.go +++ /dev/null @@ -1,122 +0,0 @@ -package planar - -import ( - "math" - - "github.com/paulmach/orb" -) - -// RingContains returns true if the point is inside the ring. -// Points on the boundary are considered in. -func RingContains(r orb.Ring, point orb.Point) bool { - if !r.Bound().Contains(point) { - return false - } - - c, on := rayIntersect(point, r[0], r[len(r)-1]) - if on { - return true - } - - for i := 0; i < len(r)-1; i++ { - inter, on := rayIntersect(point, r[i], r[i+1]) - if on { - return true - } - - if inter { - c = !c - } - } - - return c -} - -// PolygonContains checks if the point is within the polygon. -// Points on the boundary are considered in. -func PolygonContains(p orb.Polygon, point orb.Point) bool { - if !RingContains(p[0], point) { - return false - } - - for i := 1; i < len(p); i++ { - if RingContains(p[i], point) { - return false - } - } - - return true -} - -// MultiPolygonContains checks if the point is within the multi-polygon. -// Points on the boundary are considered in. -func MultiPolygonContains(mp orb.MultiPolygon, point orb.Point) bool { - for _, p := range mp { - if PolygonContains(p, point) { - return true - } - } - - return false -} - -// Original implementation: http://rosettacode.org/wiki/Ray-casting_algorithm#Go -func rayIntersect(p, s, e orb.Point) (intersects, on bool) { - if s[0] > e[0] { - s, e = e, s - } - - if p[0] == s[0] { - if p[1] == s[1] { - // p == start - return false, true - } else if s[0] == e[0] { - // vertical segment (s -> e) - // return true if within the line, check to see if start or end is greater. - if s[1] > e[1] && s[1] >= p[1] && p[1] >= e[1] { - return false, true - } - - if e[1] > s[1] && e[1] >= p[1] && p[1] >= s[1] { - return false, true - } - } - - // Move the y coordinate to deal with degenerate case - p[0] = math.Nextafter(p[0], math.Inf(1)) - } else if p[0] == e[0] { - if p[1] == e[1] { - // matching the end point - return false, true - } - - p[0] = math.Nextafter(p[0], math.Inf(1)) - } - - if p[0] < s[0] || p[0] > e[0] { - return false, false - } - - if s[1] > e[1] { - if p[1] > s[1] { - return false, false - } else if p[1] < e[1] { - return true, false - } - } else { - if p[1] > e[1] { - return false, false - } else if p[1] < s[1] { - return true, false - } - } - - rs := (p[1] - s[1]) / (p[0] - s[0]) - ds := (e[1] - s[1]) / (e[0] - s[0]) - - if rs == ds { - return false, true - } - - return rs <= ds, false -} diff --git a/vendor/github.com/paulmach/orb/planar/distance.go b/vendor/github.com/paulmach/orb/planar/distance.go deleted file mode 100644 index a0304a7..0000000 --- a/vendor/github.com/paulmach/orb/planar/distance.go +++ /dev/null @@ -1,21 +0,0 @@ -package planar - -import ( - "math" - - "github.com/paulmach/orb" -) - -// Distance returns the distance between two points in 2d euclidean geometry. -func Distance(p1, p2 orb.Point) float64 { - d0 := (p1[0] - p2[0]) - d1 := (p1[1] - p2[1]) - return math.Sqrt(d0*d0 + d1*d1) -} - -// DistanceSquared returns the square of the distance between two points in 2d euclidean geometry. -func DistanceSquared(p1, p2 orb.Point) float64 { - d0 := (p1[0] - p2[0]) - d1 := (p1[1] - p2[1]) - return d0*d0 + d1*d1 -} diff --git a/vendor/github.com/paulmach/orb/planar/distance_from.go b/vendor/github.com/paulmach/orb/planar/distance_from.go deleted file mode 100644 index da4fffc..0000000 --- a/vendor/github.com/paulmach/orb/planar/distance_from.go +++ /dev/null @@ -1,173 +0,0 @@ -package planar - -import ( - "fmt" - "math" - - "github.com/paulmach/orb" -) - -// DistanceFromSegment returns the point's distance from the segment [a, b]. -func DistanceFromSegment(a, b, point orb.Point) float64 { - return math.Sqrt(DistanceFromSegmentSquared(a, b, point)) -} - -// DistanceFromSegmentSquared returns point's squared distance from the segement [a, b]. -func DistanceFromSegmentSquared(a, b, point orb.Point) float64 { - x := a[0] - y := a[1] - dx := b[0] - x - dy := b[1] - y - - if dx != 0 || dy != 0 { - t := ((point[0]-x)*dx + (point[1]-y)*dy) / (dx*dx + dy*dy) - - if t > 1 { - x = b[0] - y = b[1] - } else if t > 0 { - x += dx * t - y += dy * t - } - } - - dx = point[0] - x - dy = point[1] - y - - return dx*dx + dy*dy -} - -// DistanceFrom returns the distance from the boundary of the geometry in -// the units of the geometry. -func DistanceFrom(g orb.Geometry, p orb.Point) float64 { - d, _ := DistanceFromWithIndex(g, p) - return d -} - -// DistanceFromWithIndex returns the minimum euclidean distance -// from the boundary of the geometry plus the index of the sub-geometry -// that was the match. -func DistanceFromWithIndex(g orb.Geometry, p orb.Point) (float64, int) { - if g == nil { - return math.Inf(1), -1 - } - - switch g := g.(type) { - case orb.Point: - return Distance(g, p), 0 - case orb.MultiPoint: - return multiPointDistanceFrom(g, p) - case orb.LineString: - return lineStringDistanceFrom(g, p) - case orb.MultiLineString: - dist := math.Inf(1) - index := -1 - for i, ls := range g { - if d, _ := lineStringDistanceFrom(ls, p); d < dist { - dist = d - index = i - } - } - - return dist, index - case orb.Ring: - return lineStringDistanceFrom(orb.LineString(g), p) - case orb.Polygon: - return polygonDistanceFrom(g, p) - case orb.MultiPolygon: - dist := math.Inf(1) - index := -1 - for i, poly := range g { - if d, _ := polygonDistanceFrom(poly, p); d < dist { - dist = d - index = i - } - } - - return dist, index - case orb.Collection: - dist := math.Inf(1) - index := -1 - for i, ge := range g { - if d, _ := DistanceFromWithIndex(ge, p); d < dist { - dist = d - index = i - } - } - - return dist, index - case orb.Bound: - return DistanceFromWithIndex(g.ToRing(), p) - } - - panic(fmt.Sprintf("geometry type not supported: %T", g)) -} - -func multiPointDistanceFrom(mp orb.MultiPoint, p orb.Point) (float64, int) { - dist := math.Inf(1) - index := -1 - - for i := range mp { - if d := DistanceSquared(mp[i], p); d < dist { - dist = d - index = i - } - } - - return math.Sqrt(dist), index -} - -func lineStringDistanceFrom(ls orb.LineString, p orb.Point) (float64, int) { - dist := math.Inf(1) - index := -1 - - for i := 0; i < len(ls)-1; i++ { - if d := segmentDistanceFromSquared(ls[i], ls[i+1], p); d < dist { - dist = d - index = i - } - } - - return math.Sqrt(dist), index -} - -func polygonDistanceFrom(p orb.Polygon, point orb.Point) (float64, int) { - if len(p) == 0 { - return math.Inf(1), -1 - } - - dist, index := lineStringDistanceFrom(orb.LineString(p[0]), point) - for i := 1; i < len(p); i++ { - d, i := lineStringDistanceFrom(orb.LineString(p[i]), point) - if d < dist { - dist = d - index = i - } - } - - return dist, index -} - -func segmentDistanceFromSquared(p1, p2, point orb.Point) float64 { - x := p1[0] - y := p1[1] - dx := p2[0] - x - dy := p2[1] - y - - if dx != 0 || dy != 0 { - t := ((point[0]-x)*dx + (point[1]-y)*dy) / (dx*dx + dy*dy) - - if t > 1 { - x = p2[0] - y = p2[1] - } else if t > 0 { - x += dx * t - y += dy * t - } - } - - dx = point[0] - x - dy = point[1] - y - - return dx*dx + dy*dy -} diff --git a/vendor/github.com/paulmach/orb/planar/length.go b/vendor/github.com/paulmach/orb/planar/length.go deleted file mode 100644 index 4eae415..0000000 --- a/vendor/github.com/paulmach/orb/planar/length.go +++ /dev/null @@ -1,12 +0,0 @@ -package planar - -import ( - "github.com/paulmach/orb" - "github.com/paulmach/orb/internal/length" -) - -// Length returns the length of the boundary of the geometry -// using 2d euclidean geometry. -func Length(g orb.Geometry) float64 { - return length.Length(g, Distance) -} diff --git a/vendor/github.com/whosonfirst/go-whosonfirst-spatial-rtree/.gitignore b/vendor/github.com/whosonfirst/go-whosonfirst-spatial-rtree/.gitignore deleted file mode 100644 index 6e7e38b..0000000 --- a/vendor/github.com/whosonfirst/go-whosonfirst-spatial-rtree/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -*~ -bin \ No newline at end of file diff --git a/vendor/github.com/whosonfirst/go-whosonfirst-spatial-rtree/LICENSE b/vendor/github.com/whosonfirst/go-whosonfirst-spatial-rtree/LICENSE deleted file mode 100644 index c927ffd..0000000 --- a/vendor/github.com/whosonfirst/go-whosonfirst-spatial-rtree/LICENSE +++ /dev/null @@ -1,27 +0,0 @@ -Copyright (c) 2020, Aaron Straup Cope -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -* Neither the name of the {organization} nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/vendor/github.com/whosonfirst/go-whosonfirst-spatial-rtree/Makefile b/vendor/github.com/whosonfirst/go-whosonfirst-spatial-rtree/Makefile deleted file mode 100644 index ebd3acb..0000000 --- a/vendor/github.com/whosonfirst/go-whosonfirst-spatial-rtree/Makefile +++ /dev/null @@ -1,2 +0,0 @@ -cli: - go build -mod vendor -o bin/query cmd/query/main.go diff --git a/vendor/github.com/whosonfirst/go-whosonfirst-spatial-rtree/README.md b/vendor/github.com/whosonfirst/go-whosonfirst-spatial-rtree/README.md deleted file mode 100644 index 86b7933..0000000 --- a/vendor/github.com/whosonfirst/go-whosonfirst-spatial-rtree/README.md +++ /dev/null @@ -1,113 +0,0 @@ -# go-whosonfirst-spatial-rtree - -In-memory implementation of the go-whosonfirst-spatial interfaces. - -## Important - -This is work in progress. Documentation remains incomplete. - -## Interfaces - -This package implements the following [go-whosonfirst-spatial](#) interfaces. - -### spatial.SpatialDatabase - -``` -import ( - "github.com/whosonfirst/go-whosonfirst-spatial/database" - _ "github.com/whosonfirst/go-whosonfirst-spatial-rtree" -) - -db, err := database.NewSpatialDatabase(ctx, "rtree://") -``` - -### Database URIs - -The `go-whosonfirst-spatial-rtree` package is instantiated using a URI in the form of: - -``` -rtree://?{PARAMETERS} -``` - -Valid parameters include: - -#### Parameters - -| Name | Value | Required| Notes | -| --- | --- | --- | --- | -| strict | bool | N | | -| index_alt_files | bool | N | | - -## Tools - -``` -$> make cli -``` - -### query - -``` -$> ./bin/query -h - -alternate-geometry value - One or more alternate geometry labels (wof:alt_label) values to filter results by. - -cessation-date string - A valid EDTF date string. - -custom-placetypes string - A JSON-encoded string containing custom placetypes defined using the syntax described in the whosonfirst/go-whosonfirst-placetypes repository. - -enable-custom-placetypes - Enable wof:placetype values that are not explicitly defined in the whosonfirst/go-whosonfirst-placetypes repository. - -geometries string - Valid options are: all, alt, default. (default "all") - -inception-date string - A valid EDTF date string. - -is-ceased value - One or more existential flags (-1, 0, 1) to filter results by. - -is-current value - One or more existential flags (-1, 0, 1) to filter results by. - -is-deprecated value - One or more existential flags (-1, 0, 1) to filter results by. - -is-superseded value - One or more existential flags (-1, 0, 1) to filter results by. - -is-superseding value - One or more existential flags (-1, 0, 1) to filter results by. - -is-wof - Input data is WOF-flavoured GeoJSON. (Pass a value of '0' or 'false' if you need to index non-WOF documents. (default true) - -iterator-uri string - A valid whosonfirst/go-whosonfirst-iterate/emitter URI. Supported schemes are: directory://, featurecollection://, file://, filelist://, geojsonl://, repo://. (default "repo://") - -latitude float - A valid latitude. - -longitude float - A valid longitude. - -placetype value - One or more place types to filter results by. - -properties-reader-uri string - A valid whosonfirst/go-reader.Reader URI. Available options are: [file:// fs:// null://] - -property value - One or more Who's On First properties to append to each result. - -spatial-database-uri string - A valid whosonfirst/go-whosonfirst-spatial/data.SpatialDatabase URI. options are: [rtree://] - -verbose - Be chatty. -``` - -#### Example - -``` -$> ./bin/query \ - -iterator-uri 'repo://?include=properties.mz:is_current=1' \ - -latitude 37.613490350845794 \ - -longitude -122.38882533303682 \ - /usr/local/data/sfomuseum-data-architecture/ - -| jq '.places[]["wof:name"]' - -"Boarding Area A" -"SFO Terminal Complex" -"International Terminal" -``` - -## See also - -* https://github.com/whosonfirst/go-whosonfirst-spatial -* https://github.com/whosonfirst/go-whosonfirst-iterate -* https://github.com/dhconnelly/rtreego diff --git a/vendor/github.com/whosonfirst/go-whosonfirst-spatial-rtree/database.go b/vendor/github.com/whosonfirst/go-whosonfirst-spatial-rtree/database.go deleted file mode 100644 index ab0667e..0000000 --- a/vendor/github.com/whosonfirst/go-whosonfirst-spatial-rtree/database.go +++ /dev/null @@ -1,709 +0,0 @@ -package rtree - -import ( - "bytes" - "context" - "encoding/json" - "fmt" - "github.com/dhconnelly/rtreego" - gocache "github.com/patrickmn/go-cache" - "github.com/paulmach/orb" - "github.com/paulmach/orb/geojson" - "github.com/paulmach/orb/planar" - "github.com/whosonfirst/go-ioutil" - "github.com/whosonfirst/go-whosonfirst-feature/alt" - "github.com/whosonfirst/go-whosonfirst-feature/geometry" - "github.com/whosonfirst/go-whosonfirst-feature/properties" - "github.com/whosonfirst/go-whosonfirst-spatial" - "github.com/whosonfirst/go-whosonfirst-spatial/database" - "github.com/whosonfirst/go-whosonfirst-spatial/filter" - "github.com/whosonfirst/go-whosonfirst-spatial/timer" - "github.com/whosonfirst/go-whosonfirst-spr/v2" - "github.com/whosonfirst/go-whosonfirst-uri" - "io" - "log" - "net/url" - "strconv" - "strings" - "sync" - "time" -) - -func init() { - ctx := context.Background() - database.RegisterSpatialDatabase(ctx, "rtree", NewRTreeSpatialDatabase) -} - -type RTreeCache struct { - Geometry *geojson.Geometry `json:"geometry"` - SPR spr.StandardPlacesResult `json:"properties"` -} - -// PLEASE DISCUSS WHY patrickm/go-cache AND NOT whosonfirst/go-cache HERE - -type RTreeSpatialDatabase struct { - database.SpatialDatabase - Logger *log.Logger - Timer *timer.Timer - index_alt_files bool - rtree *rtreego.Rtree - gocache *gocache.Cache - mu *sync.RWMutex - strict bool -} - -type RTreeSpatialIndex struct { - Rect *rtreego.Rect - Id string - FeatureId string - IsAlt bool - AltLabel string -} - -func (i *RTreeSpatialIndex) Bounds() *rtreego.Rect { - return i.Rect -} - -type RTreeResults struct { - spr.StandardPlacesResults `json:",omitempty"` - Places []spr.StandardPlacesResult `json:"places"` -} - -func (r *RTreeResults) Results() []spr.StandardPlacesResult { - return r.Places -} - -func NewRTreeSpatialDatabase(ctx context.Context, uri string) (database.SpatialDatabase, error) { - - u, err := url.Parse(uri) - - if err != nil { - return nil, err - } - - q := u.Query() - - strict := true - - if q.Get("strict") == "false" { - strict = false - } - - expires := 0 * time.Second - cleanup := 0 * time.Second - - str_exp := q.Get("default_expiration") - str_cleanup := q.Get("cleanup_interval") - - if str_exp != "" { - - int_expires, err := strconv.Atoi(str_exp) - - if err != nil { - return nil, err - } - - expires = time.Duration(int_expires) * time.Second - } - - if str_cleanup != "" { - - int_cleanup, err := strconv.Atoi(str_cleanup) - - if err != nil { - return nil, err - } - - cleanup = time.Duration(int_cleanup) * time.Second - } - - index_alt_files := false - - str_index_alt := q.Get("index_alt_files") - - if str_index_alt != "" { - - index_alt, err := strconv.ParseBool(str_index_alt) - - if err != nil { - return nil, err - } - - index_alt_files = index_alt - } - - gc := gocache.New(expires, cleanup) - - logger := log.Default() - - rtree := rtreego.NewTree(2, 25, 50) - - mu := new(sync.RWMutex) - - t := timer.NewTimer() - - db := &RTreeSpatialDatabase{ - Logger: logger, - Timer: t, - rtree: rtree, - index_alt_files: index_alt_files, - gocache: gc, - strict: strict, - mu: mu, - } - - return db, nil -} - -func (r *RTreeSpatialDatabase) Close(ctx context.Context) error { - return nil -} - -func (r *RTreeSpatialDatabase) IndexFeature(ctx context.Context, body []byte) error { - - is_alt := alt.IsAlt(body) - alt_label, _ := properties.AltLabel(body) - - if is_alt && !r.index_alt_files { - return nil - } - - if is_alt && alt_label == "" { - return fmt.Errorf("Invalid alt label") - } - - err := r.setCache(ctx, body) - - if err != nil { - return fmt.Errorf("Failed to cache feature, %w", err) - } - - feature_id, err := properties.Id(body) - - if err != nil { - return fmt.Errorf("Failed to derive ID, %w", err) - } - - str_id := strconv.FormatInt(feature_id, 10) - - // START OF put me in go-whosonfirst-feature/geometry - - geojson_geom, err := geometry.Geometry(body) - - if err != nil { - return fmt.Errorf("Failed to derive geometry, %w", err) - } - - orb_geom := geojson_geom.Geometry() - - bounds := make([]orb.Bound, 0) - - switch orb_geom.GeoJSONType() { - - case "MultiPolygon": - - for _, poly := range orb_geom.(orb.MultiPolygon) { - - for _, ring := range poly { - bounds = append(bounds, ring.Bound()) - } - } - - case "Polygon": - - for _, ring := range orb_geom.(orb.Polygon) { - bounds = append(bounds, ring.Bound()) - } - default: - bounds = append(bounds, orb_geom.Bound()) - } - - // END OF put me in go-whosonfirst-feature/geometry - - for i, bbox := range bounds { - - sp_id, err := spatial.SpatialIdWithFeature(body, i) - - if err != nil { - return fmt.Errorf("Failed to derive spatial ID, %v", err) - } - - min := bbox.Min - max := bbox.Max - - min_x := min[0] - min_y := min[1] - - max_x := max[0] - max_y := max[1] - - llat := max_y - min_y - llon := max_x - min_x - - pt := rtreego.Point{min_x, min_y} - rect, err := rtreego.NewRect(pt, []float64{llon, llat}) - - if err != nil { - - if r.strict { - return fmt.Errorf("Failed to derive rtree bounds, %w", err) - } - - r.Logger.Printf("%s failed indexing, (%v). Strict mode is disabled, so skipping.", sp_id, err) - return nil - } - - r.Logger.Printf("index %s %v", sp_id, rect) - - sp := &RTreeSpatialIndex{ - Rect: rect, - Id: sp_id, - FeatureId: str_id, - IsAlt: is_alt, - AltLabel: alt_label, - } - - r.mu.Lock() - r.rtree.Insert(sp) - - r.mu.Unlock() - } - - return nil -} - -/* - -TO DO: figure out suitable comparitor - -/ DeleteWithComparator removes an object from the tree using a custom -// comparator for evaluating equalness. This is useful when you want to remove -// an object from a tree but don't have a pointer to the original object -// anymore. -func (tree *Rtree) DeleteWithComparator(obj Spatial, cmp Comparator) bool { - n := tree.findLeaf(tree.root, obj, cmp) - -// Comparator compares two spatials and returns whether they are equal. -type Comparator func(obj1, obj2 Spatial) (equal bool) - -func defaultComparator(obj1, obj2 Spatial) bool { - return obj1 == obj2 -} - -*/ - -func (r *RTreeSpatialDatabase) RemoveFeature(ctx context.Context, id string) error { - - obj := &RTreeSpatialIndex{ - Rect: nil, - Id: id, - } - - comparator := func(obj1, obj2 rtreego.Spatial) bool { - - // 2021/10/12 11:17:11 COMPARE 1: '101737491#:0' 2: '101737491' - // log.Printf("COMPARE 1: '%v' 2: '%v'\n", obj1.(*RTreeSpatialIndex).Id, obj2.(*RTreeSpatialIndex).Id) - - obj1_id := obj1.(*RTreeSpatialIndex).Id - obj2_id := obj2.(*RTreeSpatialIndex).Id - - return strings.HasPrefix(obj1_id, obj2_id) - } - - ok := r.rtree.DeleteWithComparator(obj, comparator) - - if !ok { - return fmt.Errorf("Failed to remove %s from rtree", id) - } - - return nil -} - -func (r *RTreeSpatialDatabase) PointInPolygon(ctx context.Context, coord *orb.Point, filters ...spatial.Filter) (spr.StandardPlacesResults, error) { - - ctx, cancel := context.WithCancel(ctx) - defer cancel() - - rsp_ch := make(chan spr.StandardPlacesResult) - err_ch := make(chan error) - done_ch := make(chan bool) - - results := make([]spr.StandardPlacesResult, 0) - working := true - - go r.PointInPolygonWithChannels(ctx, rsp_ch, err_ch, done_ch, coord, filters...) - - for { - select { - case <-ctx.Done(): - return nil, nil - case <-done_ch: - working = false - case rsp := <-rsp_ch: - results = append(results, rsp) - case err := <-err_ch: - return nil, err - default: - // pass - } - - if !working { - break - } - } - - spr_results := &RTreeResults{ - Places: results, - } - - return spr_results, nil -} - -func (r *RTreeSpatialDatabase) PointInPolygonWithChannels(ctx context.Context, rsp_ch chan spr.StandardPlacesResult, err_ch chan error, done_ch chan bool, coord *orb.Point, filters ...spatial.Filter) { - - defer func() { - done_ch <- true - }() - - rows, err := r.getIntersectsByCoord(coord) - - if err != nil { - err_ch <- err - return - } - - r.inflateResultsWithChannels(ctx, rsp_ch, err_ch, rows, coord, filters...) - return -} - -func (r *RTreeSpatialDatabase) PointInPolygonCandidates(ctx context.Context, coord *orb.Point, filters ...spatial.Filter) ([]*spatial.PointInPolygonCandidate, error) { - - ctx, cancel := context.WithCancel(ctx) - defer cancel() - - rsp_ch := make(chan *spatial.PointInPolygonCandidate) - err_ch := make(chan error) - done_ch := make(chan bool) - - candidates := make([]*spatial.PointInPolygonCandidate, 0) - working := true - - go r.PointInPolygonCandidatesWithChannels(ctx, rsp_ch, err_ch, done_ch, coord, filters...) - - for { - select { - case <-ctx.Done(): - return nil, nil - case <-done_ch: - working = false - case rsp := <-rsp_ch: - candidates = append(candidates, rsp) - case err := <-err_ch: - return nil, err - default: - // pass - } - - if !working { - break - } - } - - return candidates, nil -} - -func (r *RTreeSpatialDatabase) PointInPolygonCandidatesWithChannels(ctx context.Context, rsp_ch chan *spatial.PointInPolygonCandidate, err_ch chan error, done_ch chan bool, coord *orb.Point, filters ...spatial.Filter) { - - defer func() { - done_ch <- true - }() - - intersects, err := r.getIntersectsByCoord(coord) - - if err != nil { - err_ch <- err - return - } - - for _, raw := range intersects { - - sp := raw.(*RTreeSpatialIndex) - - // bounds := sp.Bounds() - - c := &spatial.PointInPolygonCandidate{ - Id: sp.Id, - FeatureId: sp.FeatureId, - AltLabel: sp.AltLabel, - // FIX ME - // Bounds: bounds, - } - - rsp_ch <- c - } - - return -} - -func (r *RTreeSpatialDatabase) getIntersectsByCoord(coord *orb.Point) ([]rtreego.Spatial, error) { - - lat := coord.Y() - lon := coord.X() - - pt := rtreego.Point{lon, lat} - rect, err := rtreego.NewRect(pt, []float64{0.0001, 0.0001}) // how small can I make this? - - if err != nil { - return nil, fmt.Errorf("Failed to derive rtree bounds, %w", err) - } - - return r.getIntersectsByRect(rect) -} - -func (r *RTreeSpatialDatabase) getIntersectsByRect(rect *rtreego.Rect) ([]rtreego.Spatial, error) { - - // to do: timings that don't slow everything down the way - // go-whosonfirst-timer does now (20170915/thisisaaronland) - - results := r.rtree.SearchIntersect(rect) - return results, nil -} - -func (r *RTreeSpatialDatabase) inflateResultsWithChannels(ctx context.Context, rsp_ch chan spr.StandardPlacesResult, err_ch chan error, possible []rtreego.Spatial, c *orb.Point, filters ...spatial.Filter) { - - seen := make(map[string]bool) - - mu := new(sync.RWMutex) - wg := new(sync.WaitGroup) - - for _, row := range possible { - - sp := row.(*RTreeSpatialIndex) - wg.Add(1) - - go func(sp *RTreeSpatialIndex) { - - sp_id := sp.Id - feature_id := sp.FeatureId - - t1 := time.Now() - - defer func() { - r.Timer.Add(ctx, sp_id, "time to inflate", time.Since(t1)) - }() - - defer wg.Done() - - select { - case <-ctx.Done(): - return - default: - // pass - } - - mu.RLock() - _, ok := seen[feature_id] - mu.RUnlock() - - if ok { - return - } - - mu.Lock() - seen[feature_id] = true - mu.Unlock() - - t2 := time.Now() - - cache_item, err := r.retrieveCache(ctx, sp) - - r.Timer.Add(ctx, sp_id, "time to retrieve cache", time.Since(t2)) - - if err != nil { - r.Logger.Printf("Failed to retrieve cache for %s, %v", sp_id, err) - return - } - - s := cache_item.SPR - - t3 := time.Now() - - for _, f := range filters { - - err = filter.FilterSPR(f, s) - - if err != nil { - // r.Logger.Debug("SKIP %s because filter error %s", sp_id, err) - return - } - } - - r.Timer.Add(ctx, sp_id, "time to filter", time.Since(t3)) - - t4 := time.Now() - - geom := cache_item.Geometry - - orb_geom := geom.Geometry() - geom_type := orb_geom.GeoJSONType() - - contains := false - - switch geom_type { - case "Polygon": - contains = planar.PolygonContains(orb_geom.(orb.Polygon), *c) - case "MultiPolygon": - contains = planar.MultiPolygonContains(orb_geom.(orb.MultiPolygon), *c) - default: - r.Logger.Printf("Geometry has unsupported geometry type '%s'", geom.Type) - } - - r.Timer.Add(ctx, sp_id, "time to test geometry", time.Since(t4)) - - if !contains { - // r.Logger.Debug("SKIP %s because does not contain coord (%v)", sp_id, c) - return - } - - rsp_ch <- s - }(sp) - } - - wg.Wait() -} - -func (r *RTreeSpatialDatabase) setCache(ctx context.Context, body []byte) error { - - s, err := spr.WhosOnFirstSPR(body) - - if err != nil { - return err - } - - geom, err := geometry.Geometry(body) - - if err != nil { - return fmt.Errorf("Failed to derive geometry for feature, %w", err) - } - - alt_label, err := properties.AltLabel(body) - - if err != nil { - return fmt.Errorf("Failed to derive alt label, %w", err) - } - - feature_id, err := properties.Id(body) - - if err != nil { - return fmt.Errorf("Failed to derive feature ID, %w", err) - } - - cache_key := fmt.Sprintf("%d:%s", feature_id, alt_label) - - cache_item := &RTreeCache{ - Geometry: geom, - SPR: s, - } - - r.gocache.Set(cache_key, cache_item, -1) - return nil -} - -func (r *RTreeSpatialDatabase) retrieveCache(ctx context.Context, sp *RTreeSpatialIndex) (*RTreeCache, error) { - - cache_key := fmt.Sprintf("%s:%s", sp.FeatureId, sp.AltLabel) - - cache_item, ok := r.gocache.Get(cache_key) - - if !ok { - return nil, fmt.Errorf("Invalid cache ID '%s'", cache_key) - } - - return cache_item.(*RTreeCache), nil -} - -// whosonfirst/go-reader interface - -func (r *RTreeSpatialDatabase) Read(ctx context.Context, str_uri string) (io.ReadSeekCloser, error) { - - id, _, err := uri.ParseURI(str_uri) - - if err != nil { - return nil, fmt.Errorf("Failed to parse URI %s, %w", str_uri, err) - } - - // TO DO : ALT STUFF HERE - - str_id := strconv.FormatInt(id, 10) - - sp := &RTreeSpatialIndex{ - FeatureId: str_id, - AltLabel: "", - } - - cache_item, err := r.retrieveCache(ctx, sp) - - if err != nil { - return nil, fmt.Errorf("Failed to retrieve cache, %w", err) - } - - // START OF this is dumb - - enc_spr, err := json.Marshal(cache_item.SPR) - - if err != nil { - return nil, fmt.Errorf("Failed to marchal cache record, %w", err) - } - - var props map[string]interface{} - - err = json.Unmarshal(enc_spr, &props) - - if err != nil { - return nil, err - } - - // END OF this is dumb - - orb_geom := cache_item.Geometry.Geometry() - f := geojson.NewFeature(orb_geom) - - if err != nil { - return nil, err - } - - f.Properties = props - - enc_f, err := f.MarshalJSON() - - if err != nil { - return nil, err - } - - br := bytes.NewReader(enc_f) - return ioutil.NewReadSeekCloser(br) -} - -func (r *RTreeSpatialDatabase) ReaderURI(ctx context.Context, str_uri string) string { - return str_uri -} - -// whosonfirst/go-writer interface - -func (r *RTreeSpatialDatabase) Write(ctx context.Context, key string, fh io.ReadSeeker) (int64, error) { - return 0, fmt.Errorf("Not implemented") -} - -func (r *RTreeSpatialDatabase) WriterURI(ctx context.Context, str_uri string) string { - return str_uri -} - -func (r *RTreeSpatialDatabase) Flush(ctx context.Context) error { - return nil -} - -// Close defined above - -func (r *RTreeSpatialDatabase) SetLogger(ctx context.Context, logger *log.Logger) error { - return nil -} diff --git a/vendor/github.com/whosonfirst/go-whosonfirst-spatial/app/properties.go b/vendor/github.com/whosonfirst/go-whosonfirst-spatial/app/properties.go index 3dea5fd..1f624c6 100644 --- a/vendor/github.com/whosonfirst/go-whosonfirst-spatial/app/properties.go +++ b/vendor/github.com/whosonfirst/go-whosonfirst-spatial/app/properties.go @@ -18,7 +18,7 @@ func NewPropertiesReaderWithFlagsSet(ctx context.Context, fs *flag.FlagSet) (rea } use_spatial_uri := fmt.Sprintf("{%s}", flags.SPATIAL_DATABASE_URI) - + if reader_uri == use_spatial_uri { spatial_database_uri, err := lookup.StringVar(fs, flags.SPATIAL_DATABASE_URI) @@ -29,6 +29,6 @@ func NewPropertiesReaderWithFlagsSet(ctx context.Context, fs *flag.FlagSet) (rea reader_uri = spatial_database_uri } - + return reader.NewReader(ctx, reader_uri) } diff --git a/vendor/github.com/whosonfirst/go-whosonfirst-spatial/flags/flags.go b/vendor/github.com/whosonfirst/go-whosonfirst-spatial/flags/flags.go index a5dc21d..c74d057 100644 --- a/vendor/github.com/whosonfirst/go-whosonfirst-spatial/flags/flags.go +++ b/vendor/github.com/whosonfirst/go-whosonfirst-spatial/flags/flags.go @@ -41,3 +41,5 @@ const PROPERTIES_READER_URI string = "properties-reader-uri" const VERBOSE string = "verbose" const IS_WOF string = "is-wof" + +const SORT string = "sort-uri" diff --git a/vendor/github.com/whosonfirst/go-whosonfirst-spatial/flags/query.go b/vendor/github.com/whosonfirst/go-whosonfirst-spatial/flags/query.go index 3128788..0c4f38a 100644 --- a/vendor/github.com/whosonfirst/go-whosonfirst-spatial/flags/query.go +++ b/vendor/github.com/whosonfirst/go-whosonfirst-spatial/flags/query.go @@ -42,6 +42,9 @@ func AppendQueryFlags(fs *flag.FlagSet) error { var is_superseding multi.MultiInt64 fs.Var(&is_superseding, IS_SUPERSEDING, "One or more existential flags (-1, 0, 1) to filter results by.") + var sort multi.MultiString + fs.Var(&sort, SORT, "Zero or more whosonfirst/go-whosonfirst-spr/sort URIs.") + return nil } diff --git a/vendor/github.com/whosonfirst/go-whosonfirst-spatial/timer/timer.go b/vendor/github.com/whosonfirst/go-whosonfirst-spatial/timer/timer.go deleted file mode 100644 index 424a6b0..0000000 --- a/vendor/github.com/whosonfirst/go-whosonfirst-spatial/timer/timer.go +++ /dev/null @@ -1,61 +0,0 @@ -package timer - -import ( - "context" - "fmt" - "sync" - "time" -) - -type Timing struct { - Created time.Time - Description string - Duration time.Duration -} - -func (t *Timing) String() string { - return fmt.Sprintf("%s: %v", t.Description, t.Duration) -} - -type Timer struct { - mu *sync.RWMutex - Timings map[string][]*Timing -} - -func NewTimer() *Timer { - - timings := make(map[string][]*Timing) - mu := new(sync.RWMutex) - - t := &Timer{ - mu: mu, - Timings: timings, - } - - return t -} - -func (t *Timer) Add(ctx context.Context, group string, description string, duration time.Duration) error { - - now := time.Now() - - tm := &Timing{ - Created: now, - Description: description, - Duration: duration, - } - - t.mu.Lock() - defer t.mu.Unlock() - - timings, ok := t.Timings[group] - - if !ok { - timings = make([]*Timing, 0) - } - - timings = append(timings, tm) - t.Timings[group] = timings - - return nil -} diff --git a/vendor/modules.txt b/vendor/modules.txt index ccda433..a8c95fc 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -4,9 +4,6 @@ github.com/aaronland/go-json-query # github.com/aaronland/go-roster v1.0.0 ## explicit; go 1.16 github.com/aaronland/go-roster -# github.com/dhconnelly/rtreego v1.1.0 -## explicit; go 1.13 -github.com/dhconnelly/rtreego # github.com/g8rswimmer/error-chain v1.0.0 ## explicit github.com/g8rswimmer/error-chain @@ -27,15 +24,10 @@ github.com/hashicorp/go-multierror # github.com/natefinch/atomic v1.0.1 ## explicit; go 1.12 github.com/natefinch/atomic -# github.com/patrickmn/go-cache v2.1.0+incompatible -## explicit -github.com/patrickmn/go-cache # github.com/paulmach/orb v0.7.1 ## explicit; go 1.15 github.com/paulmach/orb github.com/paulmach/orb/geojson -github.com/paulmach/orb/internal/length -github.com/paulmach/orb/planar # github.com/sfomuseum/go-edtf v1.1.1 ## explicit; go 1.12 github.com/sfomuseum/go-edtf @@ -106,7 +98,7 @@ github.com/whosonfirst/go-whosonfirst-placetypes ## explicit; go 1.12 github.com/whosonfirst/go-whosonfirst-sources github.com/whosonfirst/go-whosonfirst-sources/sources -# github.com/whosonfirst/go-whosonfirst-spatial v0.5.2 +# github.com/whosonfirst/go-whosonfirst-spatial v0.5.3 ## explicit; go 1.18 github.com/whosonfirst/go-whosonfirst-spatial github.com/whosonfirst/go-whosonfirst-spatial/app @@ -114,13 +106,9 @@ github.com/whosonfirst/go-whosonfirst-spatial/database github.com/whosonfirst/go-whosonfirst-spatial/filter github.com/whosonfirst/go-whosonfirst-spatial/flags github.com/whosonfirst/go-whosonfirst-spatial/geo -github.com/whosonfirst/go-whosonfirst-spatial/timer # github.com/whosonfirst/go-whosonfirst-spatial-pip v0.3.1 ## explicit; go 1.18 github.com/whosonfirst/go-whosonfirst-spatial-pip -# github.com/whosonfirst/go-whosonfirst-spatial-rtree v0.2.4 -## explicit; go 1.18 -github.com/whosonfirst/go-whosonfirst-spatial-rtree # github.com/whosonfirst/go-whosonfirst-spr/v2 v2.3.3 ## explicit; go 1.18 github.com/whosonfirst/go-whosonfirst-spr/v2