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

should it be called "stay" instead of "leave"? #21

Open
bsnyh opened this issue Aug 17, 2019 · 0 comments
Open

should it be called "stay" instead of "leave"? #21

bsnyh opened this issue Aug 17, 2019 · 0 comments

Comments

@bsnyh
Copy link

bsnyh commented Aug 17, 2019

#######################
### Crop Single Way ###
#######################

function crop!(nodes::Dict, bounds::OpenStreetMapX.Bounds, way::OpenStreetMapX.Way)
    valid = falses(length(way.nodes)+2)
    n = 1
    while n <= length(way.nodes)
        if !haskey(nodes, way.nodes[n])
            splice!(way.nodes, n)
            splice!(valid, n+1)
        else
            valid[n+1] = OpenStreetMapX.inbounds(nodes[way.nodes[n]], bounds)
            n += 1
        end
    end
    if sum(valid) == 0
        return true
    elseif sum(valid) < (length(valid)-2)
		leave = trues(length(way.nodes))
        for i in 2:(length(valid)-1)
            if !valid[i]
                if valid[i-1] != valid[i]
                    if !OpenStreetMapX.onbounds(nodes[way.nodes[i-2]], bounds)
                        new_node = OpenStreetMapX.boundary_point(nodes[way.nodes[i-2]], nodes[way.nodes[i-1]],bounds)
                        new_id = OpenStreetMapX.add_new_node!(nodes, new_node)
                        way.nodes[i-1] = new_id
                    else
						leave[i-1] = false
                    end
                elseif valid[i] != valid[i+1]
                    if !OpenStreetMapX.onbounds(nodes[way.nodes[i]], bounds)
                        new_node = OpenStreetMapX.boundary_point(nodes[way.nodes[i-1]], nodes[way.nodes[i]],bounds)
                        new_id = OpenStreetMapX.add_new_node!(nodes, new_node)
                        way.nodes[i-1] = new_id
                    else
                        leave[i-1] = false
                    end
                else
                    leave[i-1] = false
                end
            end
        end
		way.nodes = way.nodes[leave]
        return false
    else
        return false
    end
end

I understand this function. The only confusing point is that, the following line
leave = trues(length(way.nodes)). Would it be better if the leave variable name be changed into stay instead? Many thanks.

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

1 participant