1
0
mirror of https://github.com/oliverbooth/VpSharp synced 2024-11-22 18:58:48 +00:00

Fix object query

VP's calculation for coordinate -> cell was not quite floor(n)
This commit is contained in:
Oliver Booth 2022-12-07 22:58:40 +00:00
parent 26766389ad
commit 0563e45511
No known key found for this signature in database
GPG Key ID: 32A00B35503AF634
2 changed files with 16 additions and 6 deletions

View File

@ -119,6 +119,21 @@ public readonly struct Cell : IEquatable<Cell>, IFormattable
return FromVector3d(vector); return FromVector3d(vector);
} }
/// <summary>
/// Calculates the cell number for a specified coordinate value.
/// </summary>
/// <param name="value">The coordinate value.</param>
/// <returns>The cell number.</returns>
/// <remarks>
/// The way VP calculates cell number isn't a <c>floor(n)</c> as one might have thought, but instead
/// <c>n &lt; 0 ? (int)value - 1 : (int)value</c>. This helper method exists because of this idiosyncrasy of the world
/// server.
/// </remarks>
public static int CellFromCoordinate(double value)
{
return value < 0 ? (int)value - 1 : (int)value;
}
/// <summary> /// <summary>
/// Converts an instance of <see cref="Vector2" /> to a new instance of <see cref="Cell" />. /// Converts an instance of <see cref="Vector2" /> to a new instance of <see cref="Cell" />.
/// </summary> /// </summary>

View File

@ -51,12 +51,7 @@ public readonly struct Location : IEquatable<Location>
/// </summary> /// </summary>
public Cell Cell public Cell Cell
{ {
get get => new(Cell.CellFromCoordinate(Position.X), Cell.CellFromCoordinate(Position.Z));
{
var x = (int)Math.Floor(Position.X);
var z = (int)Math.Floor(Position.Z);
return new Cell(x, z);
}
} }
/// <summary> /// <summary>