Skip to content

Commit 4218bcc

Browse files
committed
Simplify AxisTensor idxin function
The previous idxin method for a 1d axis tensor behaved different that non singlular dimension axistensors. This commit unifies all the different methods by using unrolled_findfirst
1 parent 803bb6b commit 4218bcc

2 files changed

Lines changed: 3 additions & 27 deletions

File tree

src/Geometry/Geometry.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module Geometry
22

33
using ..RecursiveApply
44
import LinearAlgebra
5+
import UnrolledUtilities: unrolled_findfirst
56

67
using StaticArrays
78

src/Geometry/axistensors.jl

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -61,33 +61,8 @@ coordinate_axis(::Type{<:LatLongPoint}) = (1, 2)
6161

6262
coordinate_axis(coord::AbstractPoint) = coordinate_axis(typeof(coord))
6363

64-
@inline idxin(I::Tuple{Int}, i::Int) = 1
65-
66-
@inline function idxin(I::Tuple{Int, Int}, i::Int)
67-
@inbounds begin
68-
if I[1] == i
69-
return 1
70-
elseif I[2] == i
71-
return 2
72-
else
73-
return nothing
74-
end
75-
end
76-
end
77-
78-
@inline function idxin(I::Tuple{Int, Int, Int}, i::Int)
79-
@inbounds begin
80-
if I[1] == i
81-
return 1
82-
elseif I[2] == i
83-
return 2
84-
elseif I[3] == i
85-
return 3
86-
else
87-
return nothing
88-
end
89-
end
90-
end
64+
@inline idxin(I::NTuple{N, Int}, i::Int) where {N} =
65+
unrolled_findfirst(isequal(i), I)
9166

9267
struct PropertyError <: Exception
9368
ax::Any

0 commit comments

Comments
 (0)