Skip to content

Commit

Permalink
Merge pull request #206 from terranodo/issue-195
Browse files Browse the repository at this point in the history
Issue #195
  • Loading branch information
JivanAmara authored Dec 6, 2017
2 parents 50e28fc + a9ef191 commit de7ef0f
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 8 deletions.
6 changes: 3 additions & 3 deletions mvt/feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,10 @@ func (c *cursor) ScalePoint(p tegola.Point) (nx, ny int64) {
}

func (c *cursor) MinMax() (min, max maths.Pt) {
return maths.Pt{0 - tilebuffer, 0 - tilebuffer},
return maths.Pt{X: 0 - tilebuffer, Y: 0 - tilebuffer},
maths.Pt{
float64(c.extent + tilebuffer),
float64(c.extent + tilebuffer),
X: float64(c.extent + tilebuffer),
Y: float64(c.extent + tilebuffer),
}
}

Expand Down
2 changes: 1 addition & 1 deletion mvt/feature_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestEncodeGeometry(t *testing.T) {
}
*/
testcases := []struct {
desc string `"test":"desc"`
desc string `tbltest:"desc"`
geo basic.Geometry
typ vectorTile.Tile_GeomType
bbox tegola.BoundingBox
Expand Down
6 changes: 2 additions & 4 deletions mvt/layer.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,7 @@ func (l *Layer) VTileLayer(ctx context.Context, extent tegola.BoundingBox) (*vec
}

//Version is the version of tile spec this layer is from.
func (*Layer) Version() int {
return 2
}
func (*Layer) Version() int { return 2 }

// Extent defaults to 4096
func (l *Layer) Extent() int {
Expand Down Expand Up @@ -156,7 +154,7 @@ FEATURES_LOOP:
continue
}
for _, cf := range l.features {
if cf.ID != nil {
if cf.ID == nil {
continue
}
// We matched, we skip
Expand Down
52 changes: 52 additions & 0 deletions mvt/layer_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package mvt

import (
"reflect"
"testing"

"context"

"github.com/gdey/tbltest"
"github.com/terranodo/tegola"
"github.com/terranodo/tegola/basic"
"github.com/terranodo/tegola/mvt/vector_tile"
Expand All @@ -23,6 +25,56 @@ func newTileLayer(name string, keys []string, values []*vectorTile.Tile_Value, f
}
}

func TestLayerAddFeatures(t *testing.T) {
type tc struct {
features []Feature
expected []Feature // Nil means that it's the same as the features.
skipped bool
}
fn := func(idx int, tcase tc) {
defer func() {
if r := recover(); r != nil {
t.Errorf("[%v] did not expect AddFeatures to panic: recovered: %v", idx, r)
}
}()
// First create a blank layer to add the features to.
l := new(Layer)
skipped := l.AddFeatures(tcase.features...)
if tcase.skipped != skipped {
t.Errorf("[%v] skipped value; expected: %v got: %v", idx, tcase.skipped, skipped)
}
gotFeatures := l.Features()
expectedFeatures := tcase.expected
if expectedFeatures == nil {
expectedFeatures = tcase.features
}
if len(gotFeatures) != len(expectedFeatures) {
t.Errorf("[%v] number of features incorrect. expected: %v got: %v", idx, len(expectedFeatures), len(gotFeatures))
}
for i := range expectedFeatures {
if !reflect.DeepEqual(expectedFeatures[i], gotFeatures[i]) {
t.Errorf("[%v] expected feature %v to match. expected: %v got: %v", idx, i, expectedFeatures[i], gotFeatures[i])
}
}
}
newID := func(id uint64) *uint64 { return &id }
tbltest.Cases(
tc{
features: []Feature{
{
Tags: map[string]interface{}{"btag": "tag"},
Geometry: basic.Point{12.0, 15.0},
},
{
ID: newID(1),
Tags: map[string]interface{}{"atag": "tag"},
Geometry: basic.Point{12.0, 15.0},
},
},
},
).Run(fn)
}

func TestLayer(t *testing.T) {
baseBBox := tegola.BoundingBox{
Minx: 0,
Expand Down

0 comments on commit de7ef0f

Please sign in to comment.