I’ve been trying for a couple days to write the least number of methods to get rid of a pile of global axis vectors. I was thinking something like axis(custom_type, axis_symbol)
as the API, but that is tentative, because I haven’t been able to get any API working. Here is the relevant code:
import StaticArrays as SA
abstract type BaseVector{N,T<:Real} <: SA.FieldVector{N,T} end
struct Vector2{T<:Real} <: BaseVector{2,T}
x::T
y::T
end
struct Vector3{T<:Real} <: BaseVector{3,T}
x::T
y::T
z::T
end
struct Vector4{T<:Real} <: BaseVector{4,T}
x::T
y::T
z::T
w::T
end
Vector2() = zero(Vector2)
Vector2(s::Real) = Vector2(s, s)
Vector2(vec::BaseVector) = Vector2(vec[1:2]...)
const V2_POSITIVE_X = Vector2(1.0, 0.0)
const V2_NEGATIVE_X = Vector2(-1.0, 0.0)
const V2_POSITIVE_Y = Vector2(0.0, 1.0)
const V2_NEGATIVE_Y = Vector2(0.0, -1.0)
const V3_POSITIVE_X = Vector3(1.0, 0.0, 0.0)
const V3_NEGATIVE_X = Vector3(-1.0, 0.0, 0.0)
const V3_POSITIVE_Y = Vector3(0.0, 1.0, 0.0)
const V3_NEGATIVE_Y = Vector3(0.0, -1.0, 0.0)
const V3_POSITIVE_Z = Vector3(0.0, 0.0, 1.0)
const V3_NEGATIVE_Z = Vector3(0.0, 0.0, -1.0)
Vector3() = zero(Vector3)
Vector3(s::Real) = Vector3(s, s, s)
Vector3(x::T, y::T) where {T<:Real} = Vector3(x, y, zero(T))
Vector3(x::Real, yz::Vector2) = Vector3(x, yz...)
Vector3(xy::Vector2, z::Real) = Vector3(xy..., z)
Vector3(vec::Vector2{T}) where {T<:Real} = Vector3(vec..., zero(T))
Vector3(vec::Union{Vector3,Vector4}) = Vector3(vec[1:3]...)
const V4_POSITIVE_X = Vector4(1.0, 0.0, 0.0, 0.0)
const V4_NEGATIVE_X = Vector4(-1.0, 0.0, 0.0, 0.0)
const V4_POSITIVE_Y = Vector4(0.0, 1.0, 0.0, 0.0)
const V4_NEGATIVE_Y = Vector4(0.0, -1.0, 0.0, 0.0)
const V4_POSITIVE_Z = Vector4(0.0, 0.0, 1.0, 0.0)
const V4_NEGATIVE_Z = Vector4(0.0, 0.0, -1.0, 0.0)
const V4_POSITIVE_W = Vector4(0.0, 0.0, 0.0, 1.0)
const V4_NEGATIVE_W = Vector4(0.0, 0.0, 0.0, -1.0)
Vector4() = zero(Vector4)
Vector4(s::Real) = Vector4(s, s, s, s)
Vector4(x::T, y::T) where {T<:Real} = Vector4(x, y, zero(T), zero(T))
Vector4(x::T, y::T, z::T) where {T<:Real} = Vector4(x, y, z, zero(T))
Vector4(xy::Vector2, z::T) where {T<:Real} = Vector4(xy..., z, zero(T))
Vector4(xy::Vector2, z::T, w::T) where {T<:Real} = Vector4(xy..., z, w)
Vector4(x::T, y::T, zw::Vector2) where {T<:Real} = Vector4(x, y, zw...)
Vector4(x::T, yz::Vector2) where {T<:Real} = Vector4(x, yz..., zero(T))
Vector4(x::T, yz::Vector2, w::T) where {T<:Real} = Vector4(x, yz..., w)
Vector4(xy::T, zw::T) where {T<:Vector2} = Vector4(xy..., zw...)
Vector4(xyz::Vector3, w::Real) = Vector4(xyz..., w)
Vector4(x::Real, yzw::Vector3) = Vector4(x, yzw...)
Vector4(vec::Vector2{T}) where {T<:Real} = Vector4(vec..., zero(T), zero(T))
Vector4(vec::Vector3{T}) where {T<:Real} = Vector4(vec..., zero(T))
Vector4(vec::Vector4) = Vector4(vec...)
# TODO: Replace global axis vectors with methods.
Any help would be appreciated, as I effectively gave up trying to figure out anything that would work at this point. Thank you.