fix edge cases again

This commit is contained in:
Araozu 2024-09-10 18:06:38 -05:00
parent 641624d238
commit ddda0706e4

19
main.go
View File

@ -186,11 +186,7 @@ func main() {
}
// Convert each CombiData into a CombiRoute and store it
for idx, combi := range combis {
if idx > 10 {
break
}
for _, combi := range combis {
log.Printf("Processing %s %s", combi.Company, combi.Ref)
returnCoord := make([][]float64, 0)
combiRoute := CombiRoute{
@ -208,6 +204,14 @@ func main() {
func getCoordinates(ways *[]OsmWay, nodes map[int64]*OsmNode, membersSlice *[]OsmMember) *[][]float64 {
coordinates := make([][]float64, 0)
// filter members, retain only those with type="way"
newMembers := make([]*OsmMember, 0)
for _, m := range *membersSlice {
if m.Type == "way" {
newMembers = append(newMembers, &m)
}
}
// The coordinate list may be reversed
// we shold check that the end of the previous set
// matches the beginning of the next set
@ -219,8 +223,7 @@ func getCoordinates(ways *[]OsmWay, nodes map[int64]*OsmNode, membersSlice *[]Os
var previousWayId int64 = -1
// get all coordinates from each
for _, member := range *membersSlice {
for _, member := range newMembers {
// get the way
way := findOsmway(member.Ref, ways)
@ -234,7 +237,7 @@ func getCoordinates(ways *[]OsmWay, nodes map[int64]*OsmNode, membersSlice *[]Os
if previousNodeId == -1 {
// just add all
secondWay := findOsmway((*membersSlice)[1].Ref, ways)
secondWay := findOsmway(newMembers[1].Ref, ways)
coords = findFirstCoord(way, secondWay, nodes)
for _, c := range coords {
orderedCoordinates = append(orderedCoordinates, c)