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:
parent
26766389ad
commit
0563e45511
@ -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 < 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>
|
||||||
|
@ -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>
|
||||||
|
Loading…
Reference in New Issue
Block a user