@ Pure public CrossRoad getFirstJunctionPoint ( ) { RoadConnection point = getFirstPoint ( ) ; double distance = 0 ; RoadSegment beforeSegment = null ; RoadSegment afterSegment = null ; int beforeSegmentIndex = - 1 ; int afterSegmentIndex = - 1 ; boolean found = false ; if ( point != null ) { int index = 0 ; for ( final RoadSegment sgmt : this ) { if ( found ) { afterSegment = sgmt ; afterSegmentIndex = index ; //stop now break ; } point = sgmt . getOtherSidePoint ( point ) ; beforeSegment = sgmt ; beforeSegmentIndex = index ; distance += sgmt . getLength ( ) ; final int count = point . getConnectedSegmentCount ( ) ; if ( count != 2 ) { found = true ; } ++ index ; } } if ( found ) { return new CrossRoad ( point , beforeSegment , beforeSegmentIndex , afterSegment , afterSegmentIndex , distance , distance ) ; } return null ; }
Replies the first cul - de - sac or cross - road point in the path .