func TestTraceBoth(t *testing.T) { img := genTestBitmap() bm := gtr.NewBitmapFromImage(img, gtr.ThresholdAlpha) { paths, err := Trace(bm, nil) if err != nil { t.Fatal(err) } else if len(paths) != 1 { t.Fatal("wrong paths count:", len(paths)) } else if paths[0].Sign != +1 { t.Fatal("wrong sign in path:", paths[0].Sign) } t.Log(paths) } { paths, err := Trace(bm, nil) if err != nil { t.Fatal(err) } else if len(paths) != 1 { t.Fatal("wrong paths count:", len(paths)) } else if paths[0].Sign != +1 { t.Fatal("wrong sign in path:", paths[0].Sign) } t.Log(paths) } }
func loadBitmap(t *testing.T) *gtr.Bitmap { file, err := os.Open("../../inp.png") if err != nil { t.Skip(err) } defer file.Close() img, _, err := image.Decode(file) if err != nil { t.Fatal(err) } bm := gtr.NewBitmapFromImage(img, func(x, y int, c color.Color) bool { r, _, _, _ := c.RGBA() return (float64(r)/0xffff)*0xff > 128 }) return bm }