Skip to content

Commit

Permalink
Add ability to create an anonymous frame.
Browse files Browse the repository at this point in the history
  • Loading branch information
tkoolen committed Nov 6, 2016
1 parent a9ee0f4 commit 5307205
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/frames.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions test/test_frames.jl
Original file line number Diff line number Diff line change
@@ -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))
Expand Down

0 comments on commit 5307205

Please sign in to comment.