Skip to content

Commit

Permalink
Renamed parameters and fields to make the definitions consistent with…
Browse files Browse the repository at this point in the history
… the docs.
  • Loading branch information
iamazadi committed Apr 10, 2024
1 parent d4b6f32 commit 95c4034
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 59 deletions.
34 changes: 17 additions & 17 deletions src/basemap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,48 +7,48 @@ export make


"""
make(q, gauge, M, segments, chart)
make(x, gauge, M, segments, chart)
Make a 2-surface of the horizontal section at point `q` after transformation with `f`, and with the given `segments` number and `chart`.
Make a 2-surface of the horizontal section at point `x` after transformation with `M`, and with the given `segments` number and `chart`.
"""
function make(q::Quaternion, gauge::Float64, f::Matrix{Float64}, segments::Integer; chart::NTuple{4, Float64} = (-π / 4, π / 4, -π / 4, π / 4))
function make(x::Quaternion, gauge::Float64, M::Matrix{Float64}, segments::Integer; chart::NTuple{4, Float64} = (-π / 4, π / 4, -π / 4, π / 4))
lspaceθ = range(chart[1], stop = chart[2], length = segments)
lspaceϕ = range(chart[3], stop = chart[4], length = segments)
[project(normalize(f * (q * Quaternion(exp* K(1) + -ϕ * K(2)) * exp(gauge * K(3)))))) for ϕ in lspaceϕ, θ in lspaceθ]
[project(normalize(M * (x * Quaternion(exp* K(1) + -ϕ * K(2)) * exp(gauge * K(3)))))) for ϕ in lspaceϕ, θ in lspaceθ]
end


"""
Represents a horizontal subspace.
fields: q, f, chart, segments, color and observable.
fields: x, M, chart, segments, color and observable.
"""
mutable struct Basemap <: Sprite
q::Quaternion
x::Quaternion
gauge::Float64
f::Matrix{Float64}
M::Matrix{Float64}
chart::NTuple{4, Float64}
segments::Integer
color::Any
observable::Tuple{GLMakie.Observable{Matrix{Float64}}, GLMakie.Observable{Matrix{Float64}}, GLMakie.Observable{Matrix{Float64}}}
Basemap(scene::GLMakie.LScene, q::Quaternion, gauge::Float64, f::Matrix{Float64}, chart::NTuple{4, Float64}, segments::Integer, color::Any; transparency::Bool = false) = begin
matrix = make(q, gauge, f, segments, chart = chart)
Basemap(scene::GLMakie.LScene, x::Quaternion, gauge::Float64, M::Matrix{Float64}, chart::NTuple{4, Float64}, segments::Integer, color::Any; transparency::Bool = false) = begin
matrix = make(x, gauge, M, segments, chart = chart)
observable = buildsurface(scene, matrix, color, transparency = transparency)
new(q, gauge, f, chart, segments, color, observable)
new(x, gauge, M, chart, segments, color, observable)
end
end


"""
update!(basemap, q, gauge, M)
update!(basemap, x, gauge, M)
Switch to the right horizontal section with the given point `q`, `gauge` and transformation `f`.
Switch to the right horizontal section with the given point `x`, `gauge` and transformation `M`.
"""
function update!(basemap::Basemap, q::Quaternion, gauge::Float64, f::Matrix{Float64})
basemap.q = q
function update!(basemap::Basemap, x::Quaternion, gauge::Float64, M::Matrix{Float64})
basemap.x = x
basemap.gauge = gauge
basemap.f = f
matrix = make(q, gauge, f, basemap.segments, chart = basemap.chart)
basemap.M = M
matrix = make(x, gauge, M, basemap.segments, chart = basemap.chart)
updatesurface!(matrix, basemap.observable)
end

Expand All @@ -60,7 +60,7 @@ Update the bundle chart in the horizontal subspace with the given 'chart.
"""
function update!(basemap::Basemap, chart::NTuple{4, Float64})
basemap.chart = chart
matrix = make(basemap.q, basemap.gauge, basemap.f, basemap.segments, chart = chart)
matrix = make(basemap.x, basemap.gauge, basemap.M, basemap.segments, chart = chart)
updatesurface!(matrix, basemap.observable)
end

46 changes: 23 additions & 23 deletions src/whirl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,49 +13,49 @@ abstract type Sprite end


"""
make(q, θ1, θ2, f, segments)
make(x, gauge1, gauge2, M, segments)
Make the vertical subspace of the boundary `q`, with the given heights `θ1` and `θ2`, transform `f` and the number of `segments`.
Make the vertical subspace of the boundary `x`, with the given heights `gauge1` and `gauge2`, transform `M` and the number of `segments`.
"""
function make(q::Vector{Quaternion}, θ1::Float64, θ2::Float64, f::Matrix{Float64}, segments::Integer)
lspaceθ = range(θ1, stop = θ2, length = segments)
[project(normalize(f * (q[i] * Quaternion(exp(K(3) * θ))))) for i in 1:length(q), θ in lspaceθ]
function make(x::Vector{Quaternion}, gauge1::Float64, gauge2::Float64, M::Matrix{Float64}, segments::Integer)
lspacegauge = range(gauge1, stop = gauge2, length = segments)
[project(normalize(M * (x[i] * Quaternion(exp(K(3) * gauge))))) for i in 1:length(x), gauge in lspacegauge]
end


"""
Represents a whirl.
fields: q, θ1, θ2, f, segments, color and observable.
fields: x, gauge1, gauge2, M, segments, color and observable.
"""
mutable struct Whirl <: Sprite
q::Vector{Quaternion}
θ1::Float64
θ2::Float64
f::Matrix{Float64}
x::Vector{Quaternion}
gauge1::Float64
gauge2::Float64
M::Matrix{Float64}
segments::Integer
color::Any
observable::Tuple{GLMakie.Observable{Matrix{Float64}}, GLMakie.Observable{Matrix{Float64}}, GLMakie.Observable{Matrix{Float64}}}
Whirl(scene::GLMakie.LScene, q::Vector{Quaternion}, θ1::Float64, θ2::Float64, f::Matrix{Float64}, segments::Integer, color::Any; transparency::Bool = false) = begin
matrix = make(q, θ1, θ2, f, segments)
color_matrix = GLMakie.Observable(fill(color, length(q), segments))
Whirl(scene::GLMakie.LScene, x::Vector{Quaternion}, gauge1::Float64, gauge2::Float64, M::Matrix{Float64}, segments::Integer, color::Any; transparency::Bool = false) = begin
matrix = make(x, gauge1, gauge2, M, segments)
color_matrix = GLMakie.Observable(fill(color, length(x), segments))
observable = buildsurface(scene, matrix, color_matrix, transparency = transparency)
new(q, θ1, θ2, f, segments, color_matrix, observable)
new(x, gauge1, gauge2, M, segments, color_matrix, observable)
end
end


"""
update!(whirl, q, θ1, θ2, f)
update!(whirl, x, gauge1, gauge2, M)
Update the shape of a `whirl` with the given boundary points `q`, gauges `θ1` and `θ2`, and transformation `f`.
Update the shape of a `whirl` with the given boundary points `x`, gauges `gauge1` and `gauge2`, and transformation `M`.
"""
function update!(whirl::Whirl, q::Vector{Quaternion}, θ1::Float64, θ2::Float64, f::Matrix{Float64})
whirl.q = q
whirl.θ1 = θ1
whirl.θ2 = θ2
whirl.f = f
matrix = make(q, θ1, θ2, f, whirl.segments)
function update!(whirl::Whirl, x::Vector{Quaternion}, gauge1::Float64, gauge2::Float64, M::Matrix{Float64})
whirl.x = x
whirl.gauge1 = gauge1
whirl.gauge2 = gauge2
whirl.M = M
matrix = make(x, gauge1, gauge2, M, whirl.segments)
updatesurface!(matrix, whirl.observable)
end

Expand All @@ -66,5 +66,5 @@ end
Update the `color` of a `whirl`.
"""
function update!(whirl::Whirl, color::Any)
whirl.color[] = fill(color, length(whirl.q), whirl.segments)
whirl.color[] = fill(color, length(whirl.x), whirl.segments)
end
12 changes: 6 additions & 6 deletions test/basemap_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import GLMakie
import FileIO


q = Quaternion(normalize(ℝ⁴(rand(4))))
x = Quaternion(normalize(ℝ⁴(rand(4))))
gauge = rand() * 2π
f = I(4)
M = I(4)
chart = (-π / 4, π / 4, -π / 4, π / 4)
matrix = make(q, gauge, f, segments, chart = chart)
matrix = make(x, gauge, M, segments, chart = chart)
@test size(matrix) == (segments, segments)
@test typeof(matrix[1, 1]) <: ℝ³

Expand All @@ -17,11 +17,11 @@ lscene = GLMakie.LScene(fig[1, 1])
segments = rand(5:10)
color = FileIO.load("../data/basemap_color.png")
transparency = rand(1:2) == 1 ? true : false
basemap = Basemap(lscene, q, gauge, f, chart, segments, color, transparency = transparency)
basemap = Basemap(lscene, x, gauge, M, chart, segments, color, transparency = transparency)

matrix = getsurface(basemap.observable, segments, segments)
q = Quaternion(normalize(ℝ⁴(rand(4))))
update!(basemap, q, gauge, f)
x = Quaternion(normalize(ℝ⁴(rand(4))))
update!(basemap, x, gauge, M)
_matrix = getsurface(basemap.observable, segments, segments)

@test all([!isapprox(matrix[i, j], _matrix[i, j]) for i in 1:segments for j in 1:segments])
Expand Down
26 changes: 13 additions & 13 deletions test/whirl_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,29 @@ import GLMakie


N = rand(5:10)
q = [Quaternion(normalize(ℝ⁴(rand(4)))) for i in 1:N]
θ1 = rand()
θ2 = rand()
x = [Quaternion(normalize(ℝ⁴(rand(4)))) for i in 1:N]
gauge1 = rand()
gauge2 = rand()
segments = rand(5:10)
f = I(4)
matrix = make(q, θ1, θ2, f, segments)
M = I(4)
matrix = make(x, gauge1, gauge2, M, segments)
@test size(matrix) == (N, segments)
@test typeof(matrix[1, 1]) <: ℝ³

fig = GLMakie.Figure()
lscene = GLMakie.LScene(fig[1, 1])
color = GLMakie.RGBAf(rand(4)...)
whirl = Whirl(lscene, q, θ1, θ2, f, segments, color, transparency = false)
whirl = Whirl(lscene, x, gauge1, gauge2, M, segments, color, transparency = false)

_q = [Quaternion(normalize(ℝ⁴(rand(4)))) for i in 1:N]
_θ1 = rand()
_θ2 = rand()
_x = [Quaternion(normalize(ℝ⁴(rand(4)))) for i in 1:N]
_gauge1 = rand()
_gauge2 = rand()

update!(whirl, _q, _θ1, _θ2, f)
update!(whirl, _x, _gauge1, _gauge2, M)

@test all([isapprox(whirl.q[i], _q[i]) for i in 1:N])
@test all([isapprox(whirl.θ1, _θ1) for i in 1:N])
@test all([isapprox(whirl.θ2, _θ2) for i in 1:N])
@test all([isapprox(whirl.x[i], _x[i]) for i in 1:N])
@test all([isapprox(whirl.gauge1, _gauge1) for i in 1:N])
@test all([isapprox(whirl.gauge2, _gauge2) for i in 1:N])

_color = GLMakie.RGBAf(rand(4)...)
update!(whirl, _color)
Expand Down

0 comments on commit 95c4034

Please sign in to comment.