fix: Adds ISpanFormattable to Geometry structs (#1231)
* Adds ISpanFormattable to geometry structs and makes ToString() near-zero-allocation. * Adds IEquatable, and Parsable to Rectangle3D to get it in-line with the other structs. Closes #1067
This commit is contained in:
parent
c75bde55da
commit
d7d914df6c
12 changed files with 721 additions and 195 deletions
|
|
@ -314,7 +314,7 @@ public static class PooledEnumeration
|
|||
}
|
||||
|
||||
[Parsable]
|
||||
public sealed class Map : IComparable<Map>
|
||||
public sealed class Map : IComparable<Map>, ISpanFormattable
|
||||
{
|
||||
public const int SectorSize = 16;
|
||||
public const int SectorShift = 4;
|
||||
|
|
@ -525,8 +525,29 @@ public sealed class Map : IComparable<Map>
|
|||
return null;
|
||||
}
|
||||
|
||||
public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format, IFormatProvider provider)
|
||||
{
|
||||
if (destination.Length >= Name.Length)
|
||||
{
|
||||
Name.CopyTo(destination);
|
||||
charsWritten = Name.Length;
|
||||
return true;
|
||||
}
|
||||
|
||||
charsWritten = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public override string ToString() => Name;
|
||||
|
||||
public string ToString(string format, IFormatProvider formatProvider)
|
||||
{
|
||||
// format and formatProvider are not doing anything right now, so use the
|
||||
// default ToString implementation.
|
||||
return ToString();
|
||||
}
|
||||
|
||||
public int GetAverageZ(int x, int y)
|
||||
{
|
||||
GetAverageZ(x, y, out _, out var avg, out _);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue