1
0
mirror of https://github.com/oliverbooth/VpSharp synced 2024-11-22 19:38:47 +00:00

Implement ToString for Rotation

This commit is contained in:
Oliver Booth 2022-12-08 15:55:04 +00:00
parent 6804959f93
commit ca0769faeb
No known key found for this signature in database
GPG Key ID: 32A00B35503AF634

View File

@ -1,4 +1,6 @@
using System.Numerics;
using System.Globalization;
using System.Numerics;
using Cysharp.Text;
using X10D.Math;
using X10D.Numerics;
@ -7,7 +9,7 @@ namespace VpSharp;
/// <summary>
/// Represents a rotation.
/// </summary>
public readonly struct Rotation : IEquatable<Rotation>
public readonly struct Rotation : IEquatable<Rotation>, IFormattable
{
/// <summary>
/// Represents no rotation.
@ -169,4 +171,38 @@ public readonly struct Rotation : IEquatable<Rotation>
{
return HashCode.Combine(Angle, Roll, Tilt, Yaw);
}
/// <summary>
/// Returns the string representation of these coordinates.
/// </summary>
/// <returns>A <see cref="string" /> representation of these coordinates.</returns>
public override string ToString()
{
return ToString("{0}");
}
/// <summary>
/// Returns the string representation of these coordinates.
/// </summary>
/// <param name="format">The format to apply to each component.</param>
/// <param name="formatProvider">The format provider.</param>
/// <returns>A <see cref="string" /> representation of these coordinates.</returns>
public string ToString(string? format, IFormatProvider? formatProvider = null)
{
format ??= "{0}";
string separator = NumberFormatInfo.GetInstance(formatProvider).NumberGroupSeparator;
using var builder = ZString.CreateUtf8StringBuilder();
builder.Append('<');
builder.Append(string.Format(formatProvider, format, Tilt));
builder.Append(separator);
builder.Append(' ');
builder.Append(string.Format(formatProvider, format, Yaw));
builder.Append(separator);
builder.Append(' ');
builder.Append(string.Format(formatProvider, format, Roll));
builder.Append('>');
return builder.ToString();
}
}