Skip to content

Commit

Permalink
Fixed fundamental bugs in conversion from rectangular to polar of uni…
Browse files Browse the repository at this point in the history
…dimensional coords.
  • Loading branch information
aptmcl committed Oct 10, 2024
1 parent 059249a commit 0baa504
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/Coords.jl
Original file line number Diff line number Diff line change
Expand Up @@ -307,13 +307,13 @@ pol_phi = cyl_phi
Base.getproperty(s::Union{X,VX}, sym::Symbol) =
sym === :y ? 0 :
sym === :z ? 0 :
sym === ? s.x :
sym === ? 0 :
sym === ? abs(s.x) :
sym === ? (s.x < 0 ? 1π : 0) :
sym === ? 0 :
getfield(s, sym)
Base.getproperty(s::Union{XY,VXY}, sym::Symbol) =
sym === :z ? 0 :
sym === ? (0 == s.x ? s.y : s.y == 0 ? s.x : sqrt(s.x^2 + s.y^2)) :
sym === ? (0 == s.x ? abs(s.y) : s.y == 0 ? abs(s.x) : sqrt(s.x^2 + s.y^2)) :
sym === ? (0 == s.x == s.y ? 0 : mod(atan(s.y, s.x), 2pi)) :
sym === ? 0 :
getfield(s, sym)
Expand Down Expand Up @@ -361,11 +361,11 @@ gen_addition(C, c, Vc, vc) =
(+)(v::Vec, p::Loc) = p + v

(-)(p::X, v::VX) =
p.cs === v.cs ? x(p.x - v.x, p.cs) : p + in_cs(v, p.cs)
p.cs === v.cs ? x(p.x - v.x, p.cs) : p - in_cs(v, p.cs)
(-)(p::Union{X,XY}, v::Union{VX,VXY,VPol,VPold}) =
p.cs === v.cs ? xy(p.x - v.x, p.y - v.y, p.cs) : p + in_cs(v, p.cs)
p.cs === v.cs ? xy(p.x - v.x, p.y - v.y, p.cs) : p - in_cs(v, p.cs)
(-)(p::Union{X,XY,XYZ}, v::Union{VX,VXY,VPol,VPold,VXYZ,VCyl,VSph}) =
p.cs === v.cs ? xyz(p.x - v.x, p.y - v.y, p.z - v.z, p.cs) : p + in_cs(v, p.cs)
p.cs === v.cs ? xyz(p.x - v.x, p.y - v.y, p.z - v.z, p.cs) : p - in_cs(v, p.cs)
(-)(p::Pol, v::Union{VX,VXY,VPol,VPold}) =
pol(xy(p) - v)
(-)(p::Cyl, v::Union{VX,VXY,VXYZ,VPol,VPold,VSph}) =
Expand Down Expand Up @@ -903,6 +903,12 @@ Base.isapprox(p::Loc, q::Loc; kwargs...) =
isapprox(wp.x, wq.x; kwargs...) && isapprox(wp.y, wq.y; kwargs...) && isapprox(wp.z, wq.z; kwargs...)
end

Base.isequal(v::Vec, w::Vec) =
let wv = in_world(v),
ww = in_world(w)
isequal(wv.x, ww.x) && isequal(wv.y, ww.y) && isequal(wv.z, ww.z)
end

# angle between

angle_between(v1, v2) =
Expand Down

0 comments on commit 0baa504

Please sign in to comment.