Skip to content

Commit e63354d

Browse files
committed
update: added bounds conversions
1 parent 8468f4e commit e63354d

2 files changed

Lines changed: 63 additions & 0 deletions

File tree

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
using System.Runtime.CompilerServices;
2+
using UnityEngine;
3+
4+
namespace FixedMathSharp
5+
{
6+
/// <summary>
7+
/// Provides extension methods for converting between Unity Bounds and FixedMathSharp bounds types.
8+
/// </summary>
9+
public static class BoundsUnityExtensions
10+
{
11+
/// <summary>
12+
/// Converts a FixedMathSharp BoundingBox into Unity Bounds.
13+
/// </summary>
14+
/// <param name="boundingBox">The BoundingBox to convert.</param>
15+
/// <returns>A Unity Bounds with equivalent minimum and maximum corners.</returns>
16+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
17+
public static Bounds ToBounds(this BoundingBox boundingBox)
18+
{
19+
Bounds bounds = new Bounds();
20+
bounds.SetMinMax(boundingBox.Min.ToVector3(), boundingBox.Max.ToVector3());
21+
return bounds;
22+
}
23+
24+
/// <summary>
25+
/// Converts a FixedMathSharp BoundingArea into Unity Bounds.
26+
/// </summary>
27+
/// <param name="boundingArea">The BoundingArea to convert.</param>
28+
/// <returns>A Unity Bounds with equivalent minimum and maximum corners.</returns>
29+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
30+
public static Bounds ToBounds(this BoundingArea boundingArea)
31+
{
32+
Bounds bounds = new Bounds();
33+
bounds.SetMinMax(boundingArea.Min.ToVector3(), boundingArea.Max.ToVector3());
34+
return bounds;
35+
}
36+
37+
/// <summary>
38+
/// Converts Unity Bounds into a FixedMathSharp BoundingBox.
39+
/// </summary>
40+
/// <param name="bounds">The Unity Bounds to convert.</param>
41+
/// <returns>A BoundingBox with equivalent minimum and maximum corners.</returns>
42+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
43+
public static BoundingBox ToBoundingBox(this Bounds bounds)
44+
{
45+
BoundingBox boundingBox = default;
46+
boundingBox.SetMinMax(bounds.min.ToVector3d(), bounds.max.ToVector3d());
47+
return boundingBox;
48+
}
49+
50+
/// <summary>
51+
/// Converts Unity Bounds into a FixedMathSharp BoundingArea.
52+
/// </summary>
53+
/// <param name="bounds">The Unity Bounds to convert.</param>
54+
/// <returns>A BoundingArea with equivalent minimum and maximum corners.</returns>
55+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
56+
public static BoundingArea ToBoundingArea(this Bounds bounds)
57+
{
58+
return new BoundingArea(bounds.min.ToVector3d(), bounds.max.ToVector3d());
59+
}
60+
}
61+
}

Runtime/Extensions/Bounds.Extensions.cs.meta

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)