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

149 lines
5.2 KiB
C#

// <auto-generated /> - edit Plane.tt to modify
#nullable enable
namespace Brutal.Numerics;
/// <summary>
/// Represents a plane in three-dimensional space, with float components.
/// </summary>
[DebuggerTypeProxy(typeof(PlaneDebugView<floatPlane, float3, float>))]
public partial struct floatPlane : IPlane<floatPlane, float3, float>
{
/// <inheritdoc />
public float3 Normal { get; set; }
/// <inheritdoc />
public float D { get; set; }
/// <inheritdoc cref="Plane(float, float, float, float)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public floatPlane(float x, float y, float z, float d)
{
Normal = new float3(x, y, z);
D = d;
}
/// <inheritdoc cref="Plane(Vector3, float)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public floatPlane(float3 normal, float d)
{
Normal = normal;
D = d;
}
/// <inheritdoc cref="Plane(Vector4)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public floatPlane(float4 value)
{
Normal = value.XYZ;
D = value.W;
}
/// <summary>A mutable view over the 4 components: normal xyz, then d.</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<floatPlane, 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<floatPlane, float>(ref Unsafe.AsRef(in this)), 4);
}
/// <summary>Construct a plane of this type from the leading 4 elements of a span (normal xyz, then d).</summary>
/// <param name="span">The elements to read; must contain at least 4, and any beyond that are ignored.</param>
/// <exception cref="ArgumentOutOfRangeException"><paramref name="span" /> holds fewer than 4 elements.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public floatPlane(ReadOnlySpan<float> span)
{
if (span.Length < 4)
throw new ArgumentOutOfRangeException(nameof(span), "Length must be at least 4.");
this = Unsafe.ReadUnaligned<floatPlane>(ref Unsafe.As<float, byte>(ref MemoryMarshal.GetReference(span)));
}
/// <summary>Construct a plane of this type from a span (normal xyz, then d).</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static floatPlane IPlane<floatPlane, float3, float>.Create(ReadOnlySpan<float> span) => new(span);
}
// Operators
public partial struct floatPlane
{
/// <inheritdoc cref="Plane.op_Equality(Plane, Plane)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator ==(floatPlane a, floatPlane b)
{
// IEEE like the vector ==; Equals stays NaN-reflexive (see Vector.equality.tt)
return a.Normal == b.Normal && a.D == b.D;
}
/// <inheritdoc cref="Plane.op_Inequality(Plane, Plane)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator !=(floatPlane a, floatPlane b)
{
return !(a == b);
}
}
// IEquatable
public partial struct floatPlane
{
/// <inheritdoc cref="Plane.Equals(object?)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override readonly bool Equals([NotNullWhen(true)] object? obj)
{
return obj is floatPlane other && Equals(other);
}
/// <inheritdoc cref="Plane.Equals(Plane)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly bool Equals(floatPlane other)
{
return Normal.Equals(other.Normal) && D.Equals(other.D);
}
/// <inheritdoc cref="Plane.GetHashCode" />
public readonly override int GetHashCode()
{
return HashCode.Combine(Normal, D);
}
}
// String
public partial struct floatPlane
{
/// <inheritdoc cref="Plane.ToString" />
public readonly override string ToString()
{
return $"{{ Normal:{Normal} D:{D} }}";
}
/// <inheritdoc />
public readonly string ToString(string? format, IFormatProvider? formatProvider)
{
return $"{{ Normal:{Normal.ToString(format, formatProvider)} D:{D.ToString(format, formatProvider)} }}";
}
/// <summary>Reinterpret as the matching vector4 - xyz+d in the same order.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private readonly float4 AsFloat4()
{
return Unsafe.BitCast<floatPlane, float4>(this);
}
/// <summary>Reinterpret a vector4 as a plane.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static floatPlane FromFloat4(float4 value)
{
return Unsafe.BitCast<float4, floatPlane>(value);
}
}