Files
RobustToolbox/Robust.Shared/Map/MapIndices.cs
T
AcruidandPieter-Jan Briers 1b3cc8aba6 Grid Bounds (#800)
* Added centered unit box static field to Box2.

* MapGrid is more testable.

* Added some unit tests for MapGrid.
Fixed bug in MapChunk.GridTileToLocal().
MapGrid.UpdateAABB() actually expands properly now.

* Moved IMapChunk to Robust.Shared.Map.
Moved Chunk class out of MapManager class.

* Added unit tests for MapChunk.

* Bounds reduce by 1, so almost working.

* Now bound shrinking works :D

* Moved MapGrid out of MapManager.
Moved IMapGrid into the Shared/Map folder.
Replaced all calls to IMapGrid.ParentMap.Index with IMapGrid.ParentMapId.

* Added more MapGrid unit tests.
Fixed a bug in TryGetTileRef.
2019-04-29 12:43:20 +02:00

103 lines
2.8 KiB
C#

using System;
using JetBrains.Annotations;
using Robust.Shared.Maths;
using Robust.Shared.Serialization;
namespace Robust.Shared.Map
{
/// <summary>
/// Internal structure to store 2 indices of a chunk or tile.
/// </summary>
[PublicAPI]
[Serializable, NetSerializable]
public readonly struct MapIndices : IEquatable<MapIndices>
{
/// <summary>
/// The <see cref="X" /> index.
/// </summary>
public readonly int X;
/// <summary>
/// The <see cref="Y" /> index.
/// </summary>
public readonly int Y;
/// <summary>
/// Public constructor.
/// </summary>
/// <param name="x">The <see cref="X" /> index.</param>
/// <param name="y">The <see cref="Y" /> index.</param>
public MapIndices(int x, int y)
{
X = x;
Y = y;
}
/// <summary>
/// Translates the indices by a given offset.
/// </summary>
public static MapIndices operator +(MapIndices left, MapIndices right)
{
return new MapIndices(left.X + right.X, left.Y + right.Y);
}
/// <summary>
/// Scales the <paramref name="indices" /> by a scalar amount.
/// </summary>
public static MapIndices operator *(MapIndices indices, int multiplier)
{
return new MapIndices(indices.X * multiplier, indices.Y * multiplier);
}
/// <summary>
/// Tests for value equality between two LocalCoordinates.
/// </summary>
public static bool operator ==(MapIndices a, MapIndices b)
{
return a.Equals(b);
}
/// <summary>
/// Tests for value inequality between two LocalCoordinates.
/// </summary>
public static bool operator !=(MapIndices a, MapIndices b)
{
return !a.Equals(b);
}
/// <inheritdoc />
public override bool Equals(object obj)
{
return obj is MapIndices idx && Equals(idx);
}
/// <inheritdoc />
public bool Equals(MapIndices other)
{
return other.X == X && other.Y == Y;
}
/// <inheritdoc />
public override string ToString()
{
return $"{{{X},{Y}}}";
}
/// <inheritdoc />
public override int GetHashCode()
{
return X ^ (Y * 23011);
}
public static implicit operator Vector2i(in MapIndices indices)
{
return new Vector2i(indices.X, indices.Y);
}
public static implicit operator MapIndices(in Vector2i indices)
{
return new MapIndices(indices.X, indices.Y);
}
}
}