1
2
3
4
5
6
7
8
9 package main
10
11 type Point struct {
12 X, Y int64
13 }
14
15 type Rect struct {
16 Min, Max Point
17 }
18
19 func (p Point) Sub(q Point) Point {
20 return Point{p.X-q.X, p.Y-q.Y}
21 }
22
23 type Obj struct {
24 bbox Rect
25 }
26
27 func (o *Obj) Bbox() Rect {
28 return o.bbox
29 }
30
31 func (o *Obj) Points() [2]Point{
32 return [2]Point{o.bbox.Min, o.bbox.Max}
33 }
34
35 var x = 0
36
37 func main() {
38 o := &Obj{Rect{Point{800, 0}, Point{}}}
39 p := Point{800, 300}
40 q := p.Sub(o.Bbox().Min)
41 if q.X != 0 || q.Y != 300 {
42 println("BUG dot: ", q.X, q.Y)
43 return
44 }
45
46 q = p.Sub(o.Points()[0])
47 if q.X != 0 || q.Y != 300 {
48 println("BUG index const: ", q.X, q.Y)
49 }
50
51 q = p.Sub(o.Points()[x])
52 if q.X != 0 || q.Y != 300 {
53 println("BUG index var: ", q.X, q.Y)
54 }
55 }
56
View as plain text