mirror of
https://bitbucket.org/s_l_teichmann/mtsatellite
synced 2024-11-08 11:10:27 +01:00
Some code cleanup in unit test for bit version of BigMin. Test is still failing.
This commit is contained in:
parent
234b487077
commit
f75e1015af
|
@ -250,33 +250,34 @@ func NaiveBigMin(minz, maxz, zcode int64) int64 {
|
|||
}
|
||||
|
||||
const (
|
||||
bits = 12
|
||||
msb = uint(3*bits - 1)
|
||||
_000_ = 0
|
||||
_001_ = 1
|
||||
_010_ = 2
|
||||
_011_ = 2 | 1
|
||||
_100_ = 4
|
||||
_101_ = 4 | 1
|
||||
mask = int64(0x924924924924924)
|
||||
full = int64(0xfffffffffffffff)
|
||||
bits = 12
|
||||
msb = uint8(3*bits - 1)
|
||||
mask = int64(0x924924924924924)
|
||||
full = int64(0xfffffffffffffff)
|
||||
)
|
||||
|
||||
func setbits(p uint, v int64) int64 {
|
||||
func setbits(p uint8, v int64) int64 {
|
||||
m := (mask >> (msb - p)) & (^(full << p) & full)
|
||||
return (v | m) & ^(1 << p) & full
|
||||
}
|
||||
|
||||
func unsetbits(p uint, v int64) int64 {
|
||||
func unsetbits(p uint8, v int64) int64 {
|
||||
m := ^(mask >> (msb - p)) & full
|
||||
return (v & m) | (int64(1) << p)
|
||||
}
|
||||
|
||||
func BigMin(minz, maxz, zcode int64) int64 {
|
||||
const (
|
||||
_001_ = 1
|
||||
_010_ = 2
|
||||
_011_ = 2 | 1
|
||||
_100_ = 4
|
||||
_101_ = 4 | 1
|
||||
)
|
||||
bigmin := maxz
|
||||
pos := msb
|
||||
for m := int64(1) << msb; m != 0; m >>= 1 {
|
||||
var v uint16
|
||||
var v uint8
|
||||
if zcode&m != 0 {
|
||||
v = _100_
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
package common
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"testing"
|
||||
)
|
||||
|
@ -161,9 +160,9 @@ func TestBigMin(t *testing.T) {
|
|||
x1 := rand.Intn(4000) - 2000
|
||||
y1 := rand.Intn(4000) - 2000
|
||||
z1 := rand.Intn(4000) - 2000
|
||||
w := rand.Intn(20) + 1
|
||||
h := rand.Intn(20) + 1
|
||||
d := rand.Intn(20) + 1
|
||||
w := rand.Intn(18) + 1
|
||||
h := rand.Intn(18) + 1
|
||||
d := rand.Intn(18) + 1
|
||||
x2 := x1 + w
|
||||
y2 := y1 + h
|
||||
z2 := z1 + d
|
||||
|
@ -171,20 +170,19 @@ func TestBigMin(t *testing.T) {
|
|||
c1 := Coord{X: int16(x1), Y: int16(y1), Z: int16(z1)}
|
||||
c2 := Coord{X: int16(x2), Y: int16(y2), Z: int16(z2)}
|
||||
cub := Cuboid{P1: c1, P2: c2}
|
||||
fmt.Printf("Cuboid: %s\n", cub)
|
||||
//fmt.Printf("Cuboid: %s\n", cub)
|
||||
|
||||
zmin := CoordToInterleaved(c1)
|
||||
zmax := CoordToInterleaved(c2)
|
||||
|
||||
for zcode := zmin + 1; zcode < zmax; zcode++ {
|
||||
c3 := InterleavedToCoord(zcode)
|
||||
if cub.Contains(c3) {
|
||||
if cub.Contains(InterleavedToCoord(zcode)) {
|
||||
continue
|
||||
}
|
||||
nbm := NaiveBigMin(zmin, zmax, zcode)
|
||||
cbm := BigMin(zmin, zmax, zcode)
|
||||
//fmt.Printf("cbm: %d\n", cbm)
|
||||
//fmt.Printf("nbm: %d\n", nbm)
|
||||
//fmt.Printf("nbm: %b\n", nbm)
|
||||
//fmt.Printf("cbm: %b\n", cbm)
|
||||
if nbm != cbm {
|
||||
errors++
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue
Block a user