Skip to content

Commit

Permalink
Finish i
Browse files Browse the repository at this point in the history
  • Loading branch information
helgee committed Feb 10, 2019
1 parent 451dc92 commit 53a3d40
Show file tree
Hide file tree
Showing 4 changed files with 256 additions and 71 deletions.
207 changes: 202 additions & 5 deletions src/i.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,17 @@ export
insrtd,
insrti!,
insrti,
inter
inter,
intmax,
intmin,
invert,
invort,
isordv,
isrchc,
isrchd,
isrchi,
isrot,
iswhsp

function _ident()
matrix = Array{SpiceDouble}(undef, 3, 3)
Expand Down Expand Up @@ -198,7 +208,7 @@ Returns `nothing` if no ellipse could be found.
### References ###
- [NAIF Documentation](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/XXX_c.html)
- [NAIF Documentation](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/inedpl_c.html)
"""
function inedpl(a, b, c, plane)
ellipse = Ellipse()
Expand Down Expand Up @@ -365,14 +375,201 @@ Returns intersection of a and b.
- [NAIF Documentation](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/inter_c.html)
"""
function inter(a::T, b::T) where {T <: SpiceCell{S}} where S
function inter(a::SpiceCell{T}, b::SpiceCell{T}) where {T}
n = card(a) + card(b)
l = max(a.cell.length, b.cell.length)
out = SpiceCell{S}(n, l)
out = SpiceCell{T}(n, l)
ccall((:inter_c, libcspice), Cvoid,
(Ref{Cell{S}}, Ref{Cell{S}}, Ref{Cell{S}}),
(Ref{Cell{T}}, Ref{Cell{T}}, Ref{Cell{T}}),
a.cell, b.cell, out.cell)
handleerror()
out
end

function _intmax()
ccall((:intmax_c, libcspice), SpiceInt, ())
end

@deprecate intmax() typemax(Cint)

"""
intmax()
!!! warning Deprecated
Use `typemax(Cint)` instead.
"""
intmax

function _intmin()
ccall((:intmin_c, libcspice), SpiceInt, ())
end

@deprecate intmin() typemin(Cint)

"""
intmin()
!!! warning Deprecated
Use `typemin(Cint)` instead.
"""
intmin

function _invert(matrix)
out = Array{SpiceDouble}(undef, 3, 3)
ccall((:invert_c, libcspice), Cvoid,
(Ptr{SpiceDouble}, Ptr{SpiceDouble}),
matrix, out)
out
end

@deprecate invert inv

"""
invert(matrix)
!!! warning Deprecated
Use `inv(matrix)` instead.
"""
invert

function _invort(matrix)
out = Array{SpiceDouble}(undef, 3, 3)
ccall((:invort_c, libcspice), Cvoid,
(Ptr{SpiceDouble}, Ptr{SpiceDouble}),
matrix, out)
out
end

@deprecate invort inv

"""
invort(matrix)
!!! warning Deprecated
Use `inv(matrix)` instead.
"""
invort

function _isordv(vec)
vec = SpiceInt.(copy(vec) .- 1)
n = length(vec)
res = ccall((:isordv_c, libcspice), SpiceBoolean,
(Ptr{SpiceInt}, SpiceInt),
vec, n)
Bool(res[])
end

@deprecate isordv isperm

"""
isordv(vec)
!!! warning Deprecated
Use `isperm(vec)` instead.
"""
isordv

function _isrchc(value, array)
data, m, n = chararray(array)
res = ccall((:isrchc_c, libcspice), SpiceInt,
(Cstring, SpiceInt, SpiceInt, Ptr{SpiceChar}),
value, m, n, data)
handleerror()
res[] + 1
end

@deprecate isrchc(value, array) findfirst(array .== item)

"""
isrchc(value, array)
!!! warning Deprecated
Use `findfirst(array .== value)` instead.
"""
isrchc

function _isrchd(value, array)
n = length(array)
res = ccall((:isrchd_c, libcspice), SpiceBoolean,
(SpiceDouble, SpiceInt, Ptr{SpiceDouble}),
value, n, array)
handleerror()
res[] + 1
end

@deprecate isrchd(value, array) findfirst(array .== item)

"""
isrchd(value, array)
!!! warning Deprecated
Use `findfirst(array .== value)` instead.
"""
isrchd

function _isrchi(value, array)
array = SpiceInt.(copy(array))
n = length(array)
res = ccall((:isrchi_c, libcspice), SpiceBoolean,
(SpiceInt, SpiceInt, Ptr{SpiceInt}),
value, n, array)
handleerror()
res[] + 1
end

@deprecate isrchi(value, array) findfirst(array .== item)

"""
isrchi(value, array)
!!! warning Deprecated
Use `findfirst(array .== value)` instead.
"""
isrchi

"""
isrot(m, ntol, dtol)
Indicate whether a 3x3 matrix is a rotation matrix.
### Arguments ###
- `m`: A matrix to be tested
- `ntol`: Tolerance for the norms of the columns of `m`
- `dtol`: Tolerance for the determinant of a matrix whose columns are the unitized columns of `m`
### Output ###
Returns `true` if `m` is a rotation matrix.
### References ###
- [NAIF Documentation](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/isrot_c.html)
"""
function isrot(m, ntol, dtol)
size(m) != (3, 3) && throw(ArgumentError("`m` must be a 3x3 matrix."))
res = ccall((:isrot_c, libcspice), SpiceBoolean,
(Ptr{SpiceDouble}, SpiceDouble, SpiceDouble),
m, ntol, dtol)
handleerror()
Bool(res[])
end

function _iswhsp(str)
res = ccall((:iswhsp_c, libcspice), SpiceBoolean,
(Cstring,),
str)
handleerror()
Bool(res[])
end

@deprecate iswhsp(str) isempty(strip(str))

"""
iswhsp(str)
!!! warning Deprecated
Use `isempty(strip(str))` instead.
"""
iswhsp

2 changes: 1 addition & 1 deletion src/r.jl
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ Convert from rectangular coordinates to geodetic coordinates.
### References ###
- [NAIF Documentation](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/XXX_c.html)
- [NAIF Documentation](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/recgeo_c.html)
"""
function recgeo(rectan, re, f)
length(rectan) != 3 && throw(ArgumentError("Length of `rectan` must be 3."))
Expand Down
11 changes: 5 additions & 6 deletions src/u.jl
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,15 @@ Returns a cell containing the union of `a` and `b`.
- [NAIF Documentation](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/union_c.html)
"""
function Base.union(a::T, b::T) where {T <: SpiceCell{S}} where S
function Base.union(a::SpiceCell{T}, b::SpiceCell{T}) where T
size = max(a.cell.size, b.cell.size)
if S <: SpiceChar
if T <: SpiceChar
length = max(a.cell.length, b.cell.length)
out = SpiceCell{S}(size, length)
out = SpiceCell{T}(size, length)
else
out = SpiceCell{S}(size)
out = SpiceCell{T}(size)
end
ccall((:union_c, libcspice), Cvoid,
(Ref{Cell{S}}, Ref{Cell{S}}, Ref{Cell{S}}),
ccall((:union_c, libcspice), Cvoid, (Ref{Cell{T}}, Ref{Cell{T}}, Ref{Cell{T}}),
a.cell, b.cell, out.cell)
handleerror()
out
Expand Down
107 changes: 48 additions & 59 deletions test/i.jl
Original file line number Diff line number Diff line change
Expand Up @@ -215,64 +215,53 @@ using LinearAlgebra: I, norm
out = inter(c1, c2)
@test out == ["1"]
end


#= @testset "intmax" begin =#
#= @test intmax() >= 2147483647 or intmax() >= 32768 =#
#= =#
#= =#
#= @testset "intmin" begin =#
#= @test intmin() <= -2147483648 or intmin() <= -32768 =#
#= =#
#= =#
#= @testset "invert" begin =#
#= m1 = array([[0.0, -1.0, 0.0], [0.5, 0.0, 0.0], [0.0, 0.0, 1.0]]) =#
#= expected = array([[0.0, 2.0, 0.0], [-1.0, 0.0, 0.0], [0.0, 0.0, 1.0]]) =#
#= mout = invert(m1) =#
#= @test array_equal(expected, mout) =#
#= =#
#= =#
#= @testset "invort" begin =#
#= # I think this is valid... =#
#= m = ident() =#
#= mit = invort(m) =#
#= npt.@test_array_almost_equal(m, mit) =#
#= =#
#= =#
#= @testset "isordv" begin =#
#= @test isordv([0, 1], 2) =#
#= @test isordv([0, 1, 2], 3) =#
#= @test isordv([0, 1, 2, 3], 4) =#
#= @test isordv([1, 1, 1], 3) is False =#
#= =#
#= =#
#= @testset "isrchc" begin =#
#= array = ["1", "0", "4", "2"] =#
#= @test isrchc("4", 4, 3, array) == 2 =#
#= @test isrchc("2", 4, 3, array) == 3 =#
#= @test isrchc("3", 4, 3, array) == -1 =#
#= =#
#= =#
#= @testset "isrchd" begin =#
#= array = [1.0, 0.0, 4.0, 2.0] =#
#= @test isrchd(4.0, 4, array) == 2 =#
#= @test isrchd(2.0, 4, array) == 3 =#
#= @test isrchd(3.0, 4, array) == -1 =#
#= =#
#= =#
#= @testset "isrchi" begin =#
#= array = [1, 0, 4, 2] =#
#= @test isrchi(4, 4, array) == 2 =#
#= @test isrchi(2, 4, array) == 3 =#
#= @test isrchi(3, 4, array) == -1 =#
#= =#
#= =#
#= @testset "isrot" begin =#
#= @test isrot(ident(), 0.0001, 0.0001) =#
#= =#
#= =#
#= @testset "iswhsp" begin =#
#= @test iswhsp(" ") =#
#= @test iswhsp("spice") is False =#
@testset "intmax" begin
@test SPICE._intmax() == typemax(SPICE.SpiceInt)
end
@testset "intmin" begin
@test SPICE._intmin() == typemin(SPICE.SpiceInt)
end
@testset "invert" begin
m1 = [0.0 -1.0 0.0; 0.5 0.0 0.0; 0.0 0.0 1.0]
expected = [0.0 2.0 0.0; -1.0 0.0 0.0; 0.0 0.0 1.0]
mout = SPICE._invert(m1)
@test expected mout
@test inv(m1) mout
end
@testset "invort" begin
m1 = eul2m(3, 2, 1, 3, 2, 1)
@test inv(m1) SPICE._invort(m1)
end
@testset "isordv" begin
@test isperm([1, 2]) == SPICE._isordv([1, 2])
@test isperm([1, 2, 3]) == SPICE._isordv([1, 2, 3])
@test isperm([1, 2, 3, 4]) == SPICE._isordv([1, 2, 3, 4])
@test isperm([1, 1, 1]) == SPICE._isordv([1, 1, 1])
end
@testset "isrchc" begin
array = ["1", "0", "4", "2"]
@test SPICE._isrchc("4", array) == findfirst(array .== "4")
@test SPICE._isrchc("2", array) == findfirst(array .== "2")
end
@testset "isrchd" begin
array = [1.0, 0.0, 4.0, 2.0]
@test SPICE._isrchd(4.0, array) == findfirst(array .== 4.0)
@test SPICE._isrchd(2.0, array) == findfirst(array .== 2.0)
end
@testset "isrchi" begin
array = [1, 0, 4, 2]
@test SPICE._isrchi(4, array) == findfirst(array .== 4)
@test SPICE._isrchi(2, array) == findfirst(array .== 2)
end
@testset "isrot" begin
m = eul2m(3, 2, 1, 3, 2, 1)
@test isrot(m, 0.0001, 0.0001)
@test_throws ArgumentError isrot(m[1:2, 1:2], 0.0001, 0.0001)
@test_throws SpiceError isrot(m, -0.0001, 0.0001)
end
@testset "iswhsp" begin
@test isempty(strip(" ")) == SPICE._iswhsp(" ")
@test isempty(strip("spice")) == SPICE._iswhsp("spice")
end
end

0 comments on commit 53a3d40

Please sign in to comment.