-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathdraw_test.go
More file actions
214 lines (170 loc) · 6.16 KB
/
Copy pathdraw_test.go
File metadata and controls
214 lines (170 loc) · 6.16 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
//go:build !tinygo
package gfx
import "testing"
func TestDrawOver(t *testing.T) {
src := NewImage(3, 3)
src.SetRGBA(1, 1, ColorRGBA(75, 0, 130, 64))
dst := NewImage(3, 3, ColorMagenta)
DrawOver(dst, dst.Bounds(), src, ZP)
}
func TestDrawSrc(t *testing.T) {
src := NewImage(3, 3, ColorRGBA(0, 255, 0, 64))
dst := NewImage(3, 3, ColorMagenta)
DrawSrc(dst, dst.Bounds(), src, ZP)
}
func TestDrawOverPalettedImage(t *testing.T) {
src := newTestLayer()
dst := NewPaletted(8, 16, PaletteEN4)
DrawPalettedImage(dst, dst.Bounds(), src)
}
func TestDrawLayerOverPaletted(t *testing.T) {
src := newTestLayer()
dst := NewPaletted(8, 16, PaletteEN4)
DrawPalettedLayer(dst, dst.Bounds(), src)
}
func TestDrawPalettedImageNonOriginRect(t *testing.T) {
src := NewPaletted(8, 16, PaletteEN4)
for i := range src.Pix {
src.Pix[i] = 1
}
dst := NewPaletted(8, 16, PaletteEN4)
r := IR(2, 4, 6, 10)
DrawPalettedImage(dst, r, src)
for y := range 16 {
for x := range 8 {
inside := x >= r.Min.X && x < r.Max.X && y >= r.Min.Y && y < r.Max.Y
got := dst.ColorIndexAt(x, y)
want := uint8(0)
if inside {
want = 1
}
if got != want {
t.Fatalf("dst.ColorIndexAt(%d, %d) = %d, want %d (inside=%v)", x, y, got, want, inside)
}
}
}
}
func TestDrawPalettedLayerNonOriginRect(t *testing.T) {
src := newTestLayer()
dst := NewPaletted(16, 12, PaletteEN4)
r := IR(4, 4, 12, 8)
DrawPalettedLayer(dst, r, src)
for y := range 12 {
for x := range 16 {
inside := x >= r.Min.X && x < r.Max.X && y >= r.Min.Y && y < r.Max.Y
got := dst.ColorIndexAt(x, y)
if inside {
if want := src.ColorIndexAt(x, y); got != want {
t.Fatalf("dst.ColorIndexAt(%d, %d) = %d, want %d (from src)", x, y, got, want)
}
} else if got != 0 {
t.Fatalf("dst.ColorIndexAt(%d, %d) = %d, want 0 (outside r)", x, y, got)
}
}
}
}
func TestDrawLine(t *testing.T) {
dst := NewImage(32, 32)
DrawLine(dst, V(4, 4), V(24, 12), 2, ColorBlue)
DrawLine(dst, V(4, 4), V(24, 12), 1, ColorGreen)
}
func TestDrawColor(t *testing.T) {
dst := NewImage(32, 32)
DrawColor(dst, IR(5, 5, 15, 20), ColorGreen)
}
func TestDrawPolygon(t *testing.T) {
dst := NewImage(32, 32, ColorBlack)
p := Polygon{
{0, 0},
{20, 2},
{25, 20},
{10, 15},
}
DrawPolygon(dst, p, 0, ColorMagenta)
DrawPolygon(dst, p, 1, ColorYellow)
}
func TestDrawPolyline(t *testing.T) {
dst := NewImage(32, 32, ColorBlack)
DrawPolyline(dst, Polyline{
{{0, 0}, {10, 0}, {10, 10}},
{{10, 10}, {20, 8}, {25, 20}},
}, 0, ColorMagenta)
}
func TestDrawCircle(t *testing.T) {
dst := NewImage(32, 32)
DrawCircle(dst, V(16, 16), 12, 0, ColorMagenta)
DrawCircle(dst, V(16, 16), 8, 2, ColorYellow)
}
func TestDrawFilledCircle(t *testing.T) {
dst := NewImage(32, 32)
DrawCircleFilled(dst, V(16, 16), 8, ColorMagenta)
}
func TestDrawCircleFast(t *testing.T) {
dst := NewImage(32, 32)
DrawCircleFast(dst, V(16, 16), 8, ColorMagenta)
}
func TestDrawPointCircle(t *testing.T) {
dst := NewImage(32, 32)
DrawPointCircle(dst, Pt(16, 16), 16, 0, ColorMagenta)
DrawPointCircle(dst, Pt(16, 16), 8, 4, ColorYellow)
}
func ExampleDrawCircle_filled() {
dst := NewPaletted(15, 13, Palette1Bit, ColorWhite)
DrawCircle(dst, V(7, 6), 6, 0, ColorBlack)
for y := 0; y < dst.Bounds().Dy(); y++ {
for x := 0; x < dst.Bounds().Dx(); x++ {
if dst.Index(x, y) == 0 {
Printf("▓▓")
} else {
Printf("░░")
}
}
Printf("\n")
}
// Output:
//
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
// ░░░░░░░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░
// ░░░░░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░
// ░░░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░
// ░░░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░
// ░░░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░
// ░░░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░
// ░░░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░
// ░░░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░
// ░░░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░
// ░░░░░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░
// ░░░░░░░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
//
}
func ExampleDrawCircle_annular() {
dst := NewPaletted(15, 13, Palette1Bit, ColorWhite)
DrawCircle(dst, V(7, 6), 6, 3, ColorBlack)
for y := 0; y < dst.Bounds().Dy(); y++ {
for x := 0; x < dst.Bounds().Dx(); x++ {
if dst.Index(x, y) == 0 {
Printf("▓▓")
} else {
Printf("░░")
}
}
Printf("\n")
}
// Output:
//
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
// ░░░░░░░░░░▓▓▓▓▓▓▓▓▓▓░░░░░░░░░░
// ░░░░░░░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░
// ░░░░░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░
// ░░░░▓▓▓▓▓▓▓▓░░░░░░▓▓▓▓▓▓▓▓░░░░
// ░░░░▓▓▓▓▓▓░░░░░░░░░░▓▓▓▓▓▓░░░░
// ░░░░▓▓▓▓▓▓░░░░░░░░░░▓▓▓▓▓▓░░░░
// ░░░░▓▓▓▓▓▓░░░░░░░░░░▓▓▓▓▓▓░░░░
// ░░░░▓▓▓▓▓▓▓▓░░░░░░▓▓▓▓▓▓▓▓░░░░
// ░░░░░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░
// ░░░░░░░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░
// ░░░░░░░░░░▓▓▓▓▓▓▓▓▓▓░░░░░░░░░░
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
//
}