Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

recenter: accept origin::Tuple #74

Merged
merged 1 commit into from
Aug 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion src/affine.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Base.show(io::IO, trans::LinearMap) = print(io, "LinearMap($(trans.linear))") #
function (trans::LinearMap{M})(x) where {M}
trans.linear * x
end
(trans::LinearMap{M})(x::Tuple) where {M} = trans(SVector(x))

Base.inv(trans::LinearMap) = LinearMap(inv(trans.linear))

Expand Down Expand Up @@ -204,7 +205,7 @@ function Base.:(==)(t1::LinearMap, t2::AffineMap)
0 == vecnorm(t2.translation)
end

recenter(trans::AbstractMatrix, origin::AbstractVector) = recenter(LinearMap(trans), origin)
recenter(trans::AbstractMatrix, origin::Union{AbstractVector, Tuple}) = recenter(LinearMap(trans), origin)

transform_deriv(trans::AffineMap, x) = trans.linear
# TODO transform_deriv_params
3 changes: 2 additions & 1 deletion src/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Base.inv(trans::ComposedTransformation) = inv(trans.t2) ∘ inv(trans.t1)
Base.inv(trans::IdentityTransformation) = trans

"""
recenter(trans::Union{AbstractMatrix,Transformation}, origin::AbstractVector) -> ctrans
recenter(trans::Union{AbstractMatrix,Transformation}, origin::Union{AbstractVector, Tuple}) -> ctrans

Return a new transformation `ctrans` such that point `origin` serves
as the origin-of-coordinates for `trans`. Translation by `±origin`
Expand All @@ -97,6 +97,7 @@ space around `origin`.
function recenter(trans::Transformation, origin::AbstractVector)
Translation(origin) ∘ trans ∘ Translation(-origin)
end
recenter(trans::Transformation, origin::Tuple) = recenter(trans, SVector(origin))


"""
Expand Down
7 changes: 7 additions & 0 deletions test/affine.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ end
@test c(origin) == origin
@test c(zero(origin)) == [6,-6]
end

# Tuple is converted to SVector first
origin = (5, -3)
new_origin = SVector(origin)
c = recenter(M, origin)
@test c(origin) == new_origin
@test c(zero(new_origin)) == [6, -6]
end

@testset "application of AffineMap in terms of LinearMap and Translation" begin
Expand Down