Skip to content

Commit

Permalink
Split off sort_array_by_distance function
Browse files Browse the repository at this point in the history
  • Loading branch information
nanaya committed Nov 17, 2024
1 parent 866e06f commit d45aedd
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 667 deletions.
22 changes: 0 additions & 22 deletions app/javascript/src/legacy/common.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -93,28 +93,6 @@ window.onerror = (error, file, line) ->
ReportError error, file, line, null
return

###
# Return the values of list starting at idx and moving outwards.
#
# sort_array_by_distance([0,1,2,3,4,5,6,7,8,9], 5)
# [5,4,6,3,7,2,8,1,9,0]
###

window.sort_array_by_distance = (list, idx) ->
ret = []
ret.push list[idx]
distance = 1
loop
length = ret.length
if idx - distance >= 0
ret.push list[idx - distance]
if idx + distance < list.length
ret.push list[idx + distance]
if length == ret.length
break
++distance
ret

### Return the squared distance between two points. ###

window.distance_squared = (x1, y1, x2, y2) ->
Expand Down
Loading

0 comments on commit d45aedd

Please sign in to comment.