From b6bc4364f798aae666c4c2be3149af9a106b404a Mon Sep 17 00:00:00 2001 From: Riccardo Foffi Date: Tue, 24 Sep 2024 23:25:08 +0200 Subject: [PATCH] update to new LightSumTypes version --- Project.toml | 4 ++-- src/MicrobeAgents.jl | 2 +- src/microbe_step.jl | 4 ++-- src/motility.jl | 37 ++++++++++++++++++++++--------------- 4 files changed, 27 insertions(+), 20 deletions(-) diff --git a/Project.toml b/Project.toml index 72a61ac..03e6500 100644 --- a/Project.toml +++ b/Project.toml @@ -8,8 +8,8 @@ Agents = "46ada45e-f475-11e8-01d0-f70cc89e6671" Autocorrelations = "b9118d5e-f165-4cbd-b2ae-b030566b7b26" DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f" -DynamicSumTypes = "5fcdbb90-de43-509e-b9a6-c4d43f29cf26" GeometryBasics = "5c1252a2-5f33-56bf-86c9-59e7332b4326" +LightSumTypes = "f56206fc-af4c-5561-a72a-43fe2ca5a923" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" MeanSquaredDisplacement = "13c93d70-909c-440c-af92-39d48ffa2ba2" Quaternions = "94ee1d12-ae83-5a48-8b1c-48b8ff168ae0" @@ -22,8 +22,8 @@ Agents = "6" Autocorrelations = "0.1" DataFrames = "1" Distributions = "0.25" -DynamicSumTypes = "1" GeometryBasics = "0.4" +LightSumTypes = "4" MeanSquaredDisplacement = "0.2" Quaternions = "0.7" StaticArrays = "1" diff --git a/src/MicrobeAgents.jl b/src/MicrobeAgents.jl index 03a0c94..b79c24e 100644 --- a/src/MicrobeAgents.jl +++ b/src/MicrobeAgents.jl @@ -7,7 +7,7 @@ export add_agent!, add_agent_own_pos! export move_agent!, walk!, run! using Distributions -using DynamicSumTypes +using LightSumTypes using LinearAlgebra using Random using Quaternions diff --git a/src/microbe_step.jl b/src/microbe_step.jl index 6cb2e9c..e62ad2c 100644 --- a/src/microbe_step.jl +++ b/src/microbe_step.jl @@ -24,7 +24,7 @@ function microbe_step!(microbe::AbstractMicrobe, model::AgentBasedModel) # if the new motile state is a TurnState with duration 0 # immediately turn and transition to another state new_motilestate = motilestate(microbe) - if kindof(new_motilestate) === :TurnState && iszero(duration(new_motilestate)) + if variantof(new_motilestate) === TurnState && iszero(duration(new_motilestate)) turn!(microbe, model) update_motilestate!(microbe, model) end @@ -53,7 +53,7 @@ function microbe_pathfinder_step!(microbe::AbstractMicrobe, model::AgentBasedMod # if the new motile state is a TurnState with duration 0 # immediately turn and transition to another state new_motilestate = motilestate(microbe) - if kindof(new_motilestate) === :TurnState && iszero(duration(new_motilestate)) + if variantof(new_motilestate) === TurnState && iszero(duration(new_motilestate)) turn!(microbe, model) update_motilestate!(microbe, model) end diff --git a/src/motility.jl b/src/motility.jl index f5a0baa..98bb260 100644 --- a/src/motility.jl +++ b/src/motility.jl @@ -5,23 +5,30 @@ export motilepattern, motilestate, state, states, transition_weights export duration, speed, polar, azimuthal export Arccos # from Agents -@sum_structs MotileState begin - @kwdef struct RunState - duration - speed - polar = nothing - azimuthal = nothing - end - @kwdef struct TurnState - duration - speed = [zero(duration)] - polar - azimuthal - end + +struct RunState + duration + speed + polar + azimuthal +end +struct TurnState + duration + speed + polar + azimuthal +end +@sumtype MotileState(RunState, TurnState) +function RunState(; duration, speed, polar=nothing, azimuthal=nothing) + MotileState(RunState(duration, speed, polar, azimuthal)) +end +function TurnState(; duration, speed=[zero(duration)], polar, azimuthal) + MotileState(TurnState(duration, speed, polar, azimuthal)) end -@pattern biased(::RunState) = true -@pattern biased(::TurnState) = false +biased(s::MotileState) = biased(variant(s)) +biased(::RunState) = true +biased(::TurnState) = false # Base motile states Run(duration::Real, speed) = RunState(; duration, speed)