modularize: edit (split, assign_note)

This commit is contained in:
qwjyh 2023-10-22 20:09:49 +09:00
parent 881d542a30
commit 29b78dd27b
No known key found for this signature in database
GPG key ID: F30838CD89227A79
3 changed files with 37 additions and 2 deletions

View file

@ -4,5 +4,6 @@ using Dates
include("typedef.jl")
include("parser.jl")
include("edit.jl")
end # end module CoordVisualize
end # module CoordVisualize

26
src/edit.jl Normal file
View file

@ -0,0 +1,26 @@
"""
split_log(log::CoordLog, at::Unsigned, notes_1::AbstractString, notes_2::AbstractString)::Vector{CoordLog}
Split `log` at `at`, i.e. to `1:at` and `at:end` then assign `notes_1` and `notes_2` to notes for each other.
"""
function split_log(log::CoordLog, at::Unsigned, notes_1::AbstractString, notes_2::AbstractString)::Vector{CoordLog}
@assert at < size(log.coords)[1] "Split index must be less than original log length($(size(log.coords)[1]))"
[
CoordLog(log.coords[1:at, :], log.logdate, notes_1),
CoordLog(log.coords[at:end, :], log.logdate, notes_2),
]
end
function split_log(log::CoordLog, at::Integer, notes_1::AbstractString, notes_2::AbstractString)::Vector{CoordLog}
split_log(log, UInt(at), notes_1, notes_2)
end
"""
assign_note!(log::CoordLog, new_note::AbstractString)
Replace `note` in `log` with `new_note`.
"""
function assign_note!(log::CoordLog, new_note::AbstractString)
log.note = new_note
end

View file

@ -1,7 +1,15 @@
using Dates
struct CoordLog{T <: AbstractFloat}
mutable struct CoordLog{T <: AbstractFloat}
coords::Matrix{T}
logdate::DateTime
note::String
end
"""
n_coords(log::CoordLog)::Integer
Get number of coordinates in `log`.
"""
function n_coords(log::CoordLog)::Integer
size(log.coords)[1]
end