Skip to content

Commit

Permalink
Make all variable and field names consistent with style guide. [#20, … (
Browse files Browse the repository at this point in the history
#123)

* Make all variable and field names consistent with style guide. [#20, #46]

* Use revive with the default configuration.

* also do error string and code style cleanup (revive defaults)
  • Loading branch information
bdon authored Jan 28, 2024
1 parent c45dec8 commit 1a2a1a7
Show file tree
Hide file tree
Showing 21 changed files with 776 additions and 776 deletions.
16 changes: 8 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var cli struct {
Bucket string `help:"Remote bucket"`
Metadata bool `help:"Print only the JSON metadata."`
Tilejson bool `help:"Print the TileJSON."`
PublicUrl string `help:"Public base URL of tile endpoint for TileJSON e.g. https://example.com/tiles"`
PublicURL string `help:"Public base URL of tile endpoint for TileJSON e.g. https://example.com/tiles"`
} `cmd:"" help:"Inspect a local or remote archive."`

Tile struct {
Expand Down Expand Up @@ -83,7 +83,7 @@ var cli struct {
Cors string `help:"Value of HTTP CORS header."`
CacheSize int `default:64 help:"Size of cache in Megabytes."`
Bucket string `help:"Remote bucket"`
PublicUrl string `help:"Public base URL of tile endpoint for TileJSON e.g. https://example.com/tiles/"`
PublicURL string `help:"Public base URL of tile endpoint for TileJSON e.g. https://example.com/tiles/"`
} `cmd:"" help:"Run an HTTP proxy server for Z/X/Y tiles."`

Download struct {
Expand Down Expand Up @@ -116,7 +116,7 @@ func main() {

switch ctx.Command() {
case "show <path>":
err := pmtiles.Show(logger, cli.Show.Bucket, cli.Show.Path, cli.Show.Metadata, cli.Show.Tilejson, cli.Show.PublicUrl, false, 0, 0, 0)
err := pmtiles.Show(logger, cli.Show.Bucket, cli.Show.Path, cli.Show.Metadata, cli.Show.Tilejson, cli.Show.PublicURL, false, 0, 0, 0)
if err != nil {
logger.Fatalf("Failed to show archive, %v", err)
}
Expand All @@ -126,7 +126,7 @@ func main() {
logger.Fatalf("Failed to show tile, %v", err)
}
case "serve <path>":
server, err := pmtiles.NewServer(cli.Serve.Bucket, cli.Serve.Path, logger, cli.Serve.CacheSize, cli.Serve.Cors, cli.Serve.PublicUrl)
server, err := pmtiles.NewServer(cli.Serve.Bucket, cli.Serve.Path, logger, cli.Serve.CacheSize, cli.Serve.Cors, cli.Serve.PublicURL)

if err != nil {
logger.Fatalf("Failed to create new server, %v", err)
Expand All @@ -136,11 +136,11 @@ func main() {

http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
start := time.Now()
status_code, headers, body := server.Get(r.Context(), r.URL.Path)
statusCode, headers, body := server.Get(r.Context(), r.URL.Path)
for k, v := range headers {
w.Header().Set(k, v)
}
w.WriteHeader(status_code)
w.WriteHeader(statusCode)
w.Write(body)
logger.Printf("served %s in %s", r.URL.Path, time.Since(start))
})
Expand All @@ -166,13 +166,13 @@ func main() {
logger.Fatalf("Failed to create temp file, %v", err)
}
} else {
abs_tmproot, err := filepath.Abs(cli.Convert.Tmpdir)
absTemproot, err := filepath.Abs(cli.Convert.Tmpdir)

if err != nil {
logger.Fatalf("Failed to derive absolute path for %s, %v", cli.Convert.Tmpdir, err)
}

tmpfile, err = os.CreateTemp(abs_tmproot, "pmtiles")
tmpfile, err = os.CreateTemp(absTemproot, "pmtiles")

if err != nil {
logger.Fatalf("Failed to create temp file, %v", err)
Expand Down
72 changes: 36 additions & 36 deletions pmtiles/bitmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,54 +15,54 @@ import (
)

func bitmapMultiPolygon(zoom uint8, multipolygon orb.MultiPolygon) (*roaring64.Bitmap, *roaring64.Bitmap) {
boundary_set := roaring64.New()
boundarySet := roaring64.New()

for _, polygon := range multipolygon {
for _, ring := range polygon {
boundary_tiles, _ := tilecover.Geometry(orb.LineString(ring), maptile.Zoom(zoom)) // TODO is this buffer-aware?
for tile := range boundary_tiles {
boundary_set.Add(ZxyToId(uint8(tile.Z), tile.X, tile.Y))
boundaryTiles, _ := tilecover.Geometry(orb.LineString(ring), maptile.Zoom(zoom)) // TODO is this buffer-aware?
for tile := range boundaryTiles {
boundarySet.Add(ZxyToID(uint8(tile.Z), tile.X, tile.Y))
}
}
}

multipolygon_projected := project.MultiPolygon(multipolygon.Clone(), project.WGS84.ToMercator)
multipolygonProjected := project.MultiPolygon(multipolygon.Clone(), project.WGS84.ToMercator)

interior_set := roaring64.New()
i := boundary_set.Iterator()
interiorSet := roaring64.New()
i := boundarySet.Iterator()
for i.HasNext() {
id := i.Next()
if !boundary_set.Contains(id+1) && i.HasNext() {
z, x, y := IdToZxy(id + 1)
if !boundarySet.Contains(id+1) && i.HasNext() {
z, x, y := IDToZxy(id + 1)
tile := maptile.New(x, y, maptile.Zoom(z))
if planar.MultiPolygonContains(multipolygon_projected, project.Point(tile.Center(), project.WGS84.ToMercator)) {
interior_set.AddRange(id+1, i.PeekNext())
if planar.MultiPolygonContains(multipolygonProjected, project.Point(tile.Center(), project.WGS84.ToMercator)) {
interiorSet.AddRange(id+1, i.PeekNext())
}
}
}

return boundary_set, interior_set
return boundarySet, interiorSet
}

func generalizeOr(r *roaring64.Bitmap, minzoom uint8) {
if r.GetCardinality() == 0 {
return
}
max_z, _, _ := IdToZxy(r.ReverseIterator().Next())
maxZ, _, _ := IDToZxy(r.ReverseIterator().Next())

var temp *roaring64.Bitmap
var to_iterate *roaring64.Bitmap
var toIterate *roaring64.Bitmap

temp = roaring64.New()
to_iterate = r
toIterate = r

for current_z := int(max_z); current_z > int(minzoom); current_z-- {
iter := to_iterate.Iterator()
for currentZ := int(maxZ); currentZ > int(minzoom); currentZ-- {
iter := toIterate.Iterator()
for iter.HasNext() {
parent_id := ParentId(iter.Next())
temp.Add(parent_id)
parentID := ParentID(iter.Next())
temp.Add(parentID)
}
to_iterate = temp
toIterate = temp
r.Or(temp)
temp = roaring64.New()
}
Expand All @@ -72,32 +72,32 @@ func generalizeAnd(r *roaring64.Bitmap) {
if r.GetCardinality() == 0 {
return
}
max_z, _, _ := IdToZxy(r.ReverseIterator().Next())
maxZ, _, _ := IDToZxy(r.ReverseIterator().Next())

var temp *roaring64.Bitmap
var to_iterate *roaring64.Bitmap
var toIterate *roaring64.Bitmap

temp = roaring64.New()
to_iterate = r
toIterate = r

for current_z := int(max_z); current_z > 0; current_z-- {
iter := to_iterate.Iterator()
for currentZ := int(maxZ); currentZ > 0; currentZ-- {
iter := toIterate.Iterator()
filled := 0
current := uint64(0) // check me...
for iter.HasNext() {
id := iter.Next()
parent_id := ParentId(id)
if parent_id == current {
filled += 1
parentID := ParentID(id)
if parentID == current {
filled++
if filled == 4 {
temp.Add(parent_id)
temp.Add(parentID)
}
} else {
current = parent_id
current = parentID
filled = 1
}
}
to_iterate = temp
toIterate = temp
r.Or(temp)
temp = roaring64.New()
}
Expand All @@ -107,16 +107,16 @@ func WriteImage(interior *roaring64.Bitmap, boundary *roaring64.Bitmap, exterior
dim := 1 << zoom
img := image.NewNRGBA(image.Rect(0, 0, dim, dim))

min := ZxyToId(zoom, 0, 0)
max := ZxyToId(zoom+1, 0, 0)
min := ZxyToID(zoom, 0, 0)
max := ZxyToID(zoom+1, 0, 0)

{
iter := interior.Iterator()
fill := color.NRGBA{R: 0, G: 255, B: 255, A: 255}
for iter.HasNext() {
id := iter.Next()
if id >= min && id < max {
_, x, y := IdToZxy(id)
_, x, y := IDToZxy(id)
img.Set(int(x), int(y), fill)
}
}
Expand All @@ -127,7 +127,7 @@ func WriteImage(interior *roaring64.Bitmap, boundary *roaring64.Bitmap, exterior
for iter.HasNext() {
id := iter.Next()
if id >= min && id < max {
_, x, y := IdToZxy(id)
_, x, y := IDToZxy(id)
img.Set(int(x), int(y), fill)
}
}
Expand All @@ -138,7 +138,7 @@ func WriteImage(interior *roaring64.Bitmap, boundary *roaring64.Bitmap, exterior
for iter.HasNext() {
id := iter.Next()
if id >= min && id < max {
_, x, y := IdToZxy(id)
_, x, y := IDToZxy(id)
img.Set(int(x), int(y), fill)
}
}
Expand Down
26 changes: 13 additions & 13 deletions pmtiles/bitmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,37 @@ func TestGeneralizeAnd(t *testing.T) {
generalizeAnd(b)
assert.Equal(t, uint64(0), b.GetCardinality())
b = roaring64.New()
b.Add(ZxyToId(3, 0, 0))
b.Add(ZxyToID(3, 0, 0))
generalizeAnd(b)
assert.Equal(t, uint64(1), b.GetCardinality())
b = roaring64.New()
b.Add(ZxyToId(3, 0, 0))
b.Add(ZxyToId(3, 0, 1))
b.Add(ZxyToId(3, 1, 0))
b.Add(ZxyToId(3, 1, 1))
b.Add(ZxyToID(3, 0, 0))
b.Add(ZxyToID(3, 0, 1))
b.Add(ZxyToID(3, 1, 0))
b.Add(ZxyToID(3, 1, 1))
generalizeAnd(b)
assert.Equal(t, uint64(5), b.GetCardinality())
assert.True(t, b.Contains(ZxyToId(2, 0, 0)))
assert.True(t, b.Contains(ZxyToID(2, 0, 0)))
}

func TestGeneralizeOr(t *testing.T) {
b := roaring64.New()
generalizeOr(b, 0)
assert.Equal(t, uint64(0), b.GetCardinality())
b = roaring64.New()
b.Add(ZxyToId(3, 0, 0))
b.Add(ZxyToID(3, 0, 0))
generalizeOr(b, 0)
assert.Equal(t, uint64(4), b.GetCardinality())
assert.True(t, b.Contains(ZxyToId(2, 0, 0)))
assert.True(t, b.Contains(ZxyToId(1, 0, 0)))
assert.True(t, b.Contains(ZxyToId(0, 0, 0)))
assert.True(t, b.Contains(ZxyToID(2, 0, 0)))
assert.True(t, b.Contains(ZxyToID(1, 0, 0)))
assert.True(t, b.Contains(ZxyToID(0, 0, 0)))
}

func TestGeneralizeOrMinZoom(t *testing.T) {
b := roaring64.New()
b.Add(ZxyToId(3, 0, 0))
b.Add(ZxyToID(3, 0, 0))
generalizeOr(b, 2)
assert.Equal(t, uint64(2), b.GetCardinality())
assert.True(t, b.Contains(ZxyToId(2, 0, 0)))
assert.False(t, b.Contains(ZxyToId(1, 0, 0)))
assert.True(t, b.Contains(ZxyToID(2, 0, 0)))
assert.False(t, b.Contains(ZxyToID(1, 0, 0)))
}
12 changes: 6 additions & 6 deletions pmtiles/bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ type Bucket interface {
NewRangeReader(ctx context.Context, key string, offset int64, length int64) (io.ReadCloser, error)
}

type HttpBucket struct {
type HTTPBucket struct {
baseURL string
}

func (b HttpBucket) NewRangeReader(ctx context.Context, key string, offset, length int64) (io.ReadCloser, error) {
func (b HTTPBucket) NewRangeReader(ctx context.Context, key string, offset, length int64) (io.ReadCloser, error) {
reqURL := b.baseURL + "/" + key

req, err := http.NewRequest("GET", reqURL, nil)
Expand All @@ -45,7 +45,7 @@ func (b HttpBucket) NewRangeReader(ctx context.Context, key string, offset, leng
return resp.Body, nil
}

func (b HttpBucket) Close() error {
func (b HTTPBucket) Close() error {
return nil
}

Expand Down Expand Up @@ -102,7 +102,7 @@ func NormalizeBucketKey(bucket string, prefix string, key string) (string, strin

func OpenBucket(ctx context.Context, bucketURL string, bucketPrefix string) (Bucket, error) {
if strings.HasPrefix(bucketURL, "http") {
bucket := HttpBucket{bucketURL}
bucket := HTTPBucket{bucketURL}
return bucket, nil
} else {
bucket, err := blob.OpenBucket(ctx, bucketURL)
Expand All @@ -112,7 +112,7 @@ func OpenBucket(ctx context.Context, bucketURL string, bucketPrefix string) (Buc
if bucketPrefix != "" && bucketPrefix != "/" && bucketPrefix != "." {
bucket = blob.PrefixedBucket(bucket, path.Clean(bucketPrefix)+string(os.PathSeparator))
}
wrapped_bucket := BucketAdapter{bucket}
return wrapped_bucket, err
wrappedBucket := BucketAdapter{bucket}
return wrappedBucket, err
}
}
Loading

0 comments on commit 1a2a1a7

Please sign in to comment.