https://github.com/liulietlee/llvector
Page-aligned array for MetalKit
https://github.com/liulietlee/llvector
ios metal metalkit swift
Last synced: 3 months ago
JSON representation
Page-aligned array for MetalKit
- Host: GitHub
- URL: https://github.com/liulietlee/llvector
- Owner: LiulietLee
- License: mit
- Created: 2019-03-29T10:16:00.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2019-12-18T08:45:27.000Z (over 5 years ago)
- Last Synced: 2025-01-20T08:28:26.886Z (5 months ago)
- Topics: ios, metal, metalkit, swift
- Language: Swift
- Homepage:
- Size: 21.5 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# LLVector
> Page-aligned array for MetalKitIt’s a very inconvenient thing to manipulate pointers directly in Swift, so I wrote this class. You can use it as a normal Swift array and create MTLBuffer by `makeBuffer(bytesNoCopy: _, ...)` with it.
## Installation
Move [src\LLVector.swift](https://github.com/LiulietLee/LLVector/blob/master/src/LLVector.swift) to your project.## Usage
### Initialization
```swift
let v = LLVector >()
// Or
let v = LLVector >(capacity: 2333)
// Or
let v = LLVector(repeaing: SIMD4(repeating: 1.0), count: 100)
```
### Access elements
```swift
let n = v[0]
v[0] = SIMD4(0.5, 0.5, 1.0, 1.0)// If you need to access elements outside the valid range (0..(...))
```
### Appending
```swift
// Add a new element to the end of the vector
v.append(SIMD4(0.0, 0.5, 1.0, 1.0))// Or add the entire array to the end of the vector
v.append(contentsOf: [
SIMD4(0.5, -0.5, 1.0, 1.0),
SIMD4(-0.5, 0.5, 1.0, 1.0)
])// Or add anthor vector to the end of the vector
v.append(contentsOf: another_vector)
```
### Inserting
```swift
// Insert methods are similar to append methods
v.insert(SIMD4(0.7, 0.3, 1.0, 1.0), at: 1)
v.insert(
contentsOf: [
SIMD4(0.2, 0.7, 1.0, 1.0),
SIMD4(0.1, 0.6, 1.0, 1.0)
],
at: 2
)
v.insert(contentsOf: another_vector, at: 3)
```
### Removing
```swift
// Use remove methods to delete elements in the vector
v.remove(at: 2)
v.removeSubrange(1..<3)
if let last = v.removeLast() { ... }
```
### Traversing
```swift
for coor in v {
print("(\(coor.x), \(coor.y))")
}for i in 0..