From da0608a44e6eeea9fd359bba8f1d43f77a14f931 Mon Sep 17 00:00:00 2001 From: David Perner Date: Mon, 6 Nov 2017 16:15:59 -0800 Subject: [PATCH 1/2] Add strict typing to translate_cam and remove Signal type conversion in map call in PerspectiveCamera. --- src/GLCamera.jl | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/GLCamera.jl b/src/GLCamera.jl index 08c34ec..5180fa3 100644 --- a/src/GLCamera.jl +++ b/src/GLCamera.jl @@ -392,12 +392,16 @@ function imagespace(pos, camera) Point2f0(pos[1], pos[2]) / pos[4] end - - function translate_cam( - translate, proj, view, window_size, prj_type, - eyepos_s, lookat_s, up_s, - ) + translate::T, + proj::Mat4{Float32}, + view::Mat4{Float32}, + window_size::SimpleRectangle{Int}, + prj_type::Projection, + eyepos_s::T, + lookat_s::T, + up_s::T, + ) where T<:Vec3 translate == Vec3f0(0) && return nothing # nothing to do lookat, eyepos, up, prjt = map(value, (lookat_s, eyepos_s, up_s, prj_type)) @@ -480,9 +484,8 @@ function PerspectiveCamera( projectionview = map(*, projectionmatrix, viewmatrix) preserve(map(translate_cam, - trans, Signal(projectionmatrix), Signal(viewmatrix), Signal(window_size), - Signal(projectiontype), Signal(eyeposition), Signal(lookatposition), - Signal(upvector) + trans, projectionmatrix, viewmatrix, window_size, + projectiontype, eyeposition, lookatposition, upvector )) preserve(map(theta) do theta_v From 70a357204157d3c25bce1db68f2ae64331e99f6c Mon Sep 17 00:00:00 2001 From: David Perner Date: Wed, 8 Nov 2017 18:36:55 -0800 Subject: [PATCH 2/2] Revert to previous nested Signal mapping and update input types for translate_cam. Add test to ensure that push!\'ed variables in translate_cam retain their original types. --- src/GLCamera.jl | 19 ++++++++++--------- test/runtests.jl | 28 ++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/src/GLCamera.jl b/src/GLCamera.jl index 5180fa3..dacc318 100644 --- a/src/GLCamera.jl +++ b/src/GLCamera.jl @@ -394,13 +394,13 @@ end function translate_cam( translate::T, - proj::Mat4{Float32}, - view::Mat4{Float32}, - window_size::SimpleRectangle{Int}, - prj_type::Projection, - eyepos_s::T, - lookat_s::T, - up_s::T, + proj::Signal{Mat4{Float32}}, + view::Signal{Mat4{Float32}}, + window_size::Signal{SimpleRectangle{Int}}, + prj_type::Signal{Projection}, + eyepos_s::Signal{T}, + lookat_s::Signal{T}, + up_s::Signal{T}, ) where T<:Vec3 translate == Vec3f0(0) && return nothing # nothing to do @@ -484,8 +484,9 @@ function PerspectiveCamera( projectionview = map(*, projectionmatrix, viewmatrix) preserve(map(translate_cam, - trans, projectionmatrix, viewmatrix, window_size, - projectiontype, eyeposition, lookatposition, upvector + trans, Signal(projectionmatrix), Signal(viewmatrix), Signal(window_size), + Signal(projectiontype), Signal(eyeposition), Signal(lookatposition), + Signal(upvector) )) preserve(map(theta) do theta_v diff --git a/test/runtests.jl b/test/runtests.jl index c9f940c..5b9fa39 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -8,6 +8,7 @@ using GLAbstraction, GeometryTypes, ModernGL, FileIO, GLWindow using ColorTypes using Base.Test import GLAbstraction: N0f8 +import Reactive: Signal @@ -58,4 +59,31 @@ while isopen(window) && i < 20 end GLFW.DestroyWindow(window) +# test for type stability in translate_cam +translate = Vec3f0([1.0, 1.0, 1.0]) +proj = Signal(Mat4{Float32}(eye(Float32,4))) +view_test = Signal(Mat4{Float32}(eye(Float32,4))) +window_size = Signal(SimpleRectangle(-1, -1, 1, 1)) #from DummyCamera +prj_type = Signal(PERSPECTIVE) +eyepos_s = Signal(Vec3f0([1.0, 0.0, 0.0])) +lookat_s = Signal(Vec3f0([0.0, 1.0, 0.0])) +up_s = Signal(Vec3f0([0.0, 0.0, 1.0])) +# Record original types +type_eyepos = typeof(eyepos_s) +type_lookat = typeof(lookat_s) + +GLAbstraction.translate_cam( + translate, + proj, + view_test, + window_size, + prj_type, + eyepos_s, + lookat_s, + up_s +) + +@test typeof(eyepos_s)==type_eyepos +@test typeof(lookat_s)==type_lookat + end