Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[3.0] Generic Maths Implementation.#2459

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
Tweety-Lab wants to merge58 commits intodotnet:develop/3.0
base:develop/3.0
Choose a base branch
Loading
fromTweety-Lab:feature/math-3.0
Draft
Changes from1 commit
Commits
Show all changes
58 commits
Select commitHold shift + click to select a range
3c95d6d
start of 3.0 Silk.Net.Maths rewrite
Tweety-LabMay 28, 2025
04846e7
Start work on Vector2I.
Tweety-LabMay 28, 2025
7afd57f
Finish implementing Vector2I Interfaces.
Tweety-LabMay 28, 2025
249be1f
Add Vector2I Unit properties.
Tweety-LabMay 28, 2025
709c142
Add Vector3I Maths methods.
Tweety-LabMay 28, 2025
94a912d
Add more missing Vector2I requirements.
Tweety-LabMay 28, 2025
051785d
Add `Vector3I`.
Tweety-LabMay 28, 2025
88b8405
Change VectorI XML comments.
Tweety-LabMay 28, 2025
d1eade9
Add `Vector4I`.
Tweety-LabMay 28, 2025
9b68e35
Improve VectorI equality checks.
Tweety-LabMay 28, 2025
6a3cf88
Start work on new `Quaternion`.
Tweety-LabMay 28, 2025
cc7ebb6
Clarify current state of new Math type's indexers.
Tweety-LabMay 28, 2025
6af8612
Add lower-dimensional VectorI constructors.
Tweety-LabMay 30, 2025
737b5a8
Add `Vector2F`.
Tweety-LabMay 30, 2025
191de4e
Include generated code.
otac0nMay 30, 2025
1cecebe
Merge pull request #1 from otac0n/feature/math-3.0
Tweety-LabMay 30, 2025
291ec1e
Generated constructors, operators, and indexers.
otac0nMay 30, 2025
cfee012
Whitespace and comments.
otac0nMay 31, 2025
91c7982
Added transpose, negate, and identity.
otac0nMay 31, 2025
650f30b
Added some necessary vector bits for testing.
otac0nMay 31, 2025
8ebcfb9
Merge pull request #2 from otac0n/feature/math-3.0
Tweety-LabMay 31, 2025
9bd27fe
Add Lerp and a couple of bugfixes.
otac0nMay 31, 2025
a617eb8
Remove `IBinaryFloatingPointIeee754` reference.
Tweety-LabMay 31, 2025
d57f94d
Make `VectorNI` Vectors use a `ref` indexer.
Tweety-LabMay 31, 2025
d5a8b54
Use partial implementations from code gen.
otac0nMay 31, 2025
3c538bd
Make `Vector2F` Vector use a `ref` indexer.
Tweety-LabMay 31, 2025
4f74ab3
Fix vector `ref` indexer exception messages.
Tweety-LabMay 31, 2025
c9e57f2
Merge branch 'feature/math-3.0' of https://github.com/Tweety-Lab/Silk…
otac0nMay 31, 2025
a4b8a6c
Move constructors & existing interfaces.
otac0nMay 31, 2025
5a82141
IReadOnlyList<T> code gen.
otac0nMay 31, 2025
16e68e2
Fix errors with Quaternion accessibility.
otac0nMay 31, 2025
7efc1eb
Merge pull request #3 from otac0n/feature/math-3.0
Tweety-LabMay 31, 2025
0cb1569
Move common operators and interfaces into templates.
otac0nMay 31, 2025
c9ce628
Use Legacy namespace qualifications for lecacy Quaternion.
otac0nMay 31, 2025
aac298a
Generate constructors to extend smaller vectors.
otac0nMay 31, 2025
25f6994
Removed AllBitsSet from Vector2F.
otac0nMay 31, 2025
41aa58d
Generate vector specific methods in templates.
otac0nMay 31, 2025
0f2d43c
Merge pull request #4 from otac0n/feature/math-3.0
Tweety-LabJun 1, 2025
09e674c
Snapshot.
otac0nJun 30, 2025
070c6f5
Replace generated I/F types with D types.
otac0nJun 30, 2025
aefd7ea
Merge matrix types.
otac0nJul 1, 2025
acaf6b4
Update existing types to use INumberBase.
otac0nJul 1, 2025
ffb7f58
Fix errors.
otac0nJul 1, 2025
d07c355
Code-gen more matrix implememtations.
otac0nJul 2, 2025
80fbbfc
Types that need Min/Max (e.g. Box) use INumber instead of INumberBase…
otac0nJul 2, 2025
2a79fd8
Added explicit casts for vectors.
otac0nJul 2, 2025
5e0e7d9
Use extension properties for LengthSquared and Length. Use these for…
otac0nJul 2, 2025
5973151
Generate more vector functions and reorganize.
otac0nJul 2, 2025
69be9de
Fix type constraints.
otac0nJul 2, 2025
75b1c5d
Overloads for casts, As, CreateChecked, CreateSaturating, and CreateT…
otac0nJul 2, 2025
ac8e94e
Handle IsIdentity and GetDeterminant errors.
otac0nJul 2, 2025
f71206c
Use T.Zero instead of default to avoid NRE.
otac0nJul 2, 2025
0345ba5
Code-gen multiply operators.
otac0nJul 3, 2025
9497be8
Recovered Old Quaternion implementation.
otac0nJul 3, 2025
9aa76de
Fix Obsolete warnings.
otac0nJul 3, 2025
2d6c95b
XML Doc Comments.
otac0nJul 3, 2025
1c2b6f8
Reset APIs.
otac0nJul 3, 2025
bfe143c
Merge pull request #5 from otac0n/feature/math-3.0
Tweety-LabJul 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
Add Vector3I Maths methods.
  • Loading branch information
@Tweety-Lab
Tweety-Lab committedMay 28, 2025
commit709c14295d051c3131074189a1f395310c0bb2c4
99 changes: 96 additions & 3 deletionssources/Maths/Maths/Vector2I.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,7 @@
using System.Collections;
using System.Diagnostics.CodeAnalysis;
using System.Numerics;
using System.Runtime.InteropServices;
using System.Text;

namespace Silk.NET.Maths
Expand DownExpand Up@@ -55,16 +56,19 @@ public Vector2I(ReadOnlySpan<T> values)
/// <summary>Returns a vector whose 2 elements are equal to zero.</summary>
public static Vector2I<T> Zero => default;

/// <summary>Gets the squared length of the vector (dot product with itself).</summary>
public T LengthSquared => (X * X) + (Y * Y);

/// <summary>The number of elements in the vector.</summary>
public int Count => 2;

///<summary>Gets the component at the specified index: 0 = X, 1 = Y. </summary>
public T this[int index] => index switch {
0 => X,
1 => Y,
_ => throw new ArgumentOutOfRangeException(nameof(index), "Index must be 0 or 1.")
};

/// <summary>The number of elements in the vector.</summary>
public int Count => 2;

/// <summary>Returns a boolean indicating whether the given Object is equal to this <see cref="Vector2I{T}"/> instance.</summary>
public bool Equals(Vector2I<T> other) => X.Equals(other.X) && Y.Equals(other.Y);

Expand All@@ -75,9 +79,59 @@ public IEnumerator<T> GetEnumerator()
yield return Y;
}

/// <summary> Computes the dot product of this vector with another vector. </summary>
public T Dot(Vector2I<T> other) => (X * other.X) + (Y * other.Y);

/// <summary> Computes the dot product of two vectors. </summary>
public static T Dot(Vector2I<T> left, Vector2I<T> right) => (left.X * right.X) + (left.Y * right.Y);

/// <summary> Computes the cross product of this vector with another vector. </summary>
public T Cross(Vector2I<T> other) => (X * other.Y) - (Y * other.X);

/// <summary> Computes the cross product of two vectors. </summary>
public static T Cross(Vector2I<T> left, Vector2I<T> right) => (left.X * right.Y) - (left.Y * right.X);

/// <summary>Returns a span over the vector components.</summary>
public Span<T> AsSpan() => MemoryMarshal.CreateSpan(ref X, 2);

/// <summary>Returns a vector with the component-wise maximum of this and another vector.</summary>
public Vector2I<T> Max(Vector2I<T> other) =>
new Vector2I<T>(T.Max(X, other.X), T.Max(Y, other.Y));

/// <summary>Returns a vector with the component-wise maximum of two vectors.</summary>
public static Vector2I<T> Max(Vector2I<T> left, Vector2I<T> right) =>
new Vector2I<T>(T.Max(left.X, right.X), T.Max(left.Y, right.Y));

/// <summary>Returns a vector with the component-wise maximum of this vector and a scalar.</summary>
public Vector2I<T> Max(T scalar) =>
new Vector2I<T>(T.Max(X, scalar), T.Max(Y, scalar));

/// <summary>Returns a vector with the component-wise maximum of a vector and a scalar.</summary>
public static Vector2I<T> Max(Vector2I<T> vector, T scalar) =>
new Vector2I<T>(T.Max(vector.X, scalar), T.Max(vector.Y, scalar));

/// <summary>Returns a vector with the component-wise minimum of this and another vector.</summary>
public Vector2I<T> Min(Vector2I<T> other) =>
new Vector2I<T>(T.Min(X, other.X), T.Min(Y, other.Y));

/// <summary>Returns a vector with the component-wise minimum of two vectors.</summary>
public static Vector2I<T> Min(Vector2I<T> left, Vector2I<T> right) =>
new Vector2I<T>(T.Min(left.X, right.X), T.Min(left.Y, right.Y));

/// <summary>Returns a vector with the component-wise minimum of this vector and a scalar.</summary>
public Vector2I<T> Min(T scalar) =>
new Vector2I<T>(T.Min(X, scalar), T.Min(Y, scalar));

/// <summary>Returns a vector with the component-wise minimum of a vector and a scalar.</summary>
public static Vector2I<T> Min(Vector2I<T> vector, T scalar) =>
new Vector2I<T>(T.Min(vector.X, scalar), T.Min(vector.Y, scalar));

/// <summary>Formats the vector as a string using the specified format and format provider.</summary>
public string ToString(string? format, IFormatProvider? formatProvider) => $"<{X.ToString(format, formatProvider)}, {Y.ToString(format, formatProvider)}>";

/// <summary>Formats the vector as a string.</summary>
public override string ToString() => $"<{X}, {Y}>";

/// <summary>Formats the vector as a string using the specified format and format provider.</summary>
public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format, IFormatProvider? provider)
{
Expand DownExpand Up@@ -239,5 +293,44 @@ public static bool TryParse(ReadOnlySpan<byte> utf8Text, IFormatProvider? provid
Encoding.UTF8.GetChars(utf8Text, charBuffer);
return TryParse(charBuffer, provider, out result);
}

// Component Operators
public static Vector2I<T> operator +(Vector2I<T> left, Vector2I<T> right) =>
new Vector2I<T>(left.X + right.X, left.Y + right.Y);

public static Vector2I<T> operator -(Vector2I<T> left, Vector2I<T> right) =>
new Vector2I<T>(left.X - right.X, left.Y - right.Y);

public static Vector2I<T> operator *(Vector2I<T> left, Vector2I<T> right) =>
new Vector2I<T>(left.X * right.X, left.Y * right.Y);

public static Vector2I<T> operator /(Vector2I<T> left, Vector2I<T> right) =>
new Vector2I<T>(left.X / right.X, left.Y / right.Y);

public static Vector2I<T> operator %(Vector2I<T> left, Vector2I<T> right) =>
new Vector2I<T>(left.X % right.X, left.Y % right.Y);

// Scalar Operators
public static Vector2I<T> operator +(Vector2I<T> vector, T scalar) =>
new Vector2I<T>(vector.X + scalar, vector.Y + scalar);

public static Vector2I<T> operator -(Vector2I<T> vector, T scalar) =>
new Vector2I<T>(vector.X - scalar, vector.Y - scalar);

public static Vector2I<T> operator *(Vector2I<T> vector, T scalar) =>
new Vector2I<T>(vector.X * scalar, vector.Y * scalar);

public static Vector2I<T> operator /(Vector2I<T> vector, T scalar) =>
new Vector2I<T>(vector.X / scalar, vector.Y / scalar);

public static Vector2I<T> operator %(Vector2I<T> vector, T scalar) =>
new Vector2I<T>(vector.X % scalar, vector.Y % scalar);

// + operator: returns the vector (?)
public static Vector2I<T> operator +(Vector2I<T> vector) => vector;

// - operator: returns the negated vector
public static Vector2I<T> operator -(Vector2I<T> vector) =>
new Vector2I<T>(-vector.X, -vector.Y);
}
}
Loading

[8]ページ先頭

©2009-2025 Movatter.jp