forked from ezrec/uv3dp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdecimate_test.go
103 lines (82 loc) · 1.34 KB
/
decimate_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
//
// Copyright (c) 2020 Jason S. McMullan <[email protected]>
//
package uv3dp
import (
"testing"
"bufio"
"image"
"strings"
)
var (
gm_eye = `Image
XXXXX
XX XX
X X X
XX XX
XXXXX
`
gm_eye_dec = `Box
X X
X X
`
gm_bottom = `Bottom
XXX
XXXXX
XXXXX
XXXXX
`
gm_bottom_dec = `Bottom Decimated
X
XXXXX
XXXXX
`
)
func grayFrom(desc string) (gm *image.Gray) {
reader := strings.NewReader(desc)
scanner := bufio.NewScanner(reader)
scanner.Scan()
var lines []string
stride := 0
for scanner.Scan() {
line := scanner.Text()
lines = append(lines, line)
if len(line) > stride {
stride = len(line)
}
}
pix := make([]uint8, stride*len(lines))
for y, line := range lines {
n := y * stride
for x, c := range line {
if c != ' ' {
pix[n+x] = 0xff
}
}
}
gm = &image.Gray{
Rect: image.Rect(0, 0, stride, len(lines)),
Stride: stride,
Pix: pix,
}
return
}
func TestDecimate(t *testing.T) {
table := []struct {
in string
out string
}{
{in: gm_bottom, out: gm_bottom_dec},
{in: gm_eye, out: gm_eye_dec},
}
for _, item := range table {
gm_in := grayFrom(item.in)
gm_out := grayFrom(item.out)
val := decimateGray(gm_in)
for n := 0; n < len(val.Pix); n++ {
if val.Pix[n] != gm_out.Pix[n] {
t.Fatalf("%s %d expected %#v, got %#v", item.out, n, gm_out.Pix[n], val.Pix[n])
}
}
}
}