Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to create an anonymous frame. #116

Merged
merged 1 commit into from
Nov 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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