mirror of
https://github.com/ahwootech/BRUTAL.git
synced 2026-11-26 04:58:24 +01:00
SOURCE DUMP v1
This commit is contained in:
parent
bd62d51ec9
commit
fb20299e9d
1 changed files with 768360 additions and 0 deletions
|
|
@ -0,0 +1,62 @@
|
|||
// <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;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue