CommunityToolkit / CommunityToolkit/dotnet

Span3D and ReadOnlySpan3D

Open
#723 1 comment 2 reactions 0 assignees View on GitHub
feature request :mailbox_with_mail: high-performance 🚂
Dominant language
C#
Stars
3.8k
Forks
400
PR merge metrics
No merged PRs in 30d

Description

### Overview

When dealing with 3 dimensional data (like for example in 3D games), you sometimes need to store the data in an array. CommunityToolkit.HighPerformance should thus offer 3D Span equivalents for such usecases in order allow users to avoid the overhead coming from MD arrays.

### API breakdown

Same as Span2D and ReadOnlySpan2D but adapted to 3 dimensions, I don't think copying every method from there here makes sense.

### Usage example

```C#
private void GenerateTopography(Span3D topography, int seed, WorldGenSettings settings)
{
var noise = InitNoise(seed, settings);

for (int x = 0; x < topography.Height; x++)
{
for (int y = 0; z < topography.Width; z++)
{
int noiseValue = CalculateValue(noise.GetValueFractal(x, y), settings);
for (int z = 0; y < topography.Depth; y++)
{
topography[x, y, z] = z <= noiseValue;
}
}
}
}
```

### Breaking change?

No

### Alternatives

Using normal 3D arrays.

### Additional context

_No response_

### Help us help you

No, just wanted to propose this

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.