ELASTICPATHING/SOURCECODE/UbiComp2014/Elastic_Pathing_Code/navigator.rb
#Find next possible points for a path
Find next possible points for a path
Find next possible points for a path
def possibleTurns(p)
    cur = p.lastTwo()
    possible = []
    if (nil == cur[0])
      possible = intersect(cur[1])
    else
      possible = intersect(cur[1]).select {|node| not p.passed(node)}
      possible=possible.select{|node|
        legal = true
        if (@has_restrictions)
          @map_data.execute("SELECT type from restrictions where nid=#{p.path.last.nid} " +
                            "and from_wid=#{p.path.last.wid}") {|r|
            restriction = r['type']
            turning_angle=turnAngle(cur[0], cur[1], node)
            if ("only_straight_on" == restriction)
              legal = (legal and ((p.path.last.wid == node.wid) or ((turning_angle<8) and (turning_angle>-8))))
            elsif ("only_right_turn" == restriction)
              legal = (legal and (turning_angle>8))
            elsif ("no_right_turn" == restriction)
              legal = (legal and (8 >= turning_angle))
            elsif ("only_left_turn" == restriction)
              legal = (legal and (-8 > turning_angle))
            elsif ("no_left_turn" == restriction)
              legal = (legal and (-8 <= turning_angle))
            elsif ("no_u_turn" == restriction)
              if (turning_angle < -8)
                legal = (legal and (cur[0].distance(node) > cur[1].distance(cur[0])))
              end
            end
          }
        end 
        if (@turnLim==false)
        true
        else
          legal
        end
      }
    end
    return possible
  end
def possibleTurns ( p ) cur = p . lastTwo ( ) possible = [ ] if ( nil == cur [ 0 ] ) possible = intersect ( cur [ 1 ] ) else possible = intersect ( cur [ 1 ] ) . select { | node | not p . passed ( node ) } possible = possible . select { | node | legal = true if ( @has_restrictions ) @map_data . execute ( "SELECT type from restrictions where nid=#{p.path.last.nid} " + "and from_wid=#{p.path.last.wid}" ) { | r | restriction = r [ 'type' ] turning_angle = turnAngle ( cur [ 0 ] , cur [ 1 ] , node ) if ( "only_straight_on" == restriction ) legal = ( legal and ( ( p . path . last . wid == node . wid ) or ( ( turning_angle < 8 ) and ( turning_angle > - 8 ) ) ) ) elsif ( "only_right_turn" == restriction ) legal = ( legal and ( turning_angle > 8 ) ) elsif ( "no_right_turn" == restriction ) legal = ( legal and ( 8 >= turning_angle ) ) elsif ( "only_left_turn" == restriction ) legal = ( legal and ( - 8 > turning_angle ) ) elsif ( "no_left_turn" == restriction ) legal = ( legal and ( - 8 <= turning_angle ) ) elsif ( "no_u_turn" == restriction ) if ( turning_angle < - 8 ) legal = ( legal and ( cur [ 0 ] . distance ( node ) > cur [ 1 ] . distance ( cur [ 0 ] ) ) ) end end } end if ( @turnLim == false ) true else legal end } end return possible end
Find next possible points for a path
Find next possible points for a path
#if (cur[1].nid==104420844) #  puts "Turn restriction: #{@has_restrictions} way id: #{cur[1].wid}" #end #Get any nodes the intersect with cur[1] and is not cur[0] #Now only keep possible nodes where the movement is legal #Multiple restrictions may apply to this road. The legality of the turn #is true only when they are all true. #See if this transition is legal. If it isn't, set legal to false #Any turn is wrong, only legal if the way does not change #A U-turn would lead back to the same way one a 2-way street #or on to the other side of the way on a divided street (but the wid #would change). Can either check the turn angle and look for #something far over 90 degrees or can check to see which ndoes #are closer. #U-turn must be a left turn #If this isn't a U-turn then the distance from the last node to the #next node should be more than the distance from the current node #(the pivot) to the last node. #if @has_restrictions #Return the legal value from the block
p