-
Notifications
You must be signed in to change notification settings - Fork 43
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
Add merge! for animation types, insert! for AnimationTrack. #115
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
21b243d
merge! for animation types, insert! for AnimationTrack.
tkoolen 5c82f53
Add Base.merge overload as well.
tkoolen 63474cc
Re-add assertion error on default_framerate.
tkoolen 888c2bc
Add mergesorted!.
tkoolen 64cd221
(frames, values) -> events.
tkoolen 2d63b91
Add kwarg to mergesorted!
tkoolen 921b889
Move mergesorted! to util.jl
tkoolen 97ddb02
Add test for and fix mergesorted!.
tkoolen 064c0b4
Use mergesorted! in merge! for AnimationTrack.
tkoolen 3c2f839
insert! for AnimationTrack: overwrite if at the same frame.
tkoolen ca6e588
Add basic Animation merge test.
tkoolen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Port of possible implementation of std::merge (second version), | ||
# https://en.cppreference.com/w/cpp/algorithm/merge | ||
# TODO: contribute to base. | ||
@inline function mergesorted!(dest::AbstractVector, a, b; by=identity, lt=isless) | ||
i = 1 | ||
it_a = iterate(a) | ||
it_b = iterate(b) | ||
while it_a !== nothing | ||
val_a, state_a = it_a | ||
if it_b === nothing | ||
dest[i] = val_a | ||
i += 1 | ||
copyto!(dest, i, Iterators.rest(a, state_a)) | ||
return dest | ||
end | ||
val_b, state_b = it_b | ||
if lt(by(val_b), by(val_a)) | ||
dest[i] = val_b | ||
it_b = iterate(b, state_b) | ||
else | ||
dest[i] = val_a | ||
it_a = iterate(a, state_a) | ||
end | ||
i += 1 | ||
end | ||
if it_b !== nothing | ||
val_b, state_b = it_b | ||
dest[i] = val_b | ||
i += 1 | ||
copyto!(dest, i, Iterators.rest(b, state_b)) | ||
end | ||
return dest | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
module UtilTest | ||
|
||
using Test | ||
using Random | ||
using MeshCat: mergesorted! | ||
|
||
@testset "mergesorted!" begin | ||
@testset "basic" begin | ||
rng = MersenneTwister(1) | ||
for i = 1 : 1000 | ||
a = sort(rand(1 : 100, rand(0 : 20))) | ||
b = sort(rand(1 : 100, rand(0 : 20))) | ||
result = similar(a, length(a) + length(b)) | ||
mergesorted!(result, a, b) | ||
@test issorted(result) | ||
@test a ⊆ result | ||
@test b ⊆ result | ||
end | ||
end | ||
|
||
@testset "by" begin | ||
rng = MersenneTwister(1) | ||
for i = 1 : 1000 | ||
a = sort([rand(1 : 100) => rand(1 : 100) for _ in rand(0 : 20)]; dims=1, by=first) | ||
b = sort([rand(1 : 100) => rand(1 : 100) for _ in rand(0 : 20)]; dims=1, by=first) | ||
result = similar(a, length(a) + length(b)) | ||
mergesorted!(result, a, b; by=first) | ||
@test issorted(result; by=first) | ||
@test a ⊆ result | ||
@test b ⊆ result | ||
end | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was just thinking: there could potentially be two animation tracks with the same name but different
jstype
s. That would currently error here. Again, not with the currentatframe
implementation,MeshCat.jl/src/atframe.jl
Lines 12 to 14 in 160933c
but still.