Skip to content

Commit

Permalink
improve findnear
Browse files Browse the repository at this point in the history
  • Loading branch information
kongdd committed Mar 22, 2024
1 parent 1577baa commit 3062e20
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/MFDataset/tools_Ipaper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@ function rm_empty(x::Vector)
inds, x[inds]
end

# function findnear(values, x)
# _, i = findmin(abs.(values .- x))
# values[i], i
# end

dist(p1, p2) = sqrt((p1[1] - p2[1])^2 + (p1[2] - p2[2])^2)

dist(p1, points::AbstractVector) = [dist(p1, p2) for p2 in points]

# value
findnear(x::Real, values::AbstractVector) = findmin(abs.(values .- x))[2]

# point
findnear(p1, points::AbstractVector) = findmin(dist(p1, points))[2]

export findnear

0 comments on commit 3062e20

Please sign in to comment.