Skip to content

Commit

Permalink
Update searchsortednearest(::Grid, ::AbstractCoordinatePoint)
Browse files Browse the repository at this point in the history
  • Loading branch information
fhagemann committed Jul 26, 2021
1 parent 85a4f69 commit e842782
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 25 deletions.
22 changes: 0 additions & 22 deletions src/Grids/Grids.jl
Original file line number Diff line number Diff line change
Expand Up @@ -67,28 +67,6 @@ end
show(io::IO, g::Grid{T, N, S}) where {T, N, S} = print(io, g)
show(io::IO, ::MIME"text/plain", g::Grid{T, N, S}) where {T, N, S} = show(io, g)


function searchsortednearest(pt::CylindricalPoint{T}, g::CylindricalGrid{T})::NTuple{3, Int} where {T <: SSDFloat}
ir::Int = searchsortednearest(g.axes[1].ticks, pt.r)
::Int = searchsortednearest(g.axes[2].ticks, pt.φ)
iz::Int = searchsortednearest(g.axes[3].ticks, pt.z)
ir, iφ, iz
end
function searchsortednearest(pt::CartesianPoint{T}, g::CylindricalGrid{T})::NTuple{3, Int} where {T <: SSDFloat}
return searchsortednearest(CylindricalPoint(pt), g)
end

function searchsortednearest(pt::CartesianPoint{T}, g::CartesianGrid{T, 3})::NTuple{3, Int} where {T <: SSDFloat}
ix::Int = searchsortednearest(g.axes[1].ticks, pt.x)
iy::Int = searchsortednearest(g.axes[2].ticks, pt.y)
iz::Int = searchsortednearest(g.axes[3].ticks, pt.z)
ix, iy, iz
end
function searchsortednearest(pt::CylindricalPoint{T}, g::CartesianGrid{T, 3})::NTuple{3, Int} where {T <: SSDFloat}
return searchsortednearest(CartesianPoint(pt), g)
end


function check_grid(grid::CylindricalGrid{T})::Nothing where {T}
nr::Int, nφ::Int, nz::Int = size(grid)
@assert iseven(nz) "GridError: Field simulation algorithm in cylindrical coordinates needs an even number of grid points in z. This is not the case. #z-ticks = $(nz)."
Expand Down
4 changes: 2 additions & 2 deletions src/SolidStateDetector/DetectorGeometries.jl
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,13 @@ function point_type(c::SolidStateDetector{T}, grid::Grid{T, 3}, p::CartesianPoin
end

# go_to_nearest_gridpoint
function searchsortednearest(grid::Grid{T, 3, Cylindrical}, pt::CylindricalPoint{T})::CylindricalPoint{T} where {T <: SSDFloat}
function searchsortednearest(grid::CylindricalGrid{T}, pt::CylindricalPoint{T})::CylindricalPoint{T} where {T <: SSDFloat}
idx1::Int = searchsortednearest(grid.axes[1].ticks, pt.r)
idx2::Int = searchsortednearest(grid.axes[2].ticks, pt.φ)
idx3::Int = searchsortednearest(grid.axes[3].ticks, pt.z)
CylindricalPoint{T}(grid.axes[1].ticks[idx1], grid.axes[2].ticks[idx2], grid.axes[3].ticks[idx3])
end
function searchsortednearest(grid::Grid{T, 3, Cartesian}, pt::CartesianPoint{T})::CartesianPoint{T} where {T <: SSDFloat}
function searchsortednearest(grid::CartesianGrid3D{T}, pt::CartesianPoint{T})::CartesianPoint{T} where {T <: SSDFloat}
idx1::Int = searchsortednearest(grid.axes[1].ticks, pt.x)
idx2::Int = searchsortednearest(grid.axes[2].ticks, pt.y)
idx3::Int = searchsortednearest(grid.axes[3].ticks, pt.z)
Expand Down
5 changes: 4 additions & 1 deletion src/Types/point_types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ end
@inline getindex(pts::PointTypes{T, N, S}, s::Symbol) where {T, N, S} = getindex(pts.grid, s)

function in(pt::AbstractCoordinatePoint{T}, pts::PointTypes{T, 3, S})::Bool where {T <: SSDFloat, S}
i1::Int, i2::Int, i3::Int = searchsortednearest(pt, pts.grid)
cpt = _convert_point(pt, S)
i1::Int = searchsortednearest(g.axes[1].ticks, cpt[1])
i2::Int = searchsortednearest(g.axes[2].ticks, cpt[2])
i3::Int = searchsortednearest(g.axes[3].ticks, cpt[3])
return pts.data[i1, i2, i3] & pn_junction_bit > 0
end

Expand Down

0 comments on commit e842782

Please sign in to comment.