Skip to content

Commit

Permalink
Replace ZhatCross with UnitVectors
Browse files Browse the repository at this point in the history
  • Loading branch information
simonp0420 committed Mar 3, 2024
1 parent 07a4a56 commit 4eedfc0
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 34 deletions.
2 changes: 1 addition & 1 deletion src/Elements.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ using Printf: @sprintf
import LibGEOS # difference, readgeom, Polygon, MultiPolygon
import GeoInterface # nhole, ngeom, coordinates, getexterior, gethole
import PolygonOps
using ..ZhatCross:
using ..UnitVectors:

macro testpos(var)
return :(all($(esc(var)) .> 0) || error($(esc(string(var))) * " must be positive!"))
Expand Down
2 changes: 1 addition & 1 deletion src/Modes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ using Unitful: ustrip, @u_str
using LinearAlgebra: norm, , ×
using StaticArrays: SVector
using ..Constants: twopi, η₀, dbmin
using ..ZhatCross:
using ..UnitVectors:
using ..Layers: Layer, TEorTM, TE, TM
using ..Sheets: RWGSheet, find_unique_periods
using ..GSMs: Gblock
Expand Down
2 changes: 1 addition & 1 deletion src/Outputs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Outputs
export @outputs, Result, append_result_data, read_result_file, extract_result_file, extract_result

using LinearAlgebra: , norm, ×
using ..ZhatCross:
using ..UnitVectors:
using ..Constants: c₀, twopi
using ..GSMs: GSM
using ..Layers: TEorTM, TE, TM
Expand Down
4 changes: 2 additions & 2 deletions src/PSSFSS.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ using ProgressMeter
using PrecompileTools

include("Constants.jl")
include("ZhatCross.jl")
include("UnitVectors.jl")
include("Log.jl")
include("PSSFSSLen.jl")
include("Rings.jl")
Expand All @@ -46,7 +46,7 @@ include("Modes.jl")
include("Outputs.jl")
include("FastSweep.jl")

using .ZhatCross:
using .UnitVectors:
using .Rings
@reexport using .Sheets: Sheet, RWGSheet, read_sheet_data, nodecount, facecount, edgecount,
export_sheet, STL_ASCII, STL_BINARY
Expand Down
2 changes: 1 addition & 1 deletion src/RWG.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export RWGData, setup_rwg, edge_current_unit_vector, rwgbfft!
using ..Sheets: RWGSheet, SV2
using StaticArrays: SVector, MVector, SArray, @SVector
using LinearAlgebra: , norm, ×
using ..ZhatCross:
using ..UnitVectors:
using NearestNeighbors: KDTree, inrange
using OffsetArrays
using Statistics: mean
Expand Down
41 changes: 41 additions & 0 deletions src/UnitVectors.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
module UnitVectors
export x̂, ŷ, ẑ

using StaticArrays: SVector
import LinearAlgebra: ×, dot

struct UnitVector{N} end # N = 1, 2, or 3 denotes x, y, or z unit vector
const= UnitVector{1}()
const= UnitVector{2}()
const= UnitVector{3}()

dot(::UnitVector{T}, v::AbstractVector) where {T} = v[t]
dot(v::AbstractVector, ::UnitVector{T}) where {T} = v[t]


×(::UnitVector{3}, t::SVector{2,T}) where {T} = SVector{2,T}(-t[2], t[1])

×(::UnitVector{1}, t::SVector{3,T}) where {T} = SVector{3,T}(zero(T), -t[3], t[2])
×(::UnitVector{2}, t::SVector{3,T}) where {T} = SVector{3,T}(t[3], zero(T), -t[1])
×(::UnitVector{3}, t::SVector{3,T}) where {T} = SVector{3,T}(-t[2], t[1], zero(T))

@inline function ×(::UnitVector{1}, t::AbstractVector)
length(t) == 3 && return [zero(eltype(t)), -t[3], t[2]]
throw(ArgumentError("Vector length not 3"))
end

@inline function ×(::UnitVector{2}, t::AbstractVector)
length(t) == 3 && return [t[3], zero(eltype(t)), -t[1]]
throw(ArgumentError("Vector length not 3"))
end

@inline function ×(::UnitVector{3}, t::AbstractVector)
length(t) == 2 && return [-t[2], t[1]]
length(t) == 3 && return [-t[2], t[1], zero(eltype(t))]
throw(ArgumentError("Vector length not 2 or 3"))
end

×(v::AbstractVector, û::UnitVector) = ×(û, -v)


end # module
27 changes: 0 additions & 27 deletions src/ZhatCross.jl

This file was deleted.

2 changes: 1 addition & 1 deletion src/Zint.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ using ..Layers: Layer
using ..RWG: RWGData
using ..PGF: jksums, jkringmax
using LinearAlgebra: , norm, ×
using ..ZhatCross:
using ..UnitVectors:
using Statistics: mean
using OhMyThreads: @tasks, @set, DynamicScheduler, StaticScheduler

Expand Down

0 comments on commit 4eedfc0

Please sign in to comment.