An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

        

# LLVector
> Page-aligned array for MetalKit

It’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..