-
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathVector2d.Extensions.cs
More file actions
94 lines (87 loc) · 4.56 KB
/
Copy pathVector2d.Extensions.cs
File metadata and controls
94 lines (87 loc) · 4.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
//=======================================================================
// Vector2d.Extensions.cs
//=======================================================================
// MIT License, Copyright (c) 2024–present David Oravsky (mrdav30)
// See LICENSE file in the project root for full license information.
//=======================================================================
using UnityEngine;
namespace FixedMathSharp
{
/// <summary>
/// Provides conversions between Unity vectors and FixedMathSharp 2D vectors.
/// </summary>
public static partial class Vector2dExtensions
{
/// <summary>
/// Converts a Unity Vector2 to a FixedMathSharp Vector2d.
/// </summary>
/// <remarks>
/// This is a direct component mapping for Unity 2D values. In FixedMathSharp 2D plane math,
/// <c>+X</c> is right and <c>+Y</c> is forward/up within the 2D plane.
/// </remarks>
/// <param name="vec2">The Unity Vector2 to convert.</param>
/// <returns>A FixedMathSharp Vector2d.</returns>
public static Vector2d ToVector2d(this Vector2 vec2) =>
Vector2d.FromDouble(vec2.x, vec2.y);
/// <summary>
/// Converts a Unity Vector3 to a FixedMathSharp Vector2d using the x and y components.
/// </summary>
/// <remarks>
/// This is a direct component projection onto the Unity XY plane. Use
/// <see cref="ToVector2dXZ(Vector3)"/> when the 2D vector represents Unity ground-plane
/// movement where <c>+Z</c> is forward.
/// </remarks>
/// <param name="vec">The Unity Vector3 to convert.</param>
/// <returns>A FixedMathSharp Vector2d projected onto the XY plane.</returns>
public static Vector2d ToVector2dXY(this Vector3 vec) =>
Vector2d.FromDouble(vec.x, vec.y);
/// <summary>
/// Converts a Unity Vector3 to a FixedMathSharp Vector2d using the x and z components.
/// </summary>
/// <remarks>
/// Unity and FixedMathSharp both use <c>+X</c> right and <c>+Z</c> forward in 3D. This helper
/// keeps that convention explicit when reducing Unity XZ-plane directions or positions to
/// FixedMathSharp 2D plane math.
/// </remarks>
/// <param name="vec">The Unity Vector3 to convert.</param>
/// <returns>A FixedMathSharp Vector2d projected onto the XZ plane.</returns>
public static Vector2d ToVector2dXZ(this Vector3 vec) =>
Vector2d.FromDouble(vec.x, vec.z);
/// <summary>
/// Converts a FixedMathSharp Vector2d to a Unity Vector2.
/// </summary>
/// <remarks>
/// This is a direct component mapping for 2D values and does not perform any 3D axis
/// conversion.
/// </remarks>
/// <param name="vec">The FixedMathSharp Vector2d to convert.</param>
/// <returns>A Unity Vector2.</returns>
public static Vector2 ToVector2(this Vector2d vec) =>
new Vector2((float)vec.X, (float)vec.Y);
/// <summary>
/// Converts a FixedMathSharp Vector2d to a Unity Vector3 on the XY plane, with the specified z-value.
/// </summary>
/// <remarks>
/// This is a direct component projection onto Unity's XY plane. Use
/// <see cref="ToVector3XZ(Vector2d, float)"/> when the 2D vector represents 3D ground-plane
/// values using <c>+Z</c> as forward.
/// </remarks>
/// <param name="vec">The FixedMathSharp Vector2d to convert.</param>
/// <param name="z">The z-value to use in the resulting Vector3.</param>
/// <returns>A Unity Vector3 with x/y populated from the Vector2d.</returns>
public static Vector3 ToVector3XY(this Vector2d vec, float z = 0f) =>
new Vector3((float)vec.X, (float)vec.Y, z);
/// <summary>
/// Converts a FixedMathSharp Vector2d to a Unity Vector3 on the XZ plane, with the specified y-value.
/// </summary>
/// <remarks>
/// The FixedMathSharp <c>Y</c> component is mapped to Unity <c>z</c>, preserving Unity and
/// FixedMathSharp's shared <c>+Z</c> forward convention for 3D ground-plane values.
/// </remarks>
/// <param name="vec">The FixedMathSharp Vector2d to convert.</param>
/// <param name="y">The y-value to use in the resulting Vector3.</param>
/// <returns>A Unity Vector3 with x/z populated from the Vector2d.</returns>
public static Vector3 ToVector3XZ(this Vector2d vec, float y = 0f) =>
new Vector3((float)vec.X, y, (float)vec.Y);
}
}