brutal/Brutal.Numerics/Rect/doubleRect/doubleRect.gen.cs
Rian Drake b578433e37 first
2026-10-15 17:10:50 +13:00

68 lines
2 KiB
C#

// <auto-generated /> - edit Rect.tt to modify
#nullable enable
namespace Brutal.Numerics;
/// <summary>
/// Implements a 2D rectangle with double components
/// </summary>
public struct doubleRect
{
/// <summary>
/// The start of the rectangle.
/// </summary>
public double2 Min;
/// <summary>
/// The end of the rectangle.
/// </summary>
public double2 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<double> AsSpan()
{
return MemoryMarshal.CreateSpan(ref Unsafe.As<doubleRect, double>(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<double> AsReadOnlySpan()
{
return MemoryMarshal.CreateReadOnlySpan(in Unsafe.As<doubleRect, double>(ref Unsafe.AsRef(in this)), 4);
}
static doubleRect()
{
if (Unsafe.SizeOf<doubleRect>() != 4 * sizeof(double))
throw new Exception("doubleRect is not the right size!");
}
/// <summary>
/// The center of the rectangle.
/// </summary>
public double2 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 double2 Extent
{
readonly get => Max - Min;
set => Max = Min + value;
}
}