Skip to content

Commit d4d9ef9

Browse files
author
Andy Ferris
committed
Added tests and fixes
1 parent a9666dc commit d4d9ef9

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

src/commontransformations.jl

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Construct the `Translation` transformation for translating Cartesian points.
1111
immutable Translation{T} <: Transformation
1212
dx::T
1313
end
14+
Translation(x::Tuple) = Translation(Vec(x))
1415
Translation(x,y) = Translation(Vec(x,y))
1516
Translation(x,y,z) = Translation(Vec(x,y,z))
1617
Base.show(io::IO, trans::Translation) = print(io, "Translation$((trans.dx...))")
@@ -19,6 +20,8 @@ function transform(trans::Translation, x)
1920
x + trans.dx
2021
end
2122

23+
transform(trans::Translation, x::Tuple) = Tuple(Vec(x) + trans.dx)
24+
2225
Base.inv(trans::Translation) = Translation(-trans.dx)
2326

2427
function compose(trans1::Translation, trans2::Translation)
@@ -169,6 +172,8 @@ function transform(trans::Rotation, x::FixedVector{3})
169172
(typeof(x2))(m * Vec(x2))
170173
end
171174

175+
transform(trans::Rotation, x::Tuple) = Tuple(transform(trans, Vec(x)))
176+
172177
transform_deriv(trans::Rotation, x) = trans.matrix # It's a linear transformation, so this is easy!
173178

174179
function transform_deriv_params{T}(trans::Rotation{Void,T}, x)
@@ -339,7 +344,7 @@ function transform(trans::RotationYZ, x::FixedVector{3})
339344
(sincos, x2) = promote(Vec(trans.sin, trans.cos), x)
340345
(typeof(x2))(x2[1], x[2]*sincos[2] - x[3]*sincos[1], x[2]*sincos[1] + x[3]*sincos[2])
341346
end
342-
function transform{T}(trans::RotationXY{T}, x)
347+
function transform{T}(trans::RotationYZ{T}, x)
343348
Z = zero(T)
344349
I = one(T)
345350

@@ -348,13 +353,13 @@ function transform{T}(trans::RotationXY{T}, x)
348353
Z trans.sin trans.cos] * x
349354
end
350355

351-
transform(trans::RotationZX, x::Vector) = [x[3]*trans.cos - x[1]*trans.sin, x[2], x[3]*trans.sin + x[1]*trans.cos]
352-
transform(trans::RotationZX, x::NTuple{3}) = (x[3]*trans.cos - x[1]*trans.sin, x[2], x[3]*trans.sin + x[1]*trans.cos)
356+
transform(trans::RotationZX, x::Vector) = [x[3]*trans.sin + x[1]*trans.cos, x[2], x[3]*trans.cos - x[1]*trans.sin]
357+
transform(trans::RotationZX, x::NTuple{3}) = (x[3]*trans.sin + x[1]*trans.cos, x[2], x[3]*trans.cos - x[1]*trans.sin)
353358
function transform(trans::RotationZX, x::FixedVector{3})
354359
(sincos, x2) = promote(Vec(trans.sin, trans.cos), x)
355360
(typeof(x2))(x[3]*sincos[1] + x[1]*sincos[2], x2[2], x[3]*sincos[2] - x[1]*sincos[1])
356361
end
357-
function transform{T}(trans::RotationXY{T}, x)
362+
function transform{T}(trans::RotationZX{T}, x)
358363
Z = zero(T)
359364
I = one(T)
360365

test/commontransformations.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
# Transform
1313
@test transform(trans, x) === Point(3.0, 1.0)
14+
@test transform(trans, Tuple(x)) === (3.0, 1.0)
15+
@test transform(trans, collect(x)) === Vec(3.0, 1.0)
1416

1517
# Transform derivative
1618
m1 = transform_deriv(trans, x)
@@ -61,6 +63,8 @@
6163

6264
# Transform
6365
@test transform(trans, x) x2
66+
@test Vec(transform(trans, Tuple(x))) x2
67+
@test transform(trans, collect(x)) collect(x2)
6468

6569
# Transform derivative
6670
x = Point(2.0,1.0)
@@ -116,6 +120,9 @@
116120

117121
y = transform(trans, x)
118122
@test y == R * Vec(1.0, 2.0, 3.0)
123+
@test transform(trans, Tuple(x)) == Tuple(R * Vec(1.0, 2.0, 3.0))
124+
@test transform(trans, collect(x)) == R * Vec(1.0, 2.0, 3.0)
125+
119126

120127
x_gn = Point(Dual(1.0,(1.,0.,0.)), Dual(2.0,(0.,1.,0.)), Dual(3.0,(0.,0.,1.)))
121128
y_gn = transform(trans, x_gn)
@@ -219,6 +226,8 @@
219226

220227
# Transform
221228
@test transform(trans, x) x2
229+
@test Vec(transform(trans, Tuple(x))) x2
230+
@test Vec(transform(trans, collect(x))) x2
222231

223232
# Transform derivative
224233
x = Point(2.0,1.0,3.0)
@@ -257,6 +266,8 @@
257266

258267
# Transform
259268
@test transform(trans, x) x2
269+
@test Vec(transform(trans, Tuple(x))) x2
270+
@test Vec(transform(trans, collect(x))) x2
260271

261272
# Transform derivative
262273
x = Point(2.0,1.0,3.0)
@@ -295,6 +306,8 @@
295306

296307
# Transform
297308
@test transform(trans, x) x2
309+
@test Vec(transform(trans, Tuple(x))) x2
310+
@test Vec(transform(trans, collect(x))) x2
298311

299312
# Transform derivative
300313
x = Point(2.0,1.0,3.0)

test/coordinatesystems.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
xy = Point(1.0, 2.0)
2323
= Polar(2.23606797749979, 1.1071487177940904)
2424
@test transform(p_from_c, xy)
25+
@test transform(p_from_c, Tuple(xy))
26+
@test transform(p_from_c, collect(xy))
2527
@test transform(c_from_p, rθ) xy
2628

2729
# TODO - define some convenience functions to create the gradient numbers and unpack the arrays.
@@ -142,6 +144,8 @@
142144
xyz = Point(1.0, 2.0, 3.0)
143145
rθϕ = Spherical(3.7416573867739413, 1.1071487177940904, 0.9302740141154721)
144146
@test transform(s_from_cart, xyz) rθϕ
147+
@test transform(s_from_cart, Tuple(xyz)) rθϕ
148+
@test transform(s_from_cart, collect(xyz)) rθϕ
145149
@test transform(cart_from_s, rθϕ) xyz
146150

147151
xyz_gn = Point(Dual(1.0, (1.0, 0.0, 0.0)), Dual(2.0, (0.0, 1.0, 0.0)), Dual(3.0, (0.0, 0.0, 1.0)))
@@ -321,6 +325,8 @@
321325
xyz = Point(1.0, 2.0, 3.0)
322326
rθz = Cylindrical(2.23606797749979, 1.1071487177940904, 3.0)
323327
@test transform(cyl_from_cart, xyz) rθz
328+
@test transform(cyl_from_cart, Tuple(xyz)) rθz
329+
@test transform(cyl_from_cart, collect(xyz)) rθz
324330
@test transform(cart_from_cyl, rθz) xyz
325331

326332
xyz_gn = Point(Dual(1.0, (1.0, 0.0, 0.0)), Dual(2.0, (0.0, 1.0, 0.0)), Dual(3.0, (0.0, 0.0, 1.0)))

0 commit comments

Comments
 (0)