mirror of
https://github.com/ahwootech/BRUTAL.git
synced 2026-11-26 21:18:24 +01:00
80 lines
2.9 KiB
C#
80 lines
2.9 KiB
C#
// <auto-generated /> - edit Plane.numerics.tt to modify
|
|
#nullable enable
|
|
|
|
namespace Brutal.Numerics;
|
|
|
|
public partial struct doublePlane
|
|
{
|
|
/// <inheritdoc cref="Plane.CreateFromVertices(Vector3, Vector3, Vector3)" />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static doublePlane CreateFromVertices(double3 point1, double3 point2, double3 point3)
|
|
{
|
|
var normal = double3.Normalize(double3.Cross(point2 - point1, point3 - point1));
|
|
|
|
return new doublePlane(normal, -double3.Dot(normal, point1));
|
|
}
|
|
|
|
/// <inheritdoc cref="Plane.Dot(Plane, Vector4)" />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static double Dot(doublePlane plane, double4 value)
|
|
{
|
|
return double4.Dot(plane.AsDouble4(), value);
|
|
}
|
|
|
|
/// <inheritdoc cref="Plane.DotCoordinate(Plane, Vector3)" />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static double DotCoordinate(doublePlane plane, double3 value)
|
|
{
|
|
return Dot(plane, new double4(value, 1));
|
|
}
|
|
|
|
/// <inheritdoc cref="Plane.DotNormal(Plane, Vector3)" />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static double DotNormal(doublePlane plane, double3 value)
|
|
{
|
|
return double3.Dot(plane.Normal, value);
|
|
}
|
|
|
|
/// <inheritdoc cref="Plane.Normalize(Plane)" />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static doublePlane Normalize(doublePlane value)
|
|
{
|
|
var lengthSquared = value.Normal.LengthSquared();
|
|
if (lengthSquared == double.PositiveInfinity)
|
|
return default;
|
|
|
|
var length = double.Sqrt(lengthSquared);
|
|
return new doublePlane(value.Normal / length, value.D / length);
|
|
}
|
|
|
|
/// <inheritdoc cref="Plane.Normalize(Plane)" />
|
|
/// <remarks>Returns a zero plane if the input plane is zero</remarks>
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static doublePlane NormalizeOrZero(doublePlane value)
|
|
{
|
|
var normalLengthSquared = value.Normal.LengthSquared();
|
|
if (normalLengthSquared == 0)
|
|
return new doublePlane(double3.Zero, 0);
|
|
|
|
if (normalLengthSquared == double.PositiveInfinity)
|
|
return default;
|
|
|
|
var length = double.Sqrt(normalLengthSquared);
|
|
return new doublePlane(value.Normal / length, value.D / length);
|
|
}
|
|
|
|
/// <inheritdoc cref="Plane.Transform(Plane, Matrix4x4)" />
|
|
// deliberately not AggressiveInlining, either overload: this one composes a full matrix Invert
|
|
public static doublePlane Transform(doublePlane plane, double4x4 matrix)
|
|
{
|
|
double4x4.Invert(matrix, out var inverseMatrix);
|
|
return FromDouble4(double4.Transform(plane.AsDouble4(), double4x4.Transpose(inverseMatrix)));
|
|
}
|
|
|
|
/// <inheritdoc cref="Plane.Transform(Plane, Quaternion)" />
|
|
public static doublePlane Transform(doublePlane plane, doubleQuat rotation)
|
|
{
|
|
return FromDouble4(double4.Transform(plane.AsDouble4(), rotation));
|
|
}
|
|
}
|
|
|