Skip to content

Commit

Permalink
minor reformat of raycast
Browse files Browse the repository at this point in the history
  • Loading branch information
axsk committed Jan 17, 2023
1 parent 279fa3e commit e2c2f07
Showing 1 changed file with 6 additions and 20 deletions.
26 changes: 6 additions & 20 deletions src/raycast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -134,23 +134,22 @@ Resumes with successive incircle searches until convergence
Q: Why is this routine split in these two parts
instead of only iterating on the right half plane?
A: Maybe this was faster, using skip only in the first iteration (but is this safe?)
A: The first might find no generator in case of a ray. This is handled explicitly here.
"""

function raycast(sig::Sigma, r::Point, u::Point, xs::Points, searcher::RaycastIncircleSkip)

x0 = xs[sig[1]]

c = maximum(dot(xs[g], u) for g in sig)
#u = convert(typeof(r), u)

# only consider points on the right side of the hyperplane
c = maximum(dot(xs[g], u) for g in sig)
skip(i) = (dot(xs[i], u) <= c) || i sig

# shift candidate onto the plane spanned by the generators
candidate = r + u * (u' * (x0-r))

# compute heuristic t assuming the resulting delauney simplex was regular
# this reduces number of extra searches by about 10%
if length(sig) > 1
n = length(sig)
radius = norm(candidate-x0)
Expand All @@ -159,20 +158,9 @@ function raycast(sig::Sigma, r::Point, u::Point, xs::Points, searcher::RaycastIn
candidate += t * u
end

is, ts = knn(searcher.tree, candidate, 1, false, skip)

if length(is) == 0 # no point was found
return [0; sig], Inf
end
is, _ = knn(searcher.tree, candidate, 1, false, skip)
(length(is) == 0) && return [0; sig], Inf # no point was found
i = is[1]
t = ts[1]

# I had this other check for no point was found
# I dont think it can happen anymore (due to changes in nn) but I leave it for now
if t == Inf
@warn "this should not happen"
return [0; sig], Inf
end

# sucessively reduce incircles unless nothing new is found
while true
Expand All @@ -181,9 +169,7 @@ function raycast(sig::Sigma, r::Point, u::Point, xs::Points, searcher::RaycastIn
candidate = r + t*u
j, d = nn(searcher.tree, candidate)

if j in sig || j == i
break
end
(j in sig || j == i) && break # converged to the smallest circle

dold = sqrt(sum(abs2, x0-candidate))
isapprox(d, dold) && @warn "degenerate vertex at $sig + [$i] ($d $dold)"
Expand Down

1 comment on commit e2c2f07

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Julia benchmark result

Benchmark suite Current: e2c2f07 Previous: 279fa3e Ratio
2/100 7679521 ns 7196868 ns 1.07
2/1000 27295025 ns 24504831 ns 1.11
3/100 28973974 ns 27966312.5 ns 1.04
3/1000 136340998 ns 127632903 ns 1.07
4/100 118964424 ns 112479955 ns 1.06
4/1000 844345489.5 ns 808264241 ns 1.04
5/100 568625324.5 ns 552583898.5 ns 1.03
5/1000 5959720056 ns 5747886594 ns 1.04

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.