Skip to content

Commit

Permalink
Replace Array with AbstractArray
Browse files Browse the repository at this point in the history
  • Loading branch information
thetazero committed May 10, 2023
1 parent ec79dac commit 8aa39f7
Show file tree
Hide file tree
Showing 10 changed files with 169 additions and 169 deletions.
12 changes: 6 additions & 6 deletions src/astrodynamics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,14 @@ The osculating elements are assumed to be (in order):
6. _M_, Mean anomaly [rad]
Arguments:
- x_oe `x::Array{<:Real, 1}`: Osculating orbital elements. See above for desription of the elements and their required order.
- x_oe `x::AbstractArray{<:Real, 1}`: Osculating orbital elements. See above for desription of the elements and their required order.
- `use_degrees:Bool`: If `true` interpret input will be interpreted as being in degrees, and output will be returned in degrees.
- `GM::Real`: Gravitational constant of central body. Defaults to `SatelliteDynamics.GM_EARTH` if none is provided.
# Returns
- x `x::Array{<:Real, 1}`: Cartesean inertial state. Returns position and velocity. [m; m/s]
- x `x::AbstractArray{<:Real, 1}`: Cartesean inertial state. Returns position and velocity. [m; m/s]
"""
function sOSCtoCART(x_oe::Array{<:Real, 1}; use_degrees::Bool=false, GM::Real=GM_EARTH)
function sOSCtoCART(x_oe::AbstractArray{<:Real, 1}; use_degrees::Bool=false, GM::Real=GM_EARTH)

if use_degrees == true
# Copy and convert input from degrees to radians if necessary
Expand Down Expand Up @@ -238,14 +238,14 @@ The osculating elements are assumed to be (in order):
6. _M_, Mean anomaly [rad]
Arguments:
- x `x::Array{<:Real, 1}`: Cartesean inertial state. Returns position and velocity. [m; m/s]
- x `x::AbstractArray{<:Real, 1}`: Cartesean inertial state. Returns position and velocity. [m; m/s]
- `use_degrees:Bool`: If `true` interpret input will be interpreted as being in degrees, and output will be returned in degrees.
- `GM::Real`: Gravitational constant of central body. Defaults to `SatelliteDynamics.GM_EARTH` if none is provided.
# Returns
- x_oe `x::Array{<:Real, 1}`: Osculating orbital elements. See above for desription of the elements and their required order.
- x_oe `x::AbstractArray{<:Real, 1}`: Osculating orbital elements. See above for desription of the elements and their required order.
"""
function sCARTtoOSC(x::Array{<:Real, 1}; use_degrees::Bool=false, GM::Real=GM_EARTH)
function sCARTtoOSC(x::AbstractArray{<:Real, 1}; use_degrees::Bool=false, GM::Real=GM_EARTH)

# Initialize Cartesian Polistion and Velocity
r = x[1:3]
Expand Down
30 changes: 15 additions & 15 deletions src/attitude.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Arguments:
- `use_degrees:Bool`: If `true` interpret input as being in degrees.
Returns:
- `r::Array{<:Real, 2}`: Rotation matrix
- `r::AbstractArray{<:Real, 2}`: Rotation matrix
References:
1. O. Montenbruck, and E. Gill, _Satellite Orbits: Models, Methods and Applications_, 2012, p.27.
Expand Down Expand Up @@ -39,7 +39,7 @@ Arguments:
- `use_degrees:Bool`: If `true` interpret input as being in degrees.
Returns:
- `r::Array{<:Real, 2}`: Rotation matrix
- `r::AbstractArray{<:Real, 2}`: Rotation matrix
References:
1. O. Montenbruck, and E. Gill, _Satellite Orbits: Models, Methods and Applications_, 2012, p.27.
Expand Down Expand Up @@ -67,7 +67,7 @@ Arguments:
- `use_degrees:Bool`: If `true` interpret input as being in degrees.
Returns:
- `r::Array{<:Real, 2}`: Rotation matrix
- `r::AbstractArray{<:Real, 2}`: Rotation matrix
References:
1. O. Montenbruck, and E. Gill, _Satellite Orbits: Models, Methods and Applications_, 2012, p.27.
Expand Down Expand Up @@ -156,16 +156,16 @@ representation.
Data members:
- `theta::Float64`: Angle of rotation
- `vec::Array{Float64, 1}`: Axis of rotation
- `vec::AbstractArray{Float64, 1}`: Axis of rotation
References:
1. J. Diebel, _Representing attitude: Euler angles, unit quaternions, and rotation vectors._ Matrix 58(15-16) (2006).
"""
mutable struct EulerAxis
angle::Float64
axis::Array{Float64, 1}
axis::AbstractArray{Float64, 1}

function EulerAxis(angle::Real, axis::Array{<:Real, 1})
function EulerAxis(angle::Real, axis::AbstractArray{<:Real, 1})
if length(axis) != 3
throw(ArgumentError("Invalid array for EulerAxis initialization. Input size: $(size(axis)), Required size: (3,)"))
end
Expand All @@ -179,15 +179,15 @@ end
##############

# Quaternion Constructors
function Quaternion(vec::Array{<:Real, 1})
function Quaternion(vec::AbstractArray{<:Real, 1})
if length(vec) != 4
throw(ArgumentError("Invalid array for Quaternion initialization. Input length: $(length(vec)), Required length: 4"))
end

Quaternion(vec...)
end

function Quaternion(mat::Array{<:Real, 2})
function Quaternion(mat::AbstractArray{<:Real, 2})
if size(mat) == (1,4)
# Actually vector initialization. so it and return early
return Quaternion(mat...)
Expand Down Expand Up @@ -377,7 +377,7 @@ Arguments:
- `q::Quaternion`: Quaternion
Returns:
- `vec::Array{Float64, 1}`: Quaternion as a (4,) vector
- `vec::AbstractArray{Float64, 1}`: Quaternion as a (4,) vector
"""
function as_vector(q::Quaternion)
return q[:]
Expand All @@ -392,7 +392,7 @@ Arguments:
- `q::Quaternion`: Quaternion
Returns:
- `mat::Array{Float64, 2}`: Rotation Matrix on SO(3).
- `mat::AbstractArray{Float64, 2}`: Rotation Matrix on SO(3).
"""
function as_matrix(q::Quaternion)
# initialize Empty Matrix
Expand Down Expand Up @@ -591,15 +591,15 @@ end
# EulerAngle #
##############

function EulerAngle(seq::Integer, vec::Array{<:Real, 1})
function EulerAngle(seq::Integer, vec::AbstractArray{<:Real, 1})
if length(vec) != 3
throw(ArgumentError("Invalid array for EulerAngle initialization. Input length: $(length(vec)), Required length: 3"))
end

EulerAngle(seq, vec...)
end

function EulerAngle(seq::Integer, mat::Array{<:Real, 2})
function EulerAngle(seq::Integer, mat::AbstractArray{<:Real, 2})
if size(mat) != (3,3)
throw(ArgumentError("Invalid array for Quaternion initialization. Input size: $(size(mat)), Required size: (3,3)"))
end
Expand Down Expand Up @@ -714,7 +714,7 @@ Arguments:
- `e::EulerAngle` Euler Angle
Returns:
- `evec::Array{Float64, 1}` Euler angles components in vector form.
- `evec::AbstractArray{Float64, 1}` Euler angles components in vector form.
"""
function as_vector(e::EulerAngle)
return [e.phi, e.theta, e.psi]
Expand All @@ -741,15 +741,15 @@ function EulerAxis(angle::Real, v1::Real, v2::Real, v3::Real)
return EulerAxis(angle, [v1, v2, v3])
end

function EulerAxis(vec::Array{<:Real, 1})
function EulerAxis(vec::AbstractArray{<:Real, 1})
if length(vec) != 4
throw(ArgumentError("Invalid array for EulerAxis initialization. Input size: $(size(vec)), Required size: (4,)"))
end

return EulerAxis(vec[1], [vec[2], vec[3], vec[4]])
end

function EulerAxis(mat::Array{<:Real, 2})
function EulerAxis(mat::AbstractArray{<:Real, 2})
if size(mat) != (3,3)
throw(ArgumentError("Invalid array for EulerAxis initialization. Input size: $(size(mat)), Required size: (3,3)"))
end
Expand Down
Loading

0 comments on commit 8aa39f7

Please sign in to comment.