< Summary

Line coverage
32%
Covered lines: 68
Uncovered lines: 140
Coverable lines: 208
Total lines: 773
Line coverage: 32.6%
Branch coverage
25%
Covered branches: 5
Total branches: 20
Branch coverage: 25%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
File 1: .ctor(...)100%11100%
File 1: .ctor(...)100%11100%
File 1: .ctor(...)100%210%
File 1: .ctor(...)100%210%
File 1: get_Zero()100%11100%
File 1: get_One()100%11100%
File 1: get_Right()100%11100%
File 1: get_Left()100%210%
File 1: get_Up()100%11100%
File 1: get_Down()100%210%
File 1: get_Forward()100%11100%
File 1: get_Back()100%210%
File 1: get_MaxValue()100%210%
File 1: get_MinValue()100%210%
File 1: get_SqrMagnitude()100%11100%
File 1: get_SqrMagnitudeFast()100%210%
File 1: get_Magnitude()100%11100%
File 1: get_Normalized()100%11100%
File 1: NormalizedWithMagnitude(...)100%210%
File 1: Normalize(...)100%22100%
File 1: Normalize(...)0%620%
File 1: op_Addition(...)100%11100%
File 1: op_Subtraction(...)100%11100%
File 1: op_UnaryNegation(...)100%11100%
File 1: op_Multiply(...)100%11100%
File 1: op_Multiply(...)100%210%
File 1: op_Division(...)100%210%
File 1: op_Equality(...)0%2040%
File 1: op_Inequality(...)100%210%
File 1: op_Implicit(...)100%210%
File 1: op_Explicit(...)100%11100%
File 1: Dot(...)100%11100%
File 1: Cross(...)100%11100%
File 1: Distance(...)100%11100%
File 1: DistanceSquared(...)100%11100%
File 1: Lerp(...)100%11100%
File 1: LerpUnclamped(...)100%11100%
File 1: Slerp(...)100%11100%
File 1: SlerpUnclamped(...)50%7441.66%
File 1: ClampMagnitude(...)0%620%
File 1: Reflect(...)100%11100%
File 1: Project(...)50%22100%
File 1: ProjectOnPlane(...)0%620%
File 1: Scale(...)100%210%
File 1: Min(...)100%210%
File 1: Max(...)100%210%
File 1: Equals(...)100%210%
File 1: Equals(...)0%620%
File 1: GetHashCode()100%210%
File 1: ToString()100%210%
File 2: get_XX()100%210%
File 2: get_XY()100%210%
File 2: get_XZ()100%210%
File 2: get_XO()100%210%
File 2: get_YX()100%210%
File 2: get_YY()100%210%
File 2: get_YZ()100%210%
File 2: get_YO()100%210%
File 2: get_ZX()100%210%
File 2: get_ZY()100%210%
File 2: get_ZZ()100%210%
File 2: get_ZO()100%210%
File 2: get_OX()100%210%
File 2: get_OY()100%210%
File 2: get_OZ()100%210%
File 2: get_OO()100%210%
File 2: get_XXX()100%210%
File 2: get_XXY()100%210%
File 2: get_XXZ()100%210%
File 2: get_XXO()100%210%
File 2: get_XYX()100%210%
File 2: get_XYY()100%210%
File 2: get_XYZ()100%11100%
File 2: get_XYO()100%210%
File 2: get_XZX()100%210%
File 2: get_XZY()100%210%
File 2: get_XZZ()100%210%
File 2: get_XZO()100%210%
File 2: get_XOX()100%210%
File 2: get_XOY()100%210%
File 2: get_XOZ()100%210%
File 2: get_XOO()100%210%
File 2: get_YXX()100%210%
File 2: get_YXY()100%210%
File 2: get_YXZ()100%210%
File 2: get_YXO()100%210%
File 2: get_YYX()100%210%
File 2: get_YYY()100%210%
File 2: get_YYZ()100%210%
File 2: get_YYO()100%210%
File 2: get_YZX()100%210%
File 2: get_YZY()100%210%
File 2: get_YZZ()100%210%
File 2: get_YZO()100%210%
File 2: get_YOX()100%210%
File 2: get_YOY()100%210%
File 2: get_YOZ()100%210%
File 2: get_YOO()100%210%
File 2: get_ZXX()100%210%
File 2: get_ZXY()100%210%
File 2: get_ZXZ()100%210%
File 2: get_ZXO()100%210%
File 2: get_ZYX()100%11100%
File 2: get_ZYY()100%210%
File 2: get_ZYZ()100%210%
File 2: get_ZYO()100%210%
File 2: get_ZZX()100%210%
File 2: get_ZZY()100%210%
File 2: get_ZZZ()100%210%
File 2: get_ZZO()100%210%
File 2: get_ZOX()100%210%
File 2: get_ZOY()100%210%
File 2: get_ZOZ()100%210%
File 2: get_ZOO()100%210%
File 2: get_OXX()100%210%
File 2: get_OXY()100%210%
File 2: get_OXZ()100%210%
File 2: get_OXO()100%210%
File 2: get_OYX()100%210%
File 2: get_OYY()100%210%
File 2: get_OYZ()100%210%
File 2: get_OYO()100%210%
File 2: get_OZX()100%210%
File 2: get_OZY()100%210%
File 2: get_OZZ()100%210%
File 2: get_OZO()100%210%
File 2: get_OOX()100%210%
File 2: get_OOY()100%210%
File 2: get_OOZ()100%210%
File 2: get_OOO()100%210%

File(s)

/home/runner/work/Sideline/Sideline/godot/scripts/lattice/Math/FPVector3.cs

#LineLine coverage
 1// Copyright (c) 2026 Sideline Authors. All rights reserved.
 2// Licensed under GPL-3.0.
 3
 4#nullable enable
 5
 6using System;
 7using System.Runtime.CompilerServices;
 8using System.Runtime.InteropServices;
 9using Lattice.Generators;
 10
 11namespace Lattice.Math
 12{
 13    /// <summary>
 14    /// 3D 定点数向量
 15    /// <para>参考 FrameSyncEngine 设计,高性能实现</para>
 16    /// <para>内存布局:连续 24 字节(3 * 8 bytes)</para>
 17    /// </summary>
 18    /// <remarks>
 19    /// <para><b>Swizzle 属性:</b></para>
 20    /// 本结构使用 <see cref="GenerateSwizzleAttribute"/> Source Generator 自动生成 Swizzle 属性。
 21    /// 可用属性包括:XX, XY, XZ, YX, YY, YZ, ZX, ZY, ZZ, XXX, XXY, XYZ, XZX, XZY, XZZ 等。
 22    ///
 23    /// <para><b>内存布局:</b></para>
 24    /// 使用 <see cref="StructLayoutAttribute"/> 显式控制内存布局,确保跨平台一致性。
 25    /// X 分量在偏移 0,Y 分量在偏移 8,Z 分量在偏移 16。
 26    /// </remarks>
 27    [StructLayout(LayoutKind.Explicit, Size = 24)]  // 3 * 8 bytes, Explicit for cross-platform consistency
 28    [GenerateSwizzle(MaxDimension = 4, IncludeZero = true)]
 29    public readonly partial struct FPVector3 : IEquatable<FPVector3>
 30    {
 31        #region 字段
 32
 33        /// <summary>X 分量</summary>
 34        [FieldOffset(0)]
 35        public readonly FP X;
 36
 37        /// <summary>Y 分量</summary>
 38        [FieldOffset(8)]
 39        public readonly FP Y;
 40
 41        /// <summary>Z 分量</summary>
 42        [FieldOffset(16)]
 43        public readonly FP Z;
 44
 45        #endregion
 46
 47        #region 构造函数
 48
 49        /// <summary>
 50        /// 从三个 FP 构造
 51        /// </summary>
 52        /// <param name="x">X 分量</param>
 53        /// <param name="y">Y 分量</param>
 54        /// <param name="z">Z 分量</param>
 55        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 56        public FPVector3(FP x, FP y, FP z)
 57        {
 17158            X = x;
 17159            Y = y;
 17160            Z = z;
 17161        }
 62
 63        /// <summary>
 64        /// 从三个 int 构造
 65        /// </summary>
 66        /// <param name="x">X 分量</param>
 67        /// <param name="y">Y 分量</param>
 68        /// <param name="z">Z 分量</param>
 69        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 70        public FPVector3(int x, int y, int z)
 71        {
 2972            X = (FP)x;
 2973            Y = (FP)y;
 2974            Z = (FP)z;
 2975        }
 76
 77        /// <summary>
 78        /// 从两个 FP 构造(Z=0)
 79        /// </summary>
 80        /// <param name="x">X 分量</param>
 81        /// <param name="y">Y 分量</param>
 82        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 83        public FPVector3(FP x, FP y)
 84        {
 085            X = x;
 086            Y = y;
 087            Z = FP._0;
 088        }
 89
 90        /// <summary>
 91        /// 从单个 FP 构造(三个分量相同)
 92        /// </summary>
 93        /// <param name="value">X、Y、Z 分量的值</param>
 94        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 95        public FPVector3(FP value)
 96        {
 097            X = value;
 098            Y = value;
 099            Z = value;
 0100        }
 101
 102        #endregion
 103
 104        #region 常量
 105
 106        /// <summary>零向量 (0, 0, 0)</summary>
 10107        public static FPVector3 Zero => default;
 108
 109        /// <summary>单位向量 (1, 1, 1)</summary>
 3110        public static FPVector3 One => new(FP._1, FP._1, FP._1);
 111
 112        /// <summary>右向量 (1, 0, 0)</summary>
 9113        public static FPVector3 Right => new(FP._1, FP._0, FP._0);
 114
 115        /// <summary>左向量 (-1, 0, 0)</summary>
 0116        public static FPVector3 Left => new(-FP._1, FP._0, FP._0);
 117
 118        /// <summary>上向量 (0, 1, 0)</summary>
 7119        public static FPVector3 Up => new(FP._0, FP._1, FP._0);
 120
 121        /// <summary>下向量 (0, -1, 0)</summary>
 0122        public static FPVector3 Down => new(FP._0, -FP._1, FP._0);
 123
 124        /// <summary>前向量 (0, 0, 1)</summary>
 4125        public static FPVector3 Forward => new(FP._0, FP._0, FP._1);
 126
 127        /// <summary>后向量 (0, 0, -1)</summary>
 0128        public static FPVector3 Back => new(FP._0, FP._0, -FP._1);
 129
 130        /// <summary>最大值向量</summary>
 0131        public static FPVector3 MaxValue => new(new FP(long.MaxValue), new FP(long.MaxValue), new FP(long.MaxValue));
 132
 133        /// <summary>最小值向量</summary>
 0134        public static FPVector3 MinValue => new(new FP(long.MinValue), new FP(long.MinValue), new FP(long.MinValue));
 135
 136        #endregion
 137
 138        // Swizzle 属性由 Source Generator 自动生成
 139        // 参见 Tools/SwizzleGenerator
 140
 141        #region 属性
 142
 143        /// <summary>
 144        /// 向量长度的平方 - 精确版(四舍五入)
 145        /// </summary>
 146        /// <remarks>
 147        /// 计算公式:(X*X + Y*Y + Z*Z) / ONE,+32768 实现四舍五入
 148        /// </remarks>
 149        public readonly FP SqrMagnitude
 150        {
 151            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 152            get
 153            {
 9154                long x2 = (X.RawValue * X.RawValue + 32768) >> 16;
 9155                long y2 = (Y.RawValue * Y.RawValue + 32768) >> 16;
 9156                long z2 = (Z.RawValue * Z.RawValue + 32768) >> 16;
 9157                return new FP(x2 + y2 + z2);
 158            }
 159        }
 160
 161        /// <summary>
 162        /// 向量长度的平方 - 快速版(截断)
 163        /// <para>无四舍五入开销,适合性能敏感场景</para>
 164        /// </summary>
 165        /// <remarks>
 166        /// 误差:最大 1 LSB(约 0.000015)
 167        /// </remarks>
 168        public readonly FP SqrMagnitudeFast
 169        {
 170            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 171            get
 172            {
 0173                long x2 = (X.RawValue * X.RawValue) >> 16;
 0174                long y2 = (Y.RawValue * Y.RawValue) >> 16;
 0175                long z2 = (Z.RawValue * Z.RawValue) >> 16;
 0176                return new FP(x2 + y2 + z2);
 177            }
 178        }
 179
 180        /// <summary>
 181        /// 向量长度
 182        /// </summary>
 183        public readonly FP Magnitude
 184        {
 185            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 6186            get => FPMath.Sqrt(SqrMagnitude);
 187        }
 188
 189        /// <summary>
 190        /// 归一化向量(FrameSync 免除法优化)
 191        /// <para>使用倒数乘法而非除法,速度快约 2-3 倍</para>
 192        /// </summary>
 193        public readonly FPVector3 Normalized
 194        {
 195            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 9196            get => Normalize(this);
 197        }
 198
 199        /// <summary>
 200        /// 归一化向量并返回原始长度
 201        /// <para>FrameSync 风格免除法实现</para>
 202        /// </summary>
 203        /// <param name="magnitude">输出原始长度</param>
 204        /// <returns>归一化后的向量</returns>
 205        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 206        public readonly FPVector3 NormalizedWithMagnitude(out FP magnitude)
 207        {
 0208            return Normalize(this, out magnitude);
 209        }
 210
 211        /// <summary>
 212        /// 归一化向量(静态方法,FrameSync 优化)
 213        /// <para>使用指数-尾数分解 + 倒数乘法,避免除法</para>
 214        /// </summary>
 215        /// <param name="value">要归一化的向量</param>
 216        /// <returns>归一化后的向量</returns>
 217        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 218        public static FPVector3 Normalize(FPVector3 value)
 219        {
 9220            ulong sqrmag = (ulong)(value.X.RawValue * value.X.RawValue + value.Y.RawValue * value.Y.RawValue + value.Z.R
 12221            if (sqrmag == 0) return Zero;
 222
 6223            var (reciprocal, shift) = FPMath.GetReciprocalForNormalize(sqrmag);
 224
 6225            return new FPVector3(
 6226                new FP(value.X.RawValue * reciprocal >> shift),
 6227                new FP(value.Y.RawValue * reciprocal >> shift),
 6228                new FP(value.Z.RawValue * reciprocal >> shift)
 6229            );
 230        }
 231
 232        /// <summary>
 233        /// 归一化向量并返回原始长度(FrameSync 优化)
 234        /// </summary>
 235        /// <param name="value">要归一化的向量</param>
 236        /// <param name="magnitude">输出原始长度</param>
 237        /// <returns>归一化后的向量</returns>
 238        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 239        public static FPVector3 Normalize(FPVector3 value, out FP magnitude)
 240        {
 0241            ulong sqrmag = (ulong)(value.X.RawValue * value.X.RawValue + value.Y.RawValue * value.Y.RawValue + value.Z.R
 0242            if (sqrmag == 0)
 243            {
 0244                magnitude = FP.Zero;
 0245                return Zero;
 246            }
 247
 0248            var sqrt = FPMath.GetSqrtDecomp(sqrmag);
 0249            var (reciprocal, shift) = FPMath.GetReciprocalForNormalize(sqrmag);
 250
 0251            magnitude = FP.FromRaw((long)sqrt.Mantissa << sqrt.Exponent >> 14);
 252
 0253            return new FPVector3(
 0254                new FP(value.X.RawValue * reciprocal >> shift),
 0255                new FP(value.Y.RawValue * reciprocal >> shift),
 0256                new FP(value.Z.RawValue * reciprocal >> shift)
 0257            );
 258        }
 259
 260        #endregion
 261
 262        #region 运算符
 263
 264        /// <summary>向量加法</summary>
 265        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 266        public static FPVector3 operator +(FPVector3 a, FPVector3 b)
 1267            => new(a.X + b.X, a.Y + b.Y, a.Z + b.Z);
 268
 269        /// <summary>向量减法</summary>
 270        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 271        public static FPVector3 operator -(FPVector3 a, FPVector3 b)
 4272            => new(a.X - b.X, a.Y - b.Y, a.Z - b.Z);
 273
 274        /// <summary>向量取反</summary>
 275        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 276        public static FPVector3 operator -(FPVector3 v)
 1277            => new(-v.X, -v.Y, -v.Z);
 278
 279        /// <summary>向量 * 标量</summary>
 280        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 281        public static FPVector3 operator *(FPVector3 v, FP s)
 3282            => new(v.X * s, v.Y * s, v.Z * s);
 283
 284        /// <summary>标量 * 向量</summary>
 285        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 286        public static FPVector3 operator *(FP s, FPVector3 v)
 0287            => v * s;
 288
 289        /// <summary>向量 / 标量</summary>
 290        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 291        public static FPVector3 operator /(FPVector3 v, FP s)
 0292            => new(v.X / s, v.Y / s, v.Z / s);
 293
 294        /// <summary>相等比较</summary>
 295        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 296        public static bool operator ==(FPVector3 a, FPVector3 b)
 0297            => a.X.RawValue == b.X.RawValue && a.Y.RawValue == b.Y.RawValue && a.Z.RawValue == b.Z.RawValue;
 298
 299        /// <summary>不等比较</summary>
 300        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 301        public static bool operator !=(FPVector3 a, FPVector3 b)
 0302            => !(a == b);
 303
 304        /// <summary>隐式从 FPVector2 转换(Z=0)</summary>
 305        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 306        public static implicit operator FPVector3(FPVector2 v)
 0307            => new(v.X, v.Y, FP._0);
 308
 309        /// <summary>显式转换为 FPVector2(丢弃 Z)</summary>
 310        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 311        public static explicit operator FPVector2(FPVector3 v)
 1312            => new(v.X, v.Y);
 313
 314        #endregion
 315
 316        #region 静态方法
 317
 318        /// <summary>
 319        /// 点积
 320        /// </summary>
 321        /// <param name="a">第一个向量</param>
 322        /// <param name="b">第二个向量</param>
 323        /// <returns>点积结果</returns>
 324        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 325        public static FP Dot(FPVector3 a, FPVector3 b)
 326        {
 5327            long x = (a.X.RawValue * b.X.RawValue + 32768) >> 16;
 5328            long y = (a.Y.RawValue * b.Y.RawValue + 32768) >> 16;
 5329            long z = (a.Z.RawValue * b.Z.RawValue + 32768) >> 16;
 5330            return new FP(x + y + z);
 331        }
 332
 333        /// <summary>
 334        /// 叉积
 335        /// </summary>
 336        /// <param name="a">第一个向量</param>
 337        /// <param name="b">第二个向量</param>
 338        /// <returns>叉积向量</returns>
 339        /// <remarks>
 340        /// 叉积结果垂直于 a 和 b 所在的平面,方向由右手定则确定。
 341        /// 结果长度等于 |a| * |b| * sin(θ),即两个向量张成的平行四边形的面积。
 342        /// </remarks>
 343        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 344        public static FPVector3 Cross(FPVector3 a, FPVector3 b)
 345        {
 7346            long x = (a.Y.RawValue * b.Z.RawValue - a.Z.RawValue * b.Y.RawValue + 32768) >> 16;
 7347            long y = (a.Z.RawValue * b.X.RawValue - a.X.RawValue * b.Z.RawValue + 32768) >> 16;
 7348            long z = (a.X.RawValue * b.Y.RawValue - a.Y.RawValue * b.X.RawValue + 32768) >> 16;
 7349            return new FPVector3(new FP(x), new FP(y), new FP(z));
 350        }
 351
 352        /// <summary>
 353        /// 两个向量之间的距离
 354        /// </summary>
 355        /// <param name="a">第一个向量</param>
 356        /// <param name="b">第二个向量</param>
 357        /// <returns>欧几里得距离</returns>
 358        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 359        public static FP Distance(FPVector3 a, FPVector3 b)
 1360            => (a - b).Magnitude;
 361
 362        /// <summary>
 363        /// 两个向量之间的距离平方(更快)
 364        /// </summary>
 365        /// <param name="a">第一个向量</param>
 366        /// <param name="b">第二个向量</param>
 367        /// <returns>距离平方</returns>
 368        /// <remarks>
 369        /// 适用于比较距离大小而不需要精确值的场景(如范围检测)。
 370        /// 比 <see cref="Distance"/> 快约 3-5 倍(省去了平方根运算)。
 371        /// </remarks>
 372        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 373        public static FP DistanceSquared(FPVector3 a, FPVector3 b)
 1374            => (a - b).SqrMagnitude;
 375
 376        /// <summary>
 377        /// 线性插值(t 限制在 [0,1])
 378        /// </summary>
 379        /// <param name="a">起始向量</param>
 380        /// <param name="b">目标向量</param>
 381        /// <param name="t">插值系数 [0, 1]</param>
 382        /// <returns>插值结果</returns>
 383        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 384        public static FPVector3 Lerp(FPVector3 a, FPVector3 b, FP t)
 385        {
 1386            t = FPMath.Clamp01(t);
 1387            return new FPVector3(
 1388                new FP(a.X.RawValue + ((b.X.RawValue - a.X.RawValue) * t.RawValue + 32768 >> 16)),
 1389                new FP(a.Y.RawValue + ((b.Y.RawValue - a.Y.RawValue) * t.RawValue + 32768 >> 16)),
 1390                new FP(a.Z.RawValue + ((b.Z.RawValue - a.Z.RawValue) * t.RawValue + 32768 >> 16))
 1391            );
 392        }
 393
 394        /// <summary>
 395        /// 线性插值(t 不限制)
 396        /// </summary>
 397        /// <param name="a">起始向量</param>
 398        /// <param name="b">目标向量</param>
 399        /// <param name="t">插值系数(任意值)</param>
 400        /// <returns>插值结果</returns>
 401        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 402        public static FPVector3 LerpUnclamped(FPVector3 a, FPVector3 b, FP t)
 403        {
 1404            return new FPVector3(
 1405                new FP(a.X.RawValue + ((b.X.RawValue - a.X.RawValue) * t.RawValue + 32768 >> 16)),
 1406                new FP(a.Y.RawValue + ((b.Y.RawValue - a.Y.RawValue) * t.RawValue + 32768 >> 16)),
 1407                new FP(a.Z.RawValue + ((b.Z.RawValue - a.Z.RawValue) * t.RawValue + 32768 >> 16))
 1408            );
 409        }
 410
 411        /// <summary>
 412        /// 球面插值(Slerp)
 413        /// </summary>
 414        /// <param name="a">起始向量(建议归一化)</param>
 415        /// <param name="b">目标向量(建议归一化)</param>
 416        /// <param name="t">插值系数 [0, 1]</param>
 417        /// <returns>球面插值结果</returns>
 418        /// <remarks>
 419        /// Slerp 在球面上进行插值,保持恒定角速度。
 420        /// 适用于相机旋转、球面移动等场景。
 421        /// </remarks>
 422        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 423        public static FPVector3 Slerp(FPVector3 a, FPVector3 b, FP t)
 424        {
 1425            t = FPMath.Clamp01(t);
 1426            return SlerpUnclamped(a, b, t);
 427        }
 428
 429        /// <summary>
 430        /// 球面插值(不限制 t)
 431        /// </summary>
 432        /// <param name="a">起始向量(建议归一化)</param>
 433        /// <param name="b">目标向量(建议归一化)</param>
 434        /// <param name="t">插值系数(任意值)</param>
 435        /// <returns>球面插值结果</returns>
 436        public static FPVector3 SlerpUnclamped(FPVector3 a, FPVector3 b, FP t)
 437        {
 1438            FP dot = Dot(a, b);
 439
 440            // 如果点积为负,反转一个向量以走最短路径
 1441            if (dot.RawValue < 0)
 442            {
 0443                dot = -dot;
 0444                b = -b;
 445            }
 446
 447            // 限制 dot 在 [-1, 1] 内
 1448            dot = FPMath.Clamp(dot, -FP._1, FP._1);
 449
 450            // 如果点积接近 1,使用线性插值(避免除以接近 0 的 sin)
 1451            if (dot.RawValue > 65536 - 100)  // 1 - epsilon
 1452                return LerpUnclamped(a, b, t);
 453
 454            // 计算角度和 sin
 0455            FP theta = FP.Acos(dot);           // a 和 b 之间的角度
 0456            FP sinTheta = FP.Sin(theta);       // sin(角度)
 457
 458            // 计算权重
 0459            FP wa = FP.Sin((FP._1 - t) * theta) / sinTheta;
 0460            FP wb = FP.Sin(t * theta) / sinTheta;
 461
 0462            return a * wa + b * wb;
 463        }
 464
 465        /// <summary>
 466        /// 限制向量长度
 467        /// </summary>
 468        /// <param name="vector">要限制的向量</param>
 469        /// <param name="maxLength">最大长度</param>
 470        /// <returns>限制后的向量</returns>
 471        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 472        public static FPVector3 ClampMagnitude(FPVector3 vector, FP maxLength)
 473        {
 0474            FP sqrMag = vector.SqrMagnitude;
 0475            FP maxSqr = maxLength * maxLength;
 0476            if (sqrMag.RawValue > maxSqr.RawValue)
 0477                return vector.Normalized * maxLength;
 0478            return vector;
 479        }
 480
 481        /// <summary>
 482        /// 反射向量
 483        /// </summary>
 484        /// <param name="direction">入射方向</param>
 485        /// <param name="normal">法线(需归一化)</param>
 486        /// <returns>反射后的方向</returns>
 487        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 488        public static FPVector3 Reflect(FPVector3 direction, FPVector3 normal)
 489        {
 1490            FP twoDot = Dot(direction, normal) * 2;
 1491            return direction - normal * twoDot;
 492        }
 493
 494        /// <summary>
 495        /// 投影向量
 496        /// </summary>
 497        /// <param name="vector">要投影的向量</param>
 498        /// <param name="onNormal">投影目标法线</param>
 499        /// <returns>投影后的向量</returns>
 500        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 501        public static FPVector3 Project(FPVector3 vector, FPVector3 onNormal)
 502        {
 1503            FP sqrMag = onNormal.SqrMagnitude;
 1504            if (sqrMag.RawValue == 0) return Zero;
 1505            FP dot = Dot(vector, onNormal);
 1506            return onNormal * (dot / sqrMag);
 507        }
 508
 509        /// <summary>
 510        /// 投影到平面上
 511        /// </summary>
 512        /// <param name="vector">要投影的向量</param>
 513        /// <param name="planeNormal">平面法线</param>
 514        /// <returns>投影到平面后的向量</returns>
 515        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 516        public static FPVector3 ProjectOnPlane(FPVector3 vector, FPVector3 planeNormal)
 517        {
 0518            FP sqrMag = planeNormal.SqrMagnitude;
 0519            if (sqrMag.RawValue == 0) return vector;
 0520            FP dot = Dot(vector, planeNormal);
 0521            return vector - planeNormal * (dot / sqrMag);
 522        }
 523
 524        /// <summary>
 525        /// 分量逐元素相乘
 526        /// </summary>
 527        /// <param name="a">第一个向量</param>
 528        /// <param name="b">第二个向量</param>
 529        /// <returns>逐元素乘积</returns>
 530        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 531        public static FPVector3 Scale(FPVector3 a, FPVector3 b)
 0532            => new(a.X * b.X, a.Y * b.Y, a.Z * b.Z);
 533
 534        /// <summary>
 535        /// 取各分量的最小值
 536        /// </summary>
 537        /// <param name="a">第一个向量</param>
 538        /// <param name="b">第二个向量</param>
 539        /// <returns>各分量的最小值</returns>
 540        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 541        public static FPVector3 Min(FPVector3 a, FPVector3 b)
 0542            => new(FPMath.Min(a.X, b.X), FPMath.Min(a.Y, b.Y), FPMath.Min(a.Z, b.Z));
 543
 544        /// <summary>
 545        /// 取各分量的最大值
 546        /// </summary>
 547        /// <param name="a">第一个向量</param>
 548        /// <param name="b">第二个向量</param>
 549        /// <returns>各分量的最大值</returns>
 550        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 551        public static FPVector3 Max(FPVector3 a, FPVector3 b)
 0552            => new(FPMath.Max(a.X, b.X), FPMath.Max(a.Y, b.Y), FPMath.Max(a.Z, b.Z));
 553
 554        #endregion
 555
 556        #region 实例方法
 557
 558        /// <summary>
 559        /// 与另一个向量相等判断
 560        /// </summary>
 561        /// <param name="other">要比较的向量</param>
 562        /// <returns>相等返回 true</returns>
 563        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 564        public readonly bool Equals(FPVector3 other)
 0565            => this == other;
 566
 567        /// <summary>
 568        /// 与对象相等判断
 569        /// </summary>
 570        /// <param name="obj">要比较的对象</param>
 571        /// <returns>相等返回 true</returns>
 572        public override readonly bool Equals(object? obj)
 0573            => obj is FPVector3 other && Equals(other);
 574
 575        /// <summary>
 576        /// 获取哈希码
 577        /// </summary>
 578        /// <returns>哈希码</returns>
 579        public override readonly int GetHashCode()
 580        {
 0581            int hash = 17;
 0582            hash = hash * 31 + X.GetHashCode();
 0583            hash = hash * 31 + Y.GetHashCode();
 0584            hash = hash * 31 + Z.GetHashCode();
 0585            return hash;
 586        }
 587
 588        /// <summary>
 589        /// 转换为字符串
 590        /// </summary>
 591        /// <returns>字符串表示 "(X, Y, Z)"</returns>
 592        public override readonly string ToString()
 0593            => $"({X}, {Y}, {Z})";
 594
 595        #endregion
 596    }
 597}

/home/runner/work/Sideline/Sideline/godot/scripts/lattice/obj/Release/net8.0/SwizzleGenerator/Lattice.Generators.SwizzleGenerator/FPVector3.Swizzle.g.cs

File '/home/runner/work/Sideline/Sideline/godot/scripts/lattice/obj/Release/net8.0/SwizzleGenerator/Lattice.Generators.SwizzleGenerator/FPVector3.Swizzle.g.cs' does not exist (any more).

Methods/Properties

.ctor(Lattice.Math.FP,Lattice.Math.FP,Lattice.Math.FP)
.ctor(System.Int32,System.Int32,System.Int32)
.ctor(Lattice.Math.FP,Lattice.Math.FP)
.ctor(Lattice.Math.FP)
get_Zero()
get_One()
get_Right()
get_Left()
get_Up()
get_Down()
get_Forward()
get_Back()
get_MaxValue()
get_MinValue()
get_SqrMagnitude()
get_SqrMagnitudeFast()
get_Magnitude()
get_Normalized()
NormalizedWithMagnitude(Lattice.Math.FP&)
Normalize(Lattice.Math.FPVector3)
Normalize(Lattice.Math.FPVector3,Lattice.Math.FP&)
op_Addition(Lattice.Math.FPVector3,Lattice.Math.FPVector3)
op_Subtraction(Lattice.Math.FPVector3,Lattice.Math.FPVector3)
op_UnaryNegation(Lattice.Math.FPVector3)
op_Multiply(Lattice.Math.FPVector3,Lattice.Math.FP)
op_Multiply(Lattice.Math.FP,Lattice.Math.FPVector3)
op_Division(Lattice.Math.FPVector3,Lattice.Math.FP)
op_Equality(Lattice.Math.FPVector3,Lattice.Math.FPVector3)
op_Inequality(Lattice.Math.FPVector3,Lattice.Math.FPVector3)
op_Implicit(Lattice.Math.FPVector2)
op_Explicit(Lattice.Math.FPVector3)
Dot(Lattice.Math.FPVector3,Lattice.Math.FPVector3)
Cross(Lattice.Math.FPVector3,Lattice.Math.FPVector3)
Distance(Lattice.Math.FPVector3,Lattice.Math.FPVector3)
DistanceSquared(Lattice.Math.FPVector3,Lattice.Math.FPVector3)
Lerp(Lattice.Math.FPVector3,Lattice.Math.FPVector3,Lattice.Math.FP)
LerpUnclamped(Lattice.Math.FPVector3,Lattice.Math.FPVector3,Lattice.Math.FP)
Slerp(Lattice.Math.FPVector3,Lattice.Math.FPVector3,Lattice.Math.FP)
SlerpUnclamped(Lattice.Math.FPVector3,Lattice.Math.FPVector3,Lattice.Math.FP)
ClampMagnitude(Lattice.Math.FPVector3,Lattice.Math.FP)
Reflect(Lattice.Math.FPVector3,Lattice.Math.FPVector3)
Project(Lattice.Math.FPVector3,Lattice.Math.FPVector3)
ProjectOnPlane(Lattice.Math.FPVector3,Lattice.Math.FPVector3)
Scale(Lattice.Math.FPVector3,Lattice.Math.FPVector3)
Min(Lattice.Math.FPVector3,Lattice.Math.FPVector3)
Max(Lattice.Math.FPVector3,Lattice.Math.FPVector3)
Equals(Lattice.Math.FPVector3)
Equals(System.Object)
GetHashCode()
ToString()
get_XX()
get_XY()
get_XZ()
get_XO()
get_YX()
get_YY()
get_YZ()
get_YO()
get_ZX()
get_ZY()
get_ZZ()
get_ZO()
get_OX()
get_OY()
get_OZ()
get_OO()
get_XXX()
get_XXY()
get_XXZ()
get_XXO()
get_XYX()
get_XYY()
get_XYZ()
get_XYO()
get_XZX()
get_XZY()
get_XZZ()
get_XZO()
get_XOX()
get_XOY()
get_XOZ()
get_XOO()
get_YXX()
get_YXY()
get_YXZ()
get_YXO()
get_YYX()
get_YYY()
get_YYZ()
get_YYO()
get_YZX()
get_YZY()
get_YZZ()
get_YZO()
get_YOX()
get_YOY()
get_YOZ()
get_YOO()
get_ZXX()
get_ZXY()
get_ZXZ()
get_ZXO()
get_ZYX()
get_ZYY()
get_ZYZ()
get_ZYO()
get_ZZX()
get_ZZY()
get_ZZZ()
get_ZZO()
get_ZOX()
get_ZOY()
get_ZOZ()
get_ZOO()
get_OXX()
get_OXY()
get_OXZ()
get_OXO()
get_OYX()
get_OYY()
get_OYZ()
get_OYO()
get_OZX()
get_OZY()
get_OZZ()
get_OZO()
get_OOX()
get_OOY()
get_OOZ()
get_OOO()