Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update docs, mark funcs deprecated and fix typo #103

Merged
merged 3 commits into from
Mar 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions backports.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ package tzf

// Backports support for not updated systems
//
// tzf will try to maintain timezone name backport compatibility until
// new major version release will remove too old names.
// Deprecated: tzf will no longer support this feature. And wil remove in v0.13.0
var backportstz = map[string]string{
"Europe/Kyiv": "Europe/Kiev", // [2022b] https://github.com/evansiroky/timezone-boundary-builder/releases/tag/2022b commit https://github.com/evansiroky/timezone-boundary-builder/commit/ea87ea5c8bf435d8318a40eb2ab69ea2f7a375aa
"Europe/Uzhgorod": "Europe/Kyiv", // [2022d] https://github.com/evansiroky/timezone-boundary-builder/releases/tag/2022d
Expand Down
30 changes: 30 additions & 0 deletions preindex/preindex.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@
//
// A sample image of output tiles show on maps:
// https://user-images.githubusercontent.com/13536789/200174943-7d40661e-bda5-4b79-a867-ec637e245a49.png
//
// Some areas are excluded from prefindex, since default most small tile `level==11`
// couldn't cover polygon shape details, see [tzf#76] for more backgrounds.
// Latest excluded areas can be views here [exclude.geojson]
//
// [tzf#76]: https://github.com/ringsaturn/tzf/issues/76
// [exclude.geojson]: http://geojson.io/#data=data:text/x-url,https%3A%2F%2Fraw.githubusercontent.com%2Fringsaturn%2Ftzf%2Fmain%2Fpreindex%2Fexclude.geojson
package preindex

import (
Expand Down Expand Up @@ -46,6 +53,29 @@ func DropEdgeTiles(tiles []maptile.Tile) []maptile.Tile {
tilehash[tile] = true
}

/*
Tiles:

┌───────────┬───────────┬───────────┐
│ │ │ │
│ │ │ │
│ x-1,y-1,z │ x+0,y-1,z │ x+1,y-1,z │
│ │ │ │
│ │ │ │
├───────────┼───────────┼───────────┤
│ │ │ │
│ │ │ │
│ x-1,y+0,z │ x+0,y+0,z │ x+1,y+0,z │
│ │ │ │
│ │ │ │
├───────────┼───────────┼───────────┤
│ │ │ │
│ │ │ │
│ x-1,y+1,z │ x+0,y+1,z │ x+1,y+1,z │
│ │ │ │
│ │ │ │
└───────────┴───────────┴───────────┘
*/
// filter all neighbor in tiles
for _, tile := range tiles {
neighbors := []maptile.Tile{
Expand Down
28 changes: 16 additions & 12 deletions tzf.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,27 +192,27 @@ func NewFinderFromCompressed(input *pb.CompressedTimezones, opts ...OptionFunc)
return NewFinderFromPB(tzs, opts...)
}

func getRTreeRangeShifed(lng float64, lat float64) float64 {
func getRTreeRangeShifted(lng float64, lat float64) float64 {
if 73 < lng && lng < 140 && 8 < lat && lat < 54 {
return 70.0
}
return 30.0
}

func (f *Finder) getItemInRanges(lng float64, lat float64) []*tzitem {
candicates := []*tzitem{}
candidates := []*tzitem{}

// TODO(ringsaturn): fix this range
shifted := getRTreeRangeShifed(lng, lat)
shifted := getRTreeRangeShifted(lng, lat)
f.tr.Search([2]float64{lng - shifted, lat - shifted}, [2]float64{lng + shifted, lat + shifted}, func(min, max [2]float64, data *tzitem) bool {
candicates = append(candicates, data)
candidates = append(candidates, data)
return true
})
if len(candicates) == 0 {
candicates = f.items
if len(candidates) == 0 {
candidates = f.items
}

return candicates
return candidates
}

func (f *Finder) getItem(lng float64, lat float64) ([]*tzitem, error) {
Expand All @@ -221,11 +221,11 @@ func (f *Finder) getItem(lng float64, lat float64) ([]*tzitem, error) {
Y: float64(lat),
}
ret := []*tzitem{}
candicates := f.getItemInRanges(lng, lat)
if len(candicates) == 0 {
candidates := f.getItemInRanges(lng, lat)
if len(candidates) == 0 {
return nil, ErrNoTimezoneFound
}
for _, item := range candicates {
for _, item := range candidates {
if item.ContainsPoint(p) {
ret = append(ret, item)
}
Expand Down Expand Up @@ -263,6 +263,7 @@ func (f *Finder) GetTimezoneNames(lng float64, lat float64) ([]string, error) {
return ret, nil
}

// Deprecated: tzf will no longer support this feature. And wil remove in v0.13.0
func (f *Finder) GetTimezoneLoc(lng float64, lat float64) (*time.Location, error) {
item, err := f.getItem(lng, lat)
if err != nil {
Expand All @@ -271,9 +272,10 @@ func (f *Finder) GetTimezoneLoc(lng float64, lat float64) (*time.Location, error
return item[0].location, nil
}

// Deprecated: tzf will no longer support this feature. And wil remove in v0.13.0
func (f *Finder) GetTimezone(lng float64, lat float64) (*pb.Timezone, error) {
if f.opt.DropPBTZ {
return nil, errors.New("tzf: not suppor when reduce mem")
return nil, errors.New("tzf: not support when reduce mem")
}
item, err := f.getItem(lng, lat)
if err != nil {
Expand All @@ -282,6 +284,7 @@ func (f *Finder) GetTimezone(lng float64, lat float64) (*pb.Timezone, error) {
return item[0].pbtz, nil
}

// Deprecated: tzf will no longer support this feature. And wil remove in v0.13.0
func (f *Finder) GetTimezoneShapeByName(name string) (*pb.Timezone, error) {
for _, item := range f.items {
if item.name == name {
Expand All @@ -291,9 +294,10 @@ func (f *Finder) GetTimezoneShapeByName(name string) (*pb.Timezone, error) {
return nil, fmt.Errorf("timezone=%v not found", name)
}

// Deprecated: tzf will no longer support this feature. And wil remove in v0.13.0
func (f *Finder) GetTimezoneShapeByShift(shift int) ([]*pb.Timezone, error) {
if f.opt.DropPBTZ {
return nil, errors.New("tzf: not suppor when reduce mem")
return nil, errors.New("tzf: not support when reduce mem")
}
res := make([]*pb.Timezone, 0)
for _, item := range f.items {
Expand Down