Skip to content

Commit

Permalink
Add angle conversion utilities for range types
Browse files Browse the repository at this point in the history
  • Loading branch information
hyazinthh committed Nov 12, 2024
1 parent 3b8fcb9 commit 15a58aa
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 0 deletions.
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
- Updated System.Text.Json dependency (CVE-2024-43485)
- Added angle conversion utilities for ranges

### 5.3.5
- [Base] added IsEmpty/IsEmptyOrNull overloads for Array/ICollection with efficient implementation
Expand Down
98 changes: 98 additions & 0 deletions src/Aardvark.Base/Math/RangesBoxes/Box_auto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8981,6 +8981,55 @@ public static Range1f GetBoundingRange(this IEnumerable<float> points)

#region Range extensions

public static partial class Conversion
{
#region Angles (Radians, Degrees, Gons)

/// <summary>
/// Converts the angles given in degrees to radians.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Range1f RadiansFromDegrees(this Range1f degrees)
=> new(degrees.Min.RadiansFromDegrees(), degrees.Max.RadiansFromDegrees());

/// <summary>
/// Converts the angles given in gons to radians.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Range1f RadiansFromGons(this Range1f gons)
=> new(gons.Min.RadiansFromGons(), gons.Max.RadiansFromGons());

/// <summary>
/// Converts the angles given in radians to degrees.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Range1f DegreesFromRadians(this Range1f radians)
=> new(radians.Min.DegreesFromRadians(), radians.Max.DegreesFromRadians());

/// <summary>
/// Converts the angles given in gons to degrees.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Range1f DegreesFromGons(this Range1f gons)
=> new(gons.Min.DegreesFromGons(), gons.Max.DegreesFromGons());

/// <summary>
/// Converts the angles given in radians to gons.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Range1f GonsFromRadians(this Range1f radians)
=> new(radians.Min.GonsFromRadians(), radians.Max.GonsFromRadians());

/// <summary>
/// Converts the angles given in degrees to gons.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Range1f GonsFromDegrees(this Range1f degrees)
=> new(degrees.Min.GonsFromDegrees(), degrees.Max.GonsFromDegrees());

#endregion
}

public static partial class RangeExtensions
{
/// <summary>
Expand Down Expand Up @@ -9991,6 +10040,55 @@ public static Range1d GetBoundingRange(this IEnumerable<double> points)

#region Range extensions

public static partial class Conversion
{
#region Angles (Radians, Degrees, Gons)

/// <summary>
/// Converts the angles given in degrees to radians.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Range1d RadiansFromDegrees(this Range1d degrees)
=> new(degrees.Min.RadiansFromDegrees(), degrees.Max.RadiansFromDegrees());

/// <summary>
/// Converts the angles given in gons to radians.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Range1d RadiansFromGons(this Range1d gons)
=> new(gons.Min.RadiansFromGons(), gons.Max.RadiansFromGons());

/// <summary>
/// Converts the angles given in radians to degrees.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Range1d DegreesFromRadians(this Range1d radians)
=> new(radians.Min.DegreesFromRadians(), radians.Max.DegreesFromRadians());

/// <summary>
/// Converts the angles given in gons to degrees.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Range1d DegreesFromGons(this Range1d gons)
=> new(gons.Min.DegreesFromGons(), gons.Max.DegreesFromGons());

/// <summary>
/// Converts the angles given in radians to gons.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Range1d GonsFromRadians(this Range1d radians)
=> new(radians.Min.GonsFromRadians(), radians.Max.GonsFromRadians());

/// <summary>
/// Converts the angles given in degrees to gons.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Range1d GonsFromDegrees(this Range1d degrees)
=> new(degrees.Min.GonsFromDegrees(), degrees.Max.GonsFromDegrees());

#endregion
}

public static partial class RangeExtensions
{
/// <summary>
Expand Down
22 changes: 22 additions & 0 deletions src/Aardvark.Base/Math/RangesBoxes/Box_template.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2381,6 +2381,28 @@ public static __ltype__[] GetOutlineCornersCW(this __type__ box, __ltype__ fromP

#region Range extensions

//# if (ft.IsReal) {
public static partial class Conversion
{
#region Angles (Radians, Degrees, Gons)

//# var units = new[] { "Radians", "Degrees", "Gons" };
//# units.ForEach(u1 => {
//# units.ForEach(u2 => { if (u1 == u2) return;
//# var n1 = u1.ToLower();
//# var n2 = u2.ToLower();
/// <summary>
/// Converts the angles given in __n2__ to __n1__.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static __type__ __u1__From__u2__(this __type__ __n2__)
=> new(__n2__.Min.__u1__From__u2__(), __n2__.Max.__u1__From__u2__());

//# }); });
#endregion
}

//# }
public static partial class __bnamecaps__Extensions
{
/// <summary>
Expand Down

0 comments on commit 15a58aa

Please sign in to comment.