module Geometry export angle2, norm2d, sq_norm2d using StaticArrays: SVector """ angle2(a::SVector{2,Float64}, b::SVector{2,Float64}) Returns the angle φ from vector a to b while φ ∈ [-π, π]. """ function angle2(a::SVector{2,Float64}, b::SVector{2,Float64}) θ_a = atan(a[2], a[1]) θ_b = atan(b[2], b[1]) θ = θ_b - θ_a return rem2pi(θ, RoundNearest) end sq_norm2d(v::SVector{2,Float64}) = v[1]^2 + v[2]^2 norm2d(v::SVector{2,Float64}) = sqrt(sq_norm2d(v)) end # module