Skip to content

Commit

Permalink
Merge pull request #8 from sisl/jkg/0.7-fixes
Browse files Browse the repository at this point in the history
Only 0.7 fixes
  • Loading branch information
tawheeler committed Aug 14, 2018
2 parents e0fb7a5 + cb0ebb5 commit d3abe62
Show file tree
Hide file tree
Showing 13 changed files with 37 additions and 21 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ notifications:
email: false
script:
- if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
- julia --check-bounds=yes -e 'using Pkg; Pkg.add(pwd()); Pkg.test("Vec"; coverage=true)'
- julia --project --check-bounds=yes -e 'import Pkg; Pkg.build(); Pkg.test("Vec"; coverage=true)'
after_success:
- julia -e 'using Pkg; cd(Pkg.dir("Vec")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'
- julia --project -e 'using Pkg; cd(Pkg.dir("Vec")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'
16 changes: 16 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name = "Vec"
uuid = "44eeaf0b-fee4-471f-9310-ed6585cb3142"
repo = "https://github.com/sisl/Vec.jl.git"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"

[targets]
test = ["Test", "ForwardDiff"]
8 changes: 4 additions & 4 deletions src/coordinate_transforms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,12 @@ function Base.convert(::Type{LatLonAlt}, ecef::ECEF, datum::GeodeticDatum=WGS_84
y = ecef.y
z = ecef.z

λ = atan2(y, x)
λ = atan(y, x)
p = sqrt(x*x + y*y)
θ = atan2(z*a, (p*b))
θ = atan(z*a, (p*b))

h = 0.0
ϕ = atan2(z,p*(1.0-e²))
ϕ = atan(z,p*(1.0-e²))

# the equation diverges at the poles
if isapprox(abs(θ), π/2, atol=0.1)
Expand All @@ -240,7 +240,7 @@ function Base.convert(::Type{LatLonAlt}, ecef::ECEF, datum::GeodeticDatum=WGS_84
while Δh > 1e-4
N = a / sqrt(1-*sin(ϕ)^2)
h₂ = p/cos(ϕ) - N
ϕ = atan2(z, p*(1-*N/(N + h₂)))
ϕ = atan(z, p*(1-*N/(N + h₂)))
Δh = abs(h - h₂)
h = h₂
end
Expand Down
2 changes: 1 addition & 1 deletion src/geom/1d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ end
Base.contains(P::LineSegment1D, v::Float64) = P.a v P.b
Base.contains(P::LineSegment1D, Q::LineSegment1D) = Q.a P.a && Q.b P.b

intersects(P::LineSegment1D, Q::LineSegment1D) = P.b Q.a && Q.b P.a
intersects(P::LineSegment1D, Q::LineSegment1D) = P.b Q.a && Q.b P.a
2 changes: 1 addition & 1 deletion src/geom/geom.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ deltaangle(a::Real, b::Real)
Return the minimum δ such that
a + δ = mod(b, 2π)
"""
deltaangle(a::Real, b::Real) = atan2(sin(b-a), cos(b-a))
deltaangle(a::Real, b::Real) = atan(sin(b-a), cos(b-a))

"""
Distance between two angles
Expand Down
2 changes: 1 addition & 1 deletion src/geom/line_segments.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Base.:-(seg::LineSegment, V::VecE2) = LineSegment(seg.A - V, seg.B - V)
Base.convert(::Type{Line}, seg::LineSegment) = Line(seg.A, seg.B)
Base.convert(::Type{LineSegment}, line::Line) = LineSegment(line.A, line.B)

get_polar_angle(seg::LineSegment) = mod2pi(atan2(seg.B.y - seg.A.y, seg.B.x - seg.A.x))
get_polar_angle(seg::LineSegment) = mod2pi(atan(seg.B.y - seg.A.y, seg.B.x - seg.A.x))

"""
The distance between the line segment and the point P
Expand Down
2 changes: 1 addition & 1 deletion src/geom/lines.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ struct Line
C::VecE2
θ::Float64
end
Line(A::VecE2, B::VecE2) = Line((A+B)/2, atan2(B - A))
Line(A::VecE2, B::VecE2) = Line((A+B)/2, atan(B - A))

Base.:-(line::Line, V::VecE2) = Line(line.C - V, line.θ)
Base.:+(line::Line, V::VecE2) = Line(line.C + V, line.θ)
Expand Down
8 changes: 4 additions & 4 deletions src/quat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ The angle (in radians) between two rotations
"""
function angledist(a::Quat, b::Quat)
d = a * conj(b)
return 2*atan2(LinearAlgebra.norm(imag(d)), abs(d.w))
return 2*atan(LinearAlgebra.norm(imag(d)), abs(d.w))
end

"""
Expand Down Expand Up @@ -143,7 +143,7 @@ The rotation axis for a quaternion.
"""
function get_axis(q::Quat)

θ = 2*atan2(sqrt(q.x*q.x + q.y*q.y + q.z*q.z), q.w)
θ = 2*atan(sqrt(q.x*q.x + q.y*q.y + q.z*q.z), q.w)
h = sin/2)

x = q.x / h
Expand Down Expand Up @@ -191,7 +191,7 @@ function Base.convert(::Type{RPY}, q::Quat)
# roll (x-axis rotation)
sinr = 2(w * x + y * z)
cosr = 1.0 - 2(x * x + y * y)
roll = atan2(sinr, cosr)
roll = atan(sinr, cosr)

# pitch (y-axis rotation)
sinp = 2(w * y - z * x)
Expand All @@ -204,7 +204,7 @@ function Base.convert(::Type{RPY}, q::Quat)
# yaw (z-axis rotation)
siny = 2(w * z + x * y)
cosy = 1.0 - 2(y * y + z * z)
yaw = atan2(siny, cosy)
yaw = atan(siny, cosy)

RPY(roll, pitch, yaw)
end
Expand Down
2 changes: 1 addition & 1 deletion src/vecE2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ polar(r::Real, θ::Real) = VecE2(r*cos(θ), r*sin(θ))

Base.show(io::IO, a::VecE2) = @printf(io, "VecE2(%.3f, %.3f)", a.x, a.y)

Base.atan2(a::VecE2) = atan2(a.y, a.x)
Base.atan(a::VecE2) = atan(a.y, a.x)

dist(a::VecE2, b::VecE2) = hypot(a.x-b.x, a.y-b.y)
function dist2(a::VecE2, b::VecE2)
Expand Down
2 changes: 1 addition & 1 deletion src/vecSE2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function normalize_euclidian(a::VecSE2, p::Real=2)
return VecSE2(a.x/n, a.y/n, a.θ)
end

Base.atan2(a::VecSE2) = atan2(a.y, a.x)
Base.atan(a::VecSE2) = atan(a.y, a.x)

function lerp(a::VecSE2, b::VecSE2, t::Real)
x = a.x + (b.x-a.x)*t
Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Vec
using Test
import LinearAlgebra: norm, normalize, dot
import Random: srand
import Random: seed!

@test invlerp(0.0,1.0,0.5) 0.5
@test invlerp(0.0,1.0,0.4) 0.4
Expand Down
4 changes: 2 additions & 2 deletions test/test_geomE2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ let
@test isapprox(L2.θ, π/4)
L2 = rot180(L)
@test isapprox(L2.θ, π/4 + π)
@test isapprox(get_polar_angle(L), atan2(1,1))
@test isapprox(get_polar_angle(L), atan(1,1))
@test isapprox(get_distance(L, VecE2(0,0)), 0)
@test isapprox(get_distance(L, VecE2(1,1)), 0, atol=1e-10)
@test isapprox(get_distance(L, VecE2(1,0)), 2/2)
Expand All @@ -91,7 +91,7 @@ let
L2 = L - VecE2(-1,1)
@test isapprox(L2.A, VecE2(1,-1))
@test isapprox(L2.B, VecE2(2, 0))
@test isapprox(get_polar_angle(L), atan2(1,1))
@test isapprox(get_polar_angle(L), atan(1,1))
@test isapprox(get_distance(L, VecE2(0,0)), 0)
@test isapprox(get_distance(L, VecE2(1,1)), 0)
@test isapprox(get_distance(L, VecE2(1,0)), 2/2)
Expand Down
4 changes: 2 additions & 2 deletions test/test_quat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ let
@test isapprox(sol, [-0.00250956, -0.948614, 0.316205, mod2pi(-1.84447)], atol=1e-3) ||
isapprox(sol, [ 0.00250956, 0.948614, -0.316205, mod2pi( 1.84447)], atol=1e-3)

srand(0)
seed!(0)
for i in 1 : 5
a = normalize(VecE3(rand(),rand(),rand()))
b = normalize(VecE3(rand(),rand(),rand()))
Expand All @@ -26,7 +26,7 @@ let
@test isapprox(angledist(Quat(1,0,0,0), Quat(0,1,0,0)), π, atol=1e-6)
@test norm(lerp(Quat(1,0,0,0), Quat(0,1,0,0), 0.5) - Quat(2/2, 2/2, 0, 0)) < 1e-6

srand(0)
seed!(0)
for i in 1 : 5
q = rand(Quat)
@test isapprox(norm(q), 1.0, atol=1e-8)
Expand Down

0 comments on commit d3abe62

Please sign in to comment.