You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#######################
### 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.
The text was updated successfully, but these errors were encountered:
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 intostay
instead? Many thanks.The text was updated successfully, but these errors were encountered: