Skip to content

Commit 076a614

Browse files
authored
Revert "Move axes from math to float3 (Unity-Technologies#146)" (Unity-Technologies#149)
This reverts commit e1340b2. Reverting because this change broke burst compilation. This reopens DOTS-1356 and is now blocked.
1 parent 3c8786a commit 076a614

7 files changed

Lines changed: 71 additions & 91 deletions

File tree

src/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
- Added [Serializable] to RigidTransform.
77
- Added math.ceillog2().
88
- Added math.floorlog2().
9-
- Added float3.down, float3.forward, etc for Cartesian coordinate axes that match UnityEngine Vector3 equivalents.
9+
- Added math.down(), math.forward(), etc for Cartesian coordinate axes that match UnityEngine Vector3 equivalents.
1010
- Added math.ispow2().
1111
- Added half.MinValueAsHalf and half.MaxValueAsHalf to avoid having to explicitly convert from float.
1212
- Added a float3x3 constructor which takes a float4x4 as input.

src/Tests/Tests/Shared/TestMath.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3121,12 +3121,12 @@ public static void infinity_double()
31213121
[TestCompiler]
31223122
public static void helper_axes()
31233123
{
3124-
TestUtils.AreEqual(float3(1.0f, 0.0f, 0.0f), float3.right);
3125-
TestUtils.AreEqual(float3(-1.0f, 0.0f, 0.0f), float3.left);
3126-
TestUtils.AreEqual(float3(0.0f, 1.0f, 0.0f), float3.up);
3127-
TestUtils.AreEqual(float3(0.0f, -1.0f, 0.0f), float3.down);
3128-
TestUtils.AreEqual(float3(0.0f, 0.0f, 1.0f), float3.forward);
3129-
TestUtils.AreEqual(float3(0.0f, 0.0f, -1.0f), float3.back);
3124+
TestUtils.AreEqual(float3(1.0f, 0.0f, 0.0f), right());
3125+
TestUtils.AreEqual(float3(-1.0f, 0.0f, 0.0f), left());
3126+
TestUtils.AreEqual(float3(0.0f, 1.0f, 0.0f), up());
3127+
TestUtils.AreEqual(float3(0.0f, -1.0f, 0.0f), down());
3128+
TestUtils.AreEqual(float3(0.0f, 0.0f, 1.0f), forward());
3129+
TestUtils.AreEqual(float3(0.0f, 0.0f, -1.0f), back());
31303130
}
31313131

31323132
[TestCompiler]

src/Tests/Tests/Shared/TestPlane.cs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -81,23 +81,23 @@ public static void ConstructWithCoefficients_NonUnitLengthNormal()
8181
[TestCompiler]
8282
public static void ConstructWithNormalAndPointInPlane_NegativeDistance()
8383
{
84-
var n = float3.up;
85-
var pointInPlane = float3.up;
84+
var n = math.up();
85+
var pointInPlane = math.up();
8686
var p = new Plane(n, pointInPlane);
8787

88-
TestUtils.AreEqual(new float4(float3.up, -1.0f), p.NormalAndDistance);
88+
TestUtils.AreEqual(new float4(math.up(), -1.0f), p.NormalAndDistance);
8989
TestUtils.AreEqual(n, p.Normal);
9090
TestUtils.AreEqual(-1.0f, p.Distance);
9191
}
9292

9393
[TestCompiler]
9494
public static void ConstructWithNormalAndPointInPlane_PositiveDistance()
9595
{
96-
var n = float3.down;
97-
var pointInPlane = float3.up;
96+
var n = math.down();
97+
var pointInPlane = math.up();
9898
var p = new Plane(n, pointInPlane);
9999

100-
TestUtils.AreEqual(new float4(float3.down, 1.0f), p.NormalAndDistance);
100+
TestUtils.AreEqual(new float4(math.down(), 1.0f), p.NormalAndDistance);
101101
TestUtils.AreEqual(n, p.Normal);
102102
TestUtils.AreEqual(1.0f, p.Distance);
103103
}
@@ -158,29 +158,29 @@ public static void SignedDistanceToPointTrivial()
158158
var p = new Plane(math.up(), 0.0f);
159159

160160
TestUtils.AreEqual(0.0f, p.SignedDistanceToPoint(float3.zero));
161-
TestUtils.AreEqual(0.0f, p.SignedDistanceToPoint(float3.left));
162-
TestUtils.AreEqual(0.0f, p.SignedDistanceToPoint(float3.right));
163-
TestUtils.AreEqual(0.0f, p.SignedDistanceToPoint(float3.forward));
164-
TestUtils.AreEqual(0.0f, p.SignedDistanceToPoint(float3.back));
165-
TestUtils.AreEqual(1.0f, p.SignedDistanceToPoint(float3.up));
166-
TestUtils.AreEqual(1.0f, p.SignedDistanceToPoint(float3.up + float3.left));
167-
TestUtils.AreEqual(1.0f, p.SignedDistanceToPoint(float3.up + float3.right));
168-
TestUtils.AreEqual(1.0f, p.SignedDistanceToPoint(float3.up + float3.back));
169-
TestUtils.AreEqual(1.0f, p.SignedDistanceToPoint(float3.up + float3.forward));
170-
TestUtils.AreEqual(-1.0f, p.SignedDistanceToPoint(float3.down));
171-
TestUtils.AreEqual(-1.0f, p.SignedDistanceToPoint(float3.down + float3.left));
172-
TestUtils.AreEqual(-1.0f, p.SignedDistanceToPoint(float3.down + float3.right));
173-
TestUtils.AreEqual(-1.0f, p.SignedDistanceToPoint(float3.down + float3.back));
174-
TestUtils.AreEqual(-1.0f, p.SignedDistanceToPoint(float3.down + float3.forward));
161+
TestUtils.AreEqual(0.0f, p.SignedDistanceToPoint(math.left()));
162+
TestUtils.AreEqual(0.0f, p.SignedDistanceToPoint(math.right()));
163+
TestUtils.AreEqual(0.0f, p.SignedDistanceToPoint(math.forward()));
164+
TestUtils.AreEqual(0.0f, p.SignedDistanceToPoint(math.back()));
165+
TestUtils.AreEqual(1.0f, p.SignedDistanceToPoint(math.up()));
166+
TestUtils.AreEqual(1.0f, p.SignedDistanceToPoint(math.up() + math.left()));
167+
TestUtils.AreEqual(1.0f, p.SignedDistanceToPoint(math.up() + math.right()));
168+
TestUtils.AreEqual(1.0f, p.SignedDistanceToPoint(math.up() + math.back()));
169+
TestUtils.AreEqual(1.0f, p.SignedDistanceToPoint(math.up() + math.forward()));
170+
TestUtils.AreEqual(-1.0f, p.SignedDistanceToPoint(math.down()));
171+
TestUtils.AreEqual(-1.0f, p.SignedDistanceToPoint(math.down() + math.left()));
172+
TestUtils.AreEqual(-1.0f, p.SignedDistanceToPoint(math.down() + math.right()));
173+
TestUtils.AreEqual(-1.0f, p.SignedDistanceToPoint(math.down() + math.back()));
174+
TestUtils.AreEqual(-1.0f, p.SignedDistanceToPoint(math.down() + math.forward()));
175175
}
176176

177177
[TestCompiler]
178178
public static void ProjectionTrivial()
179179
{
180-
var p = new Plane(float3.up, 0.0f);
181-
var expected = float3.left + float3.forward;
180+
var p = new Plane(math.up(), 0.0f);
181+
var expected = math.left() + math.forward();
182182

183-
TestUtils.AreEqual(expected, p.Projection(float3.up + expected));
183+
TestUtils.AreEqual(expected, p.Projection(math.up() + expected));
184184
}
185185

186186
[TestCompiler]

src/Unity.Mathematics/Unity.Mathematics.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@
8787
<Compile Include="double4x2.gen.cs" />
8888
<Compile Include="double4x3.gen.cs" />
8989
<Compile Include="double4x4.gen.cs" />
90-
<Compile Include="float3.cs" />
9190
<Compile Include="Geometry\MinMaxAABB.cs" />
9291
<Compile Include="Geometry\Plane.cs" />
9392
<Compile Include="float2.gen.cs" />

src/Unity.Mathematics/float3.cs

Lines changed: 0 additions & 49 deletions
This file was deleted.

src/Unity.Mathematics/float3.cs.meta

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/Unity.Mathematics/math.cs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3987,6 +3987,47 @@ public static unsafe uint hash(void* pBuffer, int numBytes, uint seed = 0)
39873987
[MethodImpl(MethodImplOptions.AggressiveInlining)]
39883988
public static float3 up() { return new float3(0.0f, 1.0f, 0.0f); } // for compatibility
39893989

3990+
/// <summary>
3991+
/// Unity's down axis (0, -1, 0).
3992+
/// </summary>
3993+
/// <remarks>Matches [https://docs.unity3d.com/ScriptReference/Vector3-down.html](https://docs.unity3d.com/ScriptReference/Vector3-down.html)</remarks>
3994+
/// <returns>The down axis.</returns>
3995+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
3996+
public static float3 down() { return new float3(0.0f, -1.0f, 0.0f); }
3997+
3998+
/// <summary>
3999+
/// Unity's forward axis (0, 0, 1).
4000+
/// </summary>
4001+
/// <remarks>Matches [https://docs.unity3d.com/ScriptReference/Vector3-forward.html](https://docs.unity3d.com/ScriptReference/Vector3-forward.html)</remarks>
4002+
/// <returns>The forward axis.</returns>
4003+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
4004+
public static float3 forward() { return new float3(0.0f, 0.0f, 1.0f); }
4005+
4006+
/// <summary>
4007+
/// Unity's back axis (0, 0, -1).
4008+
/// </summary>
4009+
/// <remarks>Matches [https://docs.unity3d.com/ScriptReference/Vector3-back.html](https://docs.unity3d.com/ScriptReference/Vector3-back.html)</remarks>
4010+
/// <returns>The back axis.</returns>
4011+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
4012+
public static float3 back() { return new float3(0.0f, 0.0f, -1.0f); }
4013+
4014+
/// <summary>
4015+
/// Unity's left axis (-1, 0, 0).
4016+
/// </summary>
4017+
/// <remarks>Matches [https://docs.unity3d.com/ScriptReference/Vector3-left.html](https://docs.unity3d.com/ScriptReference/Vector3-left.html)</remarks>
4018+
/// <returns>The left axis.</returns>
4019+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
4020+
public static float3 left() { return new float3(-1.0f, 0.0f, 0.0f); }
4021+
4022+
/// <summary>
4023+
/// Unity's right axis (1, 0, 0).
4024+
/// </summary>
4025+
/// <remarks>Matches [https://docs.unity3d.com/ScriptReference/Vector3-right.html](https://docs.unity3d.com/ScriptReference/Vector3-right.html)</remarks>
4026+
/// <returns>The right axis.</returns>
4027+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
4028+
public static float3 right() { return new float3(1.0f, 0.0f, 0.0f); }
4029+
4030+
39904031
// Internal
39914032

39924033
// SSE shuffles

0 commit comments

Comments
 (0)