Skip to content

Span3D and ReadOnlySpan3D #723

@MichalPetryka

Description

@MichalPetryka

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

private void GenerateTopography(Span3D<bool> 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature request 📬A request for new changes to improve functionalityhigh-performance 🚂Issues/PRs for the HighPerformance package

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions