mirror of
https://github.com/Noratrieb/game-wip-dontplay.git
synced 2026-01-16 12:25:02 +01:00
Eliminate negative coordinates
They were making coordinate calculations more difficult, and probably slower due to having to special case negative coordinates
This commit is contained in:
parent
67b2098ffb
commit
2a2c8f721c
3 changed files with 9 additions and 53 deletions
11
src/math.rs
11
src/math.rs
|
|
@ -1,6 +1,6 @@
|
|||
use crate::world::{TilePos, TilePosScalar};
|
||||
|
||||
pub type WorldPosScalar = i32;
|
||||
pub type WorldPosScalar = u32;
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct WorldPos {
|
||||
|
|
@ -20,11 +20,7 @@ impl WorldPos {
|
|||
}
|
||||
|
||||
pub fn wp_to_tp(wp: WorldPosScalar) -> TilePosScalar {
|
||||
if wp.is_negative() {
|
||||
(wp + 1) / TILE_SIZE as TilePosScalar - 1
|
||||
} else {
|
||||
wp / TILE_SIZE as TilePosScalar
|
||||
}
|
||||
wp / TILE_SIZE as TilePosScalar
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -32,7 +28,4 @@ fn test_wp_to_tp() {
|
|||
assert_eq!(wp_to_tp(0), 0);
|
||||
assert_eq!(wp_to_tp(1), 0);
|
||||
assert_eq!(wp_to_tp(33), 1);
|
||||
assert_eq!(wp_to_tp(-1), -1);
|
||||
assert_eq!(wp_to_tp(-32), -1);
|
||||
assert_eq!(wp_to_tp(-33), -2);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue