From 5307205b51c735ef0dfda81ced0e6917b03a13bd Mon Sep 17 00:00:00 2001 From: Twan Koolen Date: Sun, 6 Nov 2016 16:31:56 -0500 Subject: [PATCH] Add ability to create an anonymous frame. --- src/frames.jl | 5 ++++- test/test_frames.jl | 7 +++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/frames.jl b/src/frames.jl index bb812146..7803f713 100644 --- a/src/frames.jl +++ b/src/frames.jl @@ -11,14 +11,17 @@ const frame_names = Dict{Int64, String}() immutable CartesianFrame3D id::Int64 + function CartesianFrame3D(name::String) ret = new(next_frame_id.x) next_frame_id.x += 1 frame_names[ret.id] = name ret end + + CartesianFrame3D() = new(-1) end -name(frame::CartesianFrame3D) = frame_names[frame.id] +name(frame::CartesianFrame3D) = frame.id >= 0 ? frame_names[frame.id] : "(anonymous)" show(io::IO, frame::CartesianFrame3D) = print(io, "CartesianFrame3D: \"$(name(frame))\"") # enable/disable frame checks diff --git a/test/test_frames.jl b/test/test_frames.jl index 48c834ea..7e5c4a38 100644 --- a/test/test_frames.jl +++ b/test/test_frames.jl @@ -1,6 +1,9 @@ @testset "frames" begin - f1 = CartesianFrame3D("1") - f2 = CartesianFrame3D("2") + f1name = "1" + f1 = CartesianFrame3D(f1name) + f2 = CartesianFrame3D() # anonymous + @test name(f1) == f1name + name(f2) # just to make sure it doesn't crash t1 = rand(Transform3D{Float64}, f2, f1) @test isapprox(t1 * inv(t1), Transform3D{Float64}(f1))