From 1000cd4fd550e2aa9f7216dab8f8a03a74ff6b6f Mon Sep 17 00:00:00 2001 From: SimonDanisch Date: Tue, 19 Jun 2018 17:04:52 +0200 Subject: [PATCH] fix tests --- src/utilities/quaternions.jl | 13 +++++++----- test/quaternions.jl | 16 +++++++++------ test/runtests.jl | 38 ++---------------------------------- 3 files changed, 20 insertions(+), 47 deletions(-) diff --git a/src/utilities/quaternions.jl b/src/utilities/quaternions.jl index 3b8355401..a622a8e2e 100644 --- a/src/utilities/quaternions.jl +++ b/src/utilities/quaternions.jl @@ -85,13 +85,16 @@ function Base.:(*)(q::Quaternion, w::Quaternion) ) end -(::Type{Mat{N}})(q::Quaternion{T}) where {N, T} = Mat4{T}(q) -function (::Type{Mat4{ET}})(q::Quaternion{T}) where {T, ET} +const SMat{N, L} = Mat{N, N, T, L} where T + +SMat{N, L}(q::Quaternion{T}) where {N, T, L} = Mat{N, N, T, L}(q) + +function Mat4{ET}(q::Quaternion{T}) where {T, ET} sx, sy, sz = 2q[4]*q[1], 2q[4]*q[2], 2q[4]*q[3] xx, xy, xz = 2q[1]^2, 2q[1]*q[2], 2q[1]*q[3] yy, yz, zz = 2q[2]^2, 2q[2]*q[3], 2q[3]^2 T0, T1 = zero(ET), one(ET) - Mat{4}( + Mat{4, 4, ET}( T1-(yy+zz), xy+sz, xz-sy, T0, xy-sz, T1-(xx+zz), yz+sx, T0, xz+sy, yz-sx, T1-(xx+yy), T0, @@ -102,12 +105,12 @@ end concrete_type(::Type{Any}, ::Type{T}) where T = T concrete_type(::Type{T}, x) where T = T -function (::Type{Mat{3, ET}})(q::Quaternion{T}) where {T, ET} +function Mat3{ET}(q::Quaternion{T}) where {T, ET} sx, sy, sz = 2q[4]*q[1], 2q[4]*q[2], 2q[4]*q[3] xx, xy, xz = 2q[1]^2, 2q[1]*q[2], 2q[1]*q[3] yy, yz, zz = 2q[2]^2, 2q[2]*q[3], 2q[3]^2 T0, T1 = zero(ET), one(ET) - Mat{3}( + Mat{3, 3, ET}( T1-(yy+zz), xy+sz, xz-sy, xy-sz, T1-(xx+zz), yz+sx, xz+sy, yz-sx, T1-(xx+yy) diff --git a/test/quaternions.jl b/test/quaternions.jl index 23af3061e..7db6fc735 100644 --- a/test/quaternions.jl +++ b/test/quaternions.jl @@ -1,3 +1,6 @@ +using StaticArrays, GeometryTypes + + qx = qrotation(Vec(1, 0, 0), pi / 4) @test qx * qx ≈ qrotation(SVector(1.0, 0.0, 0.0), pi / 2) @test qx^2 ≈ qrotation(SVector(1.0, 0.0, 0.0), pi / 2) @@ -5,21 +8,22 @@ theta = pi / 8 qx = qrotation(SVector(1.0, 0.0, 0.0), theta) c = cos(theta); s = sin(theta) Rx = [1 0 0; 0 c -s; 0 s c] -@test Mat3(qx) ≈ Rx + +@test Mat3f0(qx) ≈ Rx theta = pi / 6 qy = qrotation(SVector(0.0, 1.0, 0.0), theta) c = cos(theta); s = sin(theta) Ry = [c 0 s; 0 1 0; -s 0 c] -@test Mat3(qy) ≈ Ry +@test Mat3f0(qy) ≈ Ry theta = 4pi / 3 qz = qrotation(SVector(0.0, 0.0, 1.0), theta) c = cos(theta); s = sin(theta) Rz = [c -s 0; s c 0; 0 0 1] -@test Mat3(qz) ≈ Rz +@test Mat3f0(qz) ≈ Rz -@test Mat3(qx * qy * qz) ≈ Rx * Ry * Rz -@test Mat3(qy * qx * qz) ≈ Ry * Rx * Rz -@test Mat3(qz * qx * qy) ≈ Rz * Rx * Ry +@test Mat3f0(qx * qy * qz) ≈ Rx * Ry * Rz +@test Mat3f0(qy * qx * qz) ≈ Ry * Rx * Rz +@test Mat3f0(qz * qx * qy) ≈ Rz * Rx * Ry a, b = qrotation(SVector(0.0, 0.0, 1.0), deg2rad(0)), qrotation(SVector(0.0, 0.0, 1.0), deg2rad(180)) # @test slerp(a, b, 0.0) ≈ a diff --git a/test/runtests.jl b/test/runtests.jl index 2c9123d25..8eb90fa25 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -6,40 +6,6 @@ else using Test end +include("quaternions.jl") -# write your own tests here -using Makie - -scene = scatter(rand(10), rand(10), rand(10)) -sub1 = scatter!(rand(10), rand(10), rand(10)) - -@test sub === sub1 -x = rand(10) -sub1 = scatter(1:10, x) -sub2 = scatter(1:10, x) - -sub = lines!(rand(10), rand(10)) -sub1 = lines!(rand(10), rand(10), rand(10)) -@test sub === sub1 -x = rand(10) -sub1 = lines(1:10, x) -sub2 = lines(1:10, x) - -scene = Scene() -x = linspace(0, 6, 100) -s = heatmap!(scene, x, x, (x, y)-> sin(x) + cos(y), show_legend = true) -scene - -# using GeometryTypes -# -# using Base.Test -# -# x = HyperRectangle(Vec3f0(-2), Vec3f0(2)) -# c = HyperRectangle(Vec3f0(-2), Vec3f0(2)) -# @test dont_touch(x, c, Vec3f0(0)) == x -# c = HyperRectangle(Vec3f0(-2), Vec3f0(1.5)) -# @test dont_touch(x, c, Vec3f0(0.25)) == HyperRectangle(Vec3f0(-1.75), Vec3f0(1.5)) -# c = HyperRectangle(Vec3f0(0), Vec3f0(1, 1.75, 1)) -# @test dont_touch(x, c, Vec3f0(0.25)) == HyperRectangle(Vec3f0(-1.25, -2.0, -1.25), Vec3f0(1.0, 1.75, 1.0)) -# x = SimpleRectangle(0, 0, 1, 1) -# SimpleRectangle(HyperRectangle(x)) +# TODO write some AbstractPlotting specific tests... So far functionality is tested in Makie.jl