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

what is the logic of the following function "find_segments"? #23

Open
bsnyh opened this issue Aug 18, 2019 · 1 comment
Open

what is the logic of the following function "find_segments"? #23

bsnyh opened this issue Aug 18, 2019 · 1 comment

Comments

@bsnyh
Copy link

bsnyh commented Aug 18, 2019

function find_segments(nodes::Dict{Int,T}, highways::Vector{OpenStreetMapX.Way}, intersections::Dict{Int,Set{Int}}) where T<:Union{OpenStreetMapX.ENU,OpenStreetMapX.ECEF}
    segments = OpenStreetMapX.Segment[]
    intersect = Set(keys(intersections))
    for highway in highways
        firstNode = 1
        for j = 2:length(highway.nodes)
            if highway.nodes[firstNode] != highway.nodes[j] && (in(highway.nodes[j], intersect)|| j == length(highway.nodes))
                if !reverseway(highway)
                    seg = OpenStreetMapX.Segment(highway.nodes[firstNode],highway.nodes[j],highway.nodes[firstNode:j], OpenStreetMapX.distance(nodes, highway.nodes[firstNode:j]), highway.id)
                    push!(segments,seg)
                else
                    seg = OpenStreetMapX.Segment(highway.nodes[j],highway.nodes[firstNode],reverse(highway.nodes[firstNode:j]), OpenStreetMapX.distance(nodes, highway.nodes[firstNode:j]), highway.id)
                    push!(segments,seg)
                end
                if !oneway(highway)
                    seg = OpenStreetMapX.Segment(highway.nodes[j],highway.nodes[firstNode],reverse(highway.nodes[firstNode:j]), OpenStreetMapX.distance(nodes, highway.nodes[firstNode:j]), highway.id)
                    push!(segments,seg)
                end
				firstNode = j
            end
        end
    end
    return segments
end

Hi, I have a question about the logic of the first if statement. I do not quite understand how it works. I mean, why is it exactly like this? Based on my understanding, highway.nodes[firstNode] is always not the same as highway.nodes[j], right? Moreover, why do we require highway.nodes[j] in the set intersect? It is rather strange to me at least. Could you kindly clarify a little bit?

@pszufe
Copy link
Owner

pszufe commented Aug 27, 2019

Since Ways represent any kind of shape I understand that we can have a situation where the same nodes can occur more than once in a single Way. From graph routing point of view this means having an unnecessary cycle and hence should be avoided. Perhaps @bartoszpankratz can elaborate more on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants