Skip to content
This repository has been archived by the owner on Oct 23, 2022. It is now read-only.

Removing functions zero3 and one3. #159

Merged
merged 2 commits into from
Apr 30, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 0 additions & 4 deletions docs/src/basic_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ OpticSim.Geometry.Vec3
OpticSim.Geometry.unitX3
OpticSim.Geometry.unitY3
OpticSim.Geometry.unitZ3
OpticSim.Geometry.zero3
OpticSim.Geometry.one3
```

## Vec4
Expand All @@ -29,8 +27,6 @@ OpticSim.Geometry.unitX4
OpticSim.Geometry.unitY4
OpticSim.Geometry.unitZ4
OpticSim.Geometry.unitW4
OpticSim.Geometry.zero4
OpticSim.Geometry.one4
```

## Transform
Expand Down
41 changes: 8 additions & 33 deletions src/Geometry/Transform.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,8 @@ unitY3(::Type{T} = Float64) where {T<:Real} = Vec3{T}(zero(T), one(T), zero(T))
returns the unit vector `[0, 0, 1]`
"""
unitZ3(::Type{T} = Float64) where {T<:Real} = Vec3{T}(zero(T), zero(T), one(T))
"""
returns the unit vector `[0, 0, 0]`
"""
zero3(::Type{T} = Float64) where {T<:Real} = zeros(Vec3{T})
"""
returns the unit vector `[1, 1, 1]`
"""
one3(::Type{T} = Float64) where {T<:Real} = Vec3{T}(one(T), one(T), one(T))

export unitX3, unitY3, unitZ3, zero3, one3
export unitX3, unitY3, unitZ3

#endregion Vec3

Expand Down Expand Up @@ -105,16 +97,8 @@ unitZ4(::Type{T} = Float64) where {T<:Real} = Vec4{T}(zero(T), zero(T), one(T),
returns the unit vector `[0, 0, 0, 1]`
"""
unitW4(::Type{T} = Float64) where {T<:Real} = Vec4{T}(zero(T), zero(T), zero(T), one(T))
"""
returns the unit vector `[0, 0, 0, 0]`
"""
zero4(::Type{T} = Float64) where {T<:Real} = zeros(Vec4{T})
"""
returns the unit vector `[1, 1, 1, 1]`
"""
one4(::Type{T} = Float64) where {T<:Real} = Vec4{T}(one(T), one(T), one(T), one(T))

export unitX4, unitY4, unitZ4, unitW4, zero4, one4
export unitX4, unitY4, unitZ4, unitW4
#endregion Vec4


Expand Down Expand Up @@ -163,6 +147,7 @@ Transform(rotation::AbstractArray{S,2}, translation::AbstractArray{S,1})
Transform{T} = SMatrix{4,4,T,16}
export Transform

lastrow(::Type{T}) where{T<:Real} = SMatrix{1,4,T}(zero(T),zero(T),zero(T),one(T))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about lastrow(::Type{T} = Float64) to conform with the rest of the code in Transform.jl?

i'll probably revisit these convenience functions later as i think they could be a little more systematic, but this is fine for now

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lastrow was only being used in one place so I removed the function and inlined it.


# for compatability ith the "old" RigidBodyTransform
"""
Expand Down Expand Up @@ -193,27 +178,18 @@ end

Costruct a transform from the input columns.
"""
function Transform(colx::Vec3{T}, coly::Vec3{T}, colz::Vec3{T}, colw::Vec3{T} = zero3(T)) where {T<:Real}
return Transform{T}(
colx[1], colx[2], colx[3], zero(T),
coly[1], coly[2], coly[3], zero(T),
colz[1], colz[2], colz[3], zero(T),
colw[1], colw[2], colw[3], one(T)
)
function Transform(colx::Vec3{T}, coly::Vec3{T}, colz::Vec3{T}, colw::Vec3{T} = zero(Vec3{T})) where {T<:Real}
return vcat(hcat(colx,coly,colz,colw),lastrow(T))
end


"""
Transform(colx::Vec3{T}, coly::Vec3{T},colz::Vec3{T}, colw::Vec3{T}, ::Type{T} = Float64) where {T<:Real}

Costruct a transform from the input columns.
"""
function Transform(colx::Vec4{T}, coly::Vec4{T}, colz::Vec4{T}, colw::Vec4{T}) where {T<:Real}
return Transform{T}(
colx[1], colx[2], colx[3], colx[4],
coly[1], coly[2], coly[3], coly[4],
colz[1], colz[2], colz[3], colz[4],
colw[1], colw[2], colw[3], colw[4]
)
return hcat(colx,coly,colz,colw)
end

"""
Expand Down Expand Up @@ -259,7 +235,6 @@ function Transform(rotation::AbstractArray{T,2}, translation::AbstractArray{T,1}
translation[1], translation[2], translation[3], one(T))
end


"""
rotationX(angle::T) where {T<:Real} -> Transform

Expand Down Expand Up @@ -333,7 +308,7 @@ function rotation(t::Transform{T}) where {T<:Real}
t[1, 1], t[2, 1], t[3, 1],
t[1, 2], t[2, 2], t[3, 2],
t[1, 3], t[2, 3], t[3, 3])
return Transform(rot, zero3(T))
return Transform(rot, zero(Vec3{T}))
end

"""
Expand Down
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ alltestsets = [
"Visualization",
"Allocations",
"GlassCat",
"Transform"
]

runtestsets = ALL_TESTS ? alltestsets : intersect(alltestsets, ARGS)
Expand Down
24 changes: 24 additions & 0 deletions test/testsets/Transform.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# MIT license
# Copyright (c) Microsoft Corporation. All rights reserved.
# See LICENSE in the project root for full license information.

@testset "Transform" begin
A = [
1 2 3 4;
4 5 6 7;
8 9 10 11;
12 13 14 15
]
x,y,z,w = Vec4.([A[:,i] for i in 1:4])
@test Geometry.Transform(x,y,z,w) == A

B = [
1 2 3 4;
4 5 6 7;
8 9 10 11;
0 0 0 1
]
x,y,z,w = Vec3.([B[1:3,i] for i in 1:4])
@test B == Geometry.Transform(x,y,z,w)

end # testset Allocations