Skip to content

Commit

Permalink
Make new Rotation constructor and redefine anim_rotate[_around] (#454)
Browse files Browse the repository at this point in the history
* Make new Rotation constructor and redefine anim_rotate[_around] to handle Integer and Irrational rotation angles.

Co-authored-by: Ole Kröger <[email protected]>
  • Loading branch information
leephillips and Wikunia authored Dec 31, 2021
1 parent 5731259 commit 0ec51d5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased
- Fix bug that would make frames <= 0 throw error
- Allow integer and irrational angles in rotation

## v0.7.1 (28th of September 2021)
- added `scale_linear` function to easily scale values or points
Expand Down
9 changes: 5 additions & 4 deletions src/structs/Transitions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ struct Rotation{T<:Real} <: AbstractTransition
center::Union{Nothing,Point,AbstractObject}
end

Rotation(from::Real, to::Real, center) = Rotation(promote(from, to)..., center)
"""
anim_rotate
Expand All @@ -52,11 +53,11 @@ act!(obj, Action(1:50, anim_rotate(2π)))
# Options
- `anim_rotate(ta::Real)` define the end angle of the rotation
- `anim_rotate(fa::T, ta::T)` define the from and end angle
- `anim_rotate(fa::Real, ta::Real)` define the from and end angle
"""
anim_rotate(ta::Real) = Rotation(0.0, ta, nothing)
anim_rotate(fa::T, ta::T) where {T<:Real} = Rotation(fa, ta, nothing)
anim_rotate(fa::Real, ta::Real) = Rotation(fa, ta, nothing)

"""
anim_rotate_around
Expand All @@ -73,11 +74,11 @@ act!(obj, Action(1:50, anim_rotate_around(2π, O)))
# Options
- `anim_rotate_around(ta::Real, p)` define the end angle of the rotation + the rotation center.
- `anim_rotate_around(fa::T, ta::T, p)` define the from and end angle + the rotation center.
- `anim_rotate_around(fa::Real, ta::Real, p)` define the from and end angle + the rotation center.
"""
anim_rotate_around(ta::Real, p) = Rotation(0.0, ta, p)
anim_rotate_around(fa::T, ta::T, p) where {T<:Real} = Rotation(fa, ta, p)
anim_rotate_around(fa::Real, ta::Real, p) = Rotation(fa, ta, p)

struct Scaling <: AbstractTransition
from::Union{Object,Scale,Symbol}
Expand Down
17 changes: 17 additions & 0 deletions test/animations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,23 @@ end
rm(pathname)
end

@testset "test angle numerical types" begin
video = Video(100, 100)
Background(1:10, ground)
p = Object(1:10, (args...) -> circle(O, 50, :fill))
p2 = Object(1:10, (args...) -> circle(O, 50, :fill))
aa = (0.0, 0, π, 0.0f0)
for fa in aa, ta in aa
rot = anim_rotate(fa, ta)
@test typeof(rot.from) == typeof(rot.to)
@test rot.center === nothing

rot = anim_rotate_around(fa, ta, p)
@test typeof(rot.from) == typeof(rot.to)
@test rot.center == p
end
end

@testset "test @error .mp3" begin
video = Video(500, 500)
Background(1:10, ground)
Expand Down

0 comments on commit 0ec51d5

Please sign in to comment.