Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Conversation

@thomas-daniels
Copy link
Contributor

This commit adds Vector2.ToArray(), Vector2.FromArray(float[]),
Vector3.ToArray(), Vector3.FromArray(float[]), Vector4.ToArray() and
Vector4.FromArray(float[]). The FromArray method copies the array elements
to a vector: the element at index 0 becomes X, the element at index 1
becomes Y and so on. The ToArray() method converts the vector to an array:
it puts X at index 0, Y at index 1 and so on.

These methods looked useful to me if you have an array but want to do
vector operations.

This commit adds Vector2.ToArray(), Vector2.FromArray(float[]),
Vector3.ToArray(), Vector3.FromArray(float[]), Vector4.ToArray() and
Vector4.FromArray(float[]). The FromArray method copies the array elements
to a vector: the element at index 0 becomes X, the element at index 1
becomes Y and so on. The ToArray() method converts the vector to an array:
it puts X at index 0, Y at index 1 and so on.

These methods looked useful to me if you have an array but want to do
vector operations.
@terrajobst
Copy link

Thanks for opening this PR.

Can you explain the scenario in which you'd use those APIs? In general, I'd say the APIs would be far more useful if they'd allow store and retrieve vectors from a larger array. This would require passing in an array and an offset. But again, I'm not sure whether that's a super useful scenario...

@thomas-daniels
Copy link
Contributor Author

A simple example where it is useful: you load 4 integers (comma-separated) from user input which you split into an array of integers, and you want to perform vector operations on them. In that case I would use the FromArray method. And the ToArray method would be useful if you have a vector that you want to pass to a method that only accepts an array.

@thomas-daniels
Copy link
Contributor Author

I understand your comment about the offset, so I added a new commit that adds a .FromArray(float[] values, int offset).

@mellinoe
Copy link
Contributor

Hey @ProgramFOX, thanks for the feature submission.Right now, we already provide a CopyTo(float[], int) method (on these types, at least) which more or less covers one of the use cases (dumping values into an array). Check out the Vector2/3/4_Intrinsics file for those definitions. However, producing values from an array is a scenario we don't have a good story for right now. One of the most frequently requested operations is creating an array from a pointer location, so I can see adding some factory methods for that, as well as exposing some helpers for creating from arrays.

@thomas-daniels
Copy link
Contributor Author

I see. Then I'll close this pull request.

@karelz karelz modified the milestone: 1.0.0-rtm Dec 3, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants