From 15a58aa9e9f95baed785f249194cf104a6c0681f Mon Sep 17 00:00:00 2001 From: Martin Date: Tue, 12 Nov 2024 19:03:49 +0100 Subject: [PATCH] Add angle conversion utilities for range types --- RELEASE_NOTES.md | 1 + .../Math/RangesBoxes/Box_auto.cs | 98 +++++++++++++++++++ .../Math/RangesBoxes/Box_template.cs | 22 +++++ 3 files changed, 121 insertions(+) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index aad3a0c2..61c92d6a 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -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 diff --git a/src/Aardvark.Base/Math/RangesBoxes/Box_auto.cs b/src/Aardvark.Base/Math/RangesBoxes/Box_auto.cs index facb2e63..2ba7fc47 100644 --- a/src/Aardvark.Base/Math/RangesBoxes/Box_auto.cs +++ b/src/Aardvark.Base/Math/RangesBoxes/Box_auto.cs @@ -8981,6 +8981,55 @@ public static Range1f GetBoundingRange(this IEnumerable points) #region Range extensions + public static partial class Conversion + { + #region Angles (Radians, Degrees, Gons) + + /// + /// Converts the angles given in degrees to radians. + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static Range1f RadiansFromDegrees(this Range1f degrees) + => new(degrees.Min.RadiansFromDegrees(), degrees.Max.RadiansFromDegrees()); + + /// + /// Converts the angles given in gons to radians. + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static Range1f RadiansFromGons(this Range1f gons) + => new(gons.Min.RadiansFromGons(), gons.Max.RadiansFromGons()); + + /// + /// Converts the angles given in radians to degrees. + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static Range1f DegreesFromRadians(this Range1f radians) + => new(radians.Min.DegreesFromRadians(), radians.Max.DegreesFromRadians()); + + /// + /// Converts the angles given in gons to degrees. + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static Range1f DegreesFromGons(this Range1f gons) + => new(gons.Min.DegreesFromGons(), gons.Max.DegreesFromGons()); + + /// + /// Converts the angles given in radians to gons. + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static Range1f GonsFromRadians(this Range1f radians) + => new(radians.Min.GonsFromRadians(), radians.Max.GonsFromRadians()); + + /// + /// Converts the angles given in degrees to gons. + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static Range1f GonsFromDegrees(this Range1f degrees) + => new(degrees.Min.GonsFromDegrees(), degrees.Max.GonsFromDegrees()); + + #endregion + } + public static partial class RangeExtensions { /// @@ -9991,6 +10040,55 @@ public static Range1d GetBoundingRange(this IEnumerable points) #region Range extensions + public static partial class Conversion + { + #region Angles (Radians, Degrees, Gons) + + /// + /// Converts the angles given in degrees to radians. + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static Range1d RadiansFromDegrees(this Range1d degrees) + => new(degrees.Min.RadiansFromDegrees(), degrees.Max.RadiansFromDegrees()); + + /// + /// Converts the angles given in gons to radians. + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static Range1d RadiansFromGons(this Range1d gons) + => new(gons.Min.RadiansFromGons(), gons.Max.RadiansFromGons()); + + /// + /// Converts the angles given in radians to degrees. + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static Range1d DegreesFromRadians(this Range1d radians) + => new(radians.Min.DegreesFromRadians(), radians.Max.DegreesFromRadians()); + + /// + /// Converts the angles given in gons to degrees. + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static Range1d DegreesFromGons(this Range1d gons) + => new(gons.Min.DegreesFromGons(), gons.Max.DegreesFromGons()); + + /// + /// Converts the angles given in radians to gons. + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static Range1d GonsFromRadians(this Range1d radians) + => new(radians.Min.GonsFromRadians(), radians.Max.GonsFromRadians()); + + /// + /// Converts the angles given in degrees to gons. + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static Range1d GonsFromDegrees(this Range1d degrees) + => new(degrees.Min.GonsFromDegrees(), degrees.Max.GonsFromDegrees()); + + #endregion + } + public static partial class RangeExtensions { /// diff --git a/src/Aardvark.Base/Math/RangesBoxes/Box_template.cs b/src/Aardvark.Base/Math/RangesBoxes/Box_template.cs index edfd8e1c..4985138a 100644 --- a/src/Aardvark.Base/Math/RangesBoxes/Box_template.cs +++ b/src/Aardvark.Base/Math/RangesBoxes/Box_template.cs @@ -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(); + /// + /// Converts the angles given in __n2__ to __n1__. + /// + [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 { ///