Fix Atlas gen with simplification

Only track lower and upper bounds in world space, and speak in terms of world space and chunks
This commit is contained in:
Marc Di Luzio 2020-07-04 22:34:28 +01:00
parent dbe944bb4e
commit 8b83672dcc
5 changed files with 240 additions and 121 deletions

View file

@ -39,3 +39,19 @@ func Min(x, y int) int {
}
return x
}
// RoundUp rounds a value up to the nearest multiple
func RoundUp(toRound int, multiple int) int {
remainder := Pmod(toRound, multiple)
if remainder == 0 {
return toRound
}
return (multiple - remainder) + toRound
}
// RoundDown rounds a value down to the nearest multiple
func RoundDown(toRound int, multiple int) int {
remainder := Pmod(toRound, multiple)
return toRound - remainder
}

View file

@ -29,5 +29,19 @@ func TestMin(t *testing.T) {
assert.Equal(t, 100, Min(100, 500))
assert.Equal(t, -4, Min(-4, 1))
assert.Equal(t, -4, Min(-4, -2))
}
func TestRoundUp(t *testing.T) {
assert.Equal(t, 10, RoundUp(10, 5))
assert.Equal(t, 12, RoundUp(10, 4))
assert.Equal(t, -8, RoundUp(-8, 4))
assert.Equal(t, -4, RoundUp(-7, 4))
}
func TestRoundDown(t *testing.T) {
assert.Equal(t, 10, RoundDown(10, 5))
assert.Equal(t, 8, RoundDown(10, 4))
assert.Equal(t, -8, RoundDown(-8, 4))
assert.Equal(t, -8, RoundDown(-7, 4))
}