Skip to content
Permalink
Browse files

fixup some type usages

  • Loading branch information...
paulmach committed Dec 1, 2017
1 parent 7a9cb48 commit 88603330979c9590e8bac7cb2d87ab913f689367
Showing with 41 additions and 39 deletions.
  1. +13 −13 annotate/relation_test.go
  2. +10 −8 marshal.go
  3. +5 −5 osmpbf/decode_data.go
  4. +2 −2 osmpbf/decode_test.go
  5. +2 −2 polygon_test.go
  6. +9 −9 way_test.go
@@ -246,34 +246,34 @@ func TestRelation_Circular(t *testing.T) {
relations := osm.Relations{
&osm.Relation{ID: 1, Version: 1, Visible: true, Timestamp: time.Date(2012, 1, 1, 0, 0, 0, 0, time.UTC),
Members: osm.Members{
osm.Member{Type: osm.TypeRelation, Ref: 2},
osm.Member{Type: osm.TypeRelation, Ref: 3},
{Type: osm.TypeRelation, Ref: 2},
{Type: osm.TypeRelation, Ref: 3},
}},
&osm.Relation{ID: 1, Version: 2, Visible: true, Timestamp: time.Date(2012, 1, 2, 0, 0, 0, 0, time.UTC),
Members: osm.Members{
osm.Member{Type: osm.TypeRelation, Ref: 2},
osm.Member{Type: osm.TypeRelation, Ref: 3},
{Type: osm.TypeRelation, Ref: 2},
{Type: osm.TypeRelation, Ref: 3},
}},
&osm.Relation{ID: 1, Version: 3, Visible: true, Timestamp: time.Date(2012, 1, 3, 0, 0, 0, 0, time.UTC),
Members: osm.Members{
osm.Member{Type: osm.TypeRelation, Ref: 2},
osm.Member{Type: osm.TypeRelation, Ref: 3},
{Type: osm.TypeRelation, Ref: 2},
{Type: osm.TypeRelation, Ref: 3},
}},
&osm.Relation{ID: 2, Version: 1, Visible: true, Timestamp: time.Date(2012, 1, 1, 0, 0, 0, 0, time.UTC),
Members: osm.Members{
osm.Member{Type: osm.TypeRelation, Ref: 3},
{Type: osm.TypeRelation, Ref: 3},
}},
&osm.Relation{ID: 2, Version: 2, Visible: true, Timestamp: time.Date(2012, 1, 4, 0, 0, 0, 0, time.UTC),
Members: osm.Members{
osm.Member{Type: osm.TypeRelation, Ref: 3},
{Type: osm.TypeRelation, Ref: 3},
}},
&osm.Relation{ID: 3, Version: 1, Visible: true, Timestamp: time.Date(2012, 1, 1, 0, 0, 0, 0, time.UTC),
Members: osm.Members{
osm.Member{Type: osm.TypeRelation, Ref: 1},
{Type: osm.TypeRelation, Ref: 1},
}},
&osm.Relation{ID: 3, Version: 2, Visible: true, Timestamp: time.Date(2012, 1, 1, 10, 0, 0, 0, time.UTC),
Members: osm.Members{
osm.Member{Type: osm.TypeRelation, Ref: 1},
{Type: osm.TypeRelation, Ref: 1},
}},
}

@@ -329,15 +329,15 @@ func TestRelation_SelfCircular(t *testing.T) {
rs := osm.Relations{
{ID: 1, Version: 1, Visible: true, Timestamp: time.Date(2012, 1, 1, 0, 0, 0, 0, time.UTC),
Members: osm.Members{
osm.Member{Type: osm.TypeRelation, Ref: 1},
{Type: osm.TypeRelation, Ref: 1},
}},
{ID: 1, Version: 2, Visible: true, Timestamp: time.Date(2012, 1, 2, 0, 0, 0, 0, time.UTC),
Members: osm.Members{
osm.Member{Type: osm.TypeRelation, Ref: 1},
{Type: osm.TypeRelation, Ref: 1},
}},
{ID: 1, Version: 3, Visible: true, Timestamp: time.Date(2012, 1, 3, 0, 0, 0, 0, time.UTC),
Members: osm.Members{
osm.Member{Type: osm.TypeRelation, Ref: 1},
{Type: osm.TypeRelation, Ref: 1},
}},
}

@@ -381,7 +381,7 @@ func nodesChangesetInfo(ns Nodes, ss *stringSet) changesetInfoResult {
return cs
}

func encodeWayNodeIDs(waynodes []WayNode) []int64 {
func encodeWayNodeIDs(waynodes WayNodes) []int64 {
result := make([]int64, len(waynodes))
var prev int64

@@ -393,12 +393,12 @@ func encodeWayNodeIDs(waynodes []WayNode) []int64 {
return result
}

func decodeWayNodeIDs(diff []int64) []WayNode {
func decodeWayNodeIDs(diff []int64) WayNodes {
if len(diff) == 0 {
return nil
}

result := make([]WayNode, len(diff))
result := make(WayNodes, len(diff))
decodeInt64(diff)

for i, d := range diff {
@@ -408,7 +408,7 @@ func decodeWayNodeIDs(diff []int64) []WayNode {
return result
}

func encodeDenseWayNodes(waynodes []WayNode) *osmpb.DenseMembers {
func encodeDenseWayNodes(waynodes WayNodes) *osmpb.DenseMembers {
l := len(waynodes)

versions := make([]int32, l)
@@ -431,7 +431,7 @@ func encodeDenseWayNodes(waynodes []WayNode) *osmpb.DenseMembers {
}
}

func decodeDenseWayNodes(waynodes []WayNode, encoded *osmpb.DenseMembers) {
func decodeDenseWayNodes(waynodes WayNodes, encoded *osmpb.DenseMembers) {
if encoded == nil {
return
}
@@ -461,9 +461,11 @@ func decodeMembers(
result := make(Members, len(roles))
decodeInt64(refs)
for i := range roles {
result[i].Role = ss[roles[i]]
result[i].Ref = refs[i]
result[i].Type = memberTypeMapRev[types[i]]
result[i] = Member{
Role: ss[roles[i]],
Ref: refs[i],
Type: memberTypeMapRev[types[i]],
}
}

return result
@@ -130,15 +130,15 @@ func (dec *dataDecoder) parseWays(pb *osmpbf.PrimitiveBlock, ways []*osmpbf.Way)
for _, way := range ways {
var (
prev int64
nodeIDs []osm.WayNode
nodeIDs osm.WayNodes
)

info := extractInfo(st, way.Info, dateGranularity)
if refs := way.GetRefs(); len(refs) > 0 {
nodeIDs = make([]osm.WayNode, len(refs))
nodeIDs = make(osm.WayNodes, len(refs))
for i, r := range refs {
prev = r + prev // delta encoding
nodeIDs[i].ID = osm.NodeID(prev)
nodeIDs[i] = osm.WayNode{ID: osm.NodeID(prev)}
}
}

@@ -157,7 +157,7 @@ func (dec *dataDecoder) parseWays(pb *osmpbf.PrimitiveBlock, ways []*osmpbf.Way)
}

// Make relation members from stringtable and three parallel arrays of IDs.
func extractMembers(stringTable []string, rel *osmpbf.Relation) []osm.Member {
func extractMembers(stringTable []string, rel *osmpbf.Relation) osm.Members {
memIDs := rel.GetMemids()
types := rel.GetTypes()
roleIDs := rel.GetRolesSid()
@@ -167,7 +167,7 @@ func extractMembers(stringTable []string, rel *osmpbf.Relation) []osm.Member {
return nil
}

members := make([]osm.Member, len(memIDs))
members := make(osm.Members, len(memIDs))
for index := range memIDs {
memID = memIDs[index] + memID // delta encoding

@@ -77,7 +77,7 @@ var (

ew = &osm.Way{
ID: 4257116,
Nodes: []osm.WayNode{
Nodes: osm.WayNodes{
{ID: 21544864},
{ID: 333731851},
{ID: 333731852},
@@ -104,7 +104,7 @@ var (

er = &osm.Relation{
ID: 7677,
Members: []osm.Member{
Members: osm.Members{
{Ref: 4875932, Type: osm.TypeWay, Role: "outer"},
{Ref: 4894305, Type: osm.TypeWay, Role: "inner"},
},
@@ -7,7 +7,7 @@ import (

func TestWayPolygon(t *testing.T) {
w := &Way{}
w.Nodes = []WayNode{
w.Nodes = WayNodes{
{ID: 1}, {ID: 2},
{ID: 3}, {ID: 1},
}
@@ -96,7 +96,7 @@ func TestWayPolygon(t *testing.T) {
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
w := &Way{
Nodes: []WayNode{
Nodes: WayNodes{
{ID: 1}, {ID: 2},
{ID: 3}, {ID: 1},
},
@@ -12,7 +12,7 @@ import (
func TestWayApplyUpdatesUpTo(t *testing.T) {
w := Way{
ID: 123,
Nodes: []WayNode{{Lat: 1}, {Lat: 2}, {Lat: 3}},
Nodes: WayNodes{{Lat: 1}, {Lat: 2}, {Lat: 3}},
Updates: Updates{
{Index: 0, Timestamp: time.Date(2012, 1, 1, 0, 0, 0, 0, time.UTC), Lat: 11},
{Index: 2, Timestamp: time.Date(2013, 1, 1, 0, 0, 0, 0, time.UTC), Lat: 13},
@@ -34,7 +34,7 @@ func TestWayApplyUpdatesUpTo(t *testing.T) {
func TestWayApplyUpdate(t *testing.T) {
w := Way{
ID: 123,
Nodes: []WayNode{{Lat: 1, Lon: 2}},
Nodes: WayNodes{{Lat: 1, Lon: 2}},
}

err := w.applyUpdate(Update{
@@ -56,15 +56,15 @@ func TestWayApplyUpdate(t *testing.T) {
Lon: 4,
}

if expected != w.Nodes[0] {
t.Errorf("incorrect update, got %v", w.Nodes[0])
if !reflect.DeepEqual(expected, w.Nodes[0]) {
t.Errorf("incorrect update, got %+v", w.Nodes[0])
}
}

func TestWayApplyUpdateError(t *testing.T) {
w := Way{
ID: 123,
Nodes: []WayNode{{Lat: 1, Lon: 2}},
Nodes: WayNodes{{Lat: 1, Lon: 2}},
}

err := w.applyUpdate(Update{
@@ -82,9 +82,9 @@ func TestWayApplyUpdateError(t *testing.T) {

func TestWayNodesBounds(t *testing.T) {
wn := WayNodes{
WayNode{Lat: 1, Lon: 2},
WayNode{Lat: 3, Lon: 4},
WayNode{Lat: 2, Lon: 3},
{Lat: 1, Lon: 2},
{Lat: 3, Lon: 4},
{Lat: 2, Lon: 3},
}

b := wn.Bounds()
@@ -125,7 +125,7 @@ func TestWayMarshalXML(t *testing.T) {
}

// node refs
w.Nodes = []WayNode{{ID: 123}}
w.Nodes = WayNodes{{ID: 123}}
data, err = xml.Marshal(w)
if err != nil {
t.Fatalf("xml marshal error: %v", err)

0 comments on commit 8860333

Please sign in to comment.
You can’t perform that action at this time.