Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/serenity4/swizzles.jl
Adding swizzles to your vectors
https://github.com/serenity4/swizzles.jl
Last synced: 8 days ago
JSON representation
Adding swizzles to your vectors
- Host: GitHub
- URL: https://github.com/serenity4/swizzles.jl
- Owner: serenity4
- License: mit
- Created: 2023-11-25T11:35:07.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-08-19T13:36:16.000Z (6 months ago)
- Last Synced: 2025-01-20T22:40:31.472Z (about 1 month ago)
- Language: Julia
- Homepage:
- Size: 344 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Swizzles
[](https://serenity4.github.io/Swizzles.jl/stable/)
[](https://serenity4.github.io/Swizzles.jl/dev/)
[](https://github.com/serenity4/Swizzles.jl/actions/workflows/CI.yml?query=branch%3Amain)
[](https://codecov.io/gh/serenity4/Swizzles.jl)Lightweight package meant to provide functionality and syntax for [swizzling](https://en.wikipedia.org/wiki/Swizzling_(computer_graphics)) operations.
Swizzling is defined for any linearly indexable object, the main example of which are `AbstractVector`.
```julia
julia> using Swizzlesjulia> v = [10, 20, 30, 40];
julia> swizzle(v, 3, 1)
2-element Vector{Int64}:
30
10
```Besides extracting vector components, swizzling may be used for mutation, with `swizzle!`:
```julia
julia> v = [10, 20, 30, 40];julia> swizzle!(v, [1, 2], 4, 2)
2-element Vector{Int64}:
1
2julia> v
4-element Vector{Int64}:
10
2
30
1
```Additionally, a `@swizzle` macro is defined which provides nice syntax for it:
```julia
julia> v = [10, 20, 30, 40];julia> @swizzle v.xy
2-element Vector{Int64}:
10
20julia> @swizzle v.rgb
3-element Vector{Int64}:
10
20
30julia> @swizzle v.xyx
3-element Vector{Int64}:
10
20
10julia> @swizzle v.wx = [1, 2]
2-element Vector{Int64}:
1
2julia> v
4-element Vector{Int64}:
2
20
30
1
```See the [documentation](https://serenity4.github.io/Swizzles.jl/dev/) to know more about the motivation for this functionality and a complete reference beyond what was shown here.