brutal/brutal.numerics/Brutal.Numerics/Rect/floatRect/floatRect.gen.cs
2026-10-15 14:12:02 +13:00

62 lines
1.8 KiB
C#

// <auto-generated /> - edit Rect.tt to modify
#nullable enable
namespace Brutal.Numerics;
/// <summary>
/// Implements a 2D rectangle with float components
/// </summary>
public struct floatRect
{
/// <summary>
/// The start of the rectangle.
/// </summary>
public float2 Min;
/// <summary>
/// The end of the rectangle.
/// </summary>
public float2 Max;
/// <summary>A mutable view over the 4 components: min xy, then max xy.</summary>
/// <remarks>
/// Deliberately NOT a readonly member, because it hands out a writable view. The consequence is that
/// calling it on a readonly field or an <see langword="in" /> parameter gets you a span over a
/// defensive COPY, so writes there are silently lost - reach for <see cref="AsReadOnlySpan" /> instead.
/// </remarks>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Span<float> AsSpan()
{
return MemoryMarshal.CreateSpan(ref Unsafe.As<floatRect, float>(ref this), 4);
}
/// <summary>A read-only view over the 4 components, safe in the readonly contexts where <see cref="AsSpan" /> would view a copy.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly ReadOnlySpan<float> AsReadOnlySpan()
{
return MemoryMarshal.CreateReadOnlySpan(in Unsafe.As<floatRect, float>(ref Unsafe.AsRef(in this)), 4);
}
/// <summary>
/// The center of the rectangle.
/// </summary>
public float2 Center
{
readonly get => (Min + Max) / 2;
set
{
var half = Extent / 2;
Min = value - half;
Max = value + half;
}
}
/// <summary>
/// The size of the rectangle.
/// </summary>
public float2 Extent
{
readonly get => Max - Min;
set => Max = Min + value;
}
}