Skip to content
This repository has been archived by the owner on Jul 13, 2021. It is now read-only.

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonDanisch committed Jun 19, 2018
1 parent af80daf commit 1000cd4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 47 deletions.
13 changes: 8 additions & 5 deletions src/utilities/quaternions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand Down
16 changes: 10 additions & 6 deletions test/quaternions.jl
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
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)
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
Expand Down
38 changes: 2 additions & 36 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 1000cd4

Please sign in to comment.