position is now center, socket improvements
This commit is contained in:
parent
40eba7a7c7
commit
d4d0abd013
1 changed files with 129 additions and 101 deletions
|
|
@ -10,8 +10,8 @@ internal static class PositionHelpers
|
|||
Debug.Assert(subX < 8);
|
||||
Debug.Assert(subY < 8);
|
||||
return new PixelPosition(
|
||||
x: (ushort)(position.X * MapService.TileSize + subX),
|
||||
y: (ushort)(position.Y * MapService.TileSize + subY)
|
||||
(ushort)(position.X * MapService.TileSize + subX),
|
||||
(ushort)(position.Y * MapService.TileSize + subY)
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -23,21 +23,26 @@ internal static class PositionHelpers
|
|||
}
|
||||
|
||||
public static PixelPosition ToPixelPosition(this FloatPosition position) => new(
|
||||
x: (ushort)((int)position.X % MapService.PixelsPerRow),
|
||||
y: (ushort)((int)position.Y % MapService.PixelsPerRow)
|
||||
(ushort)((int)position.X % MapService.PixelsPerRow),
|
||||
(ushort)((int)position.Y % MapService.PixelsPerRow)
|
||||
);
|
||||
|
||||
public static PixelPosition ToPixelPosition(this TilePosition position) => new(
|
||||
(ushort)(position.X * MapService.TileSize),
|
||||
(ushort)(position.Y * MapService.TileSize)
|
||||
);
|
||||
|
||||
public static TilePosition ToTilePosition(this PixelPosition position) => new(
|
||||
x: (ushort)(position.X / MapService.TileSize),
|
||||
y: (ushort)(position.Y / MapService.TileSize)
|
||||
(ushort)(position.X / MapService.TileSize),
|
||||
(ushort)(position.Y / MapService.TileSize)
|
||||
);
|
||||
|
||||
public static FloatPosition ToFloatPosition(this PixelPosition position) => new(position.X, position.Y);
|
||||
|
||||
|
||||
public static double Distance(this FloatPosition p1, FloatPosition p2)
|
||||
=> Math.Sqrt(
|
||||
public static double Distance(this FloatPosition p1, FloatPosition p2) =>
|
||||
Math.Sqrt(
|
||||
Math.Pow(p1.X - p2.X, 2) +
|
||||
Math.Pow(p1.Y - p2.Y, 2)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue