714f2e47f7
Updates golang/go#16904 Change-Id: I4e11e4e859c007c3444655a227ac935c27f3f784 Reviewed-on: https://go-review.googlesource.com/28347 Reviewed-by: David Crawshaw <crawshaw@golang.org>
60 lines
2.5 KiB
Go
60 lines
2.5 KiB
Go
// Copyright 2016 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package vector
|
|
|
|
// TODO: add tests for NaN and Inf coordinates.
|
|
|
|
import (
|
|
"image"
|
|
"image/draw"
|
|
"testing"
|
|
|
|
"golang.org/x/image/math/f32"
|
|
)
|
|
|
|
func TestBasicPath(t *testing.T) {
|
|
want := []byte{
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
0x00, 0x00, 0xd4, 0xdd, 0xc5, 0xab, 0x63, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
0x00, 0x00, 0x9f, 0xff, 0xff, 0xff, 0xff, 0xfb, 0xb3, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
0x00, 0x00, 0x60, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf1, 0x5b, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
0x00, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x5b, 0x00, 0x00, 0x00, 0x00,
|
|
0x00, 0x00, 0x00, 0xdf, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf1, 0x20, 0x00, 0x00, 0x00,
|
|
0x00, 0x00, 0x00, 0x9f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xb3, 0x00, 0x00, 0x00,
|
|
0x00, 0x00, 0x00, 0x5f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfb, 0x12, 0x00, 0x00,
|
|
0x00, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x63, 0x00, 0x00,
|
|
0x00, 0x00, 0x00, 0x00, 0xdf, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xab, 0x00, 0x00,
|
|
0x00, 0x00, 0x00, 0x00, 0x9f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc5, 0x00, 0x00,
|
|
0x00, 0x00, 0x00, 0x00, 0x5f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xdd, 0x00, 0x00,
|
|
0x00, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf4, 0x00, 0x00,
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
}
|
|
|
|
z := NewRasterizer(16, 16)
|
|
z.MoveTo(f32.Vec2{2, 2})
|
|
z.QuadTo(f32.Vec2{14, 2}, f32.Vec2{14, 14})
|
|
z.LineTo(f32.Vec2{5, 14})
|
|
z.ClosePath()
|
|
|
|
dst := image.NewAlpha(z.Bounds())
|
|
z.DrawOp = draw.Src
|
|
z.Draw(dst, dst.Bounds(), image.Opaque, image.Point{})
|
|
|
|
got := dst.Pix
|
|
if len(got) != len(want) {
|
|
t.Fatalf("len(got)=%d and len(want)=%d differ", len(got), len(want))
|
|
}
|
|
for i := range got {
|
|
delta := int(got[i]) - int(want[i])
|
|
// The +/- 2 allows different implementations to give different
|
|
// rounding errors.
|
|
if delta < -2 || +2 < delta {
|
|
t.Errorf("i=%d: got %#02x, want %#02x", i, got[i], want[i])
|
|
}
|
|
}
|
|
}
|