go vet fixes
This commit is contained in:
parent
fb6189e246
commit
bb793d237f
3 changed files with 61 additions and 19 deletions
10
arc.go
10
arc.go
|
@ -35,7 +35,6 @@ func arc(t VertexConverter, x, y, rx, ry, start, angle, scale float64) (lastX, l
|
|||
angle += da
|
||||
t.Vertex(curX, curY)
|
||||
}
|
||||
return curX, curY
|
||||
}
|
||||
|
||||
func arcAdder(adder raster.Adder, x, y, rx, ry, start, angle, scale float64) raster.Point {
|
||||
|
@ -56,13 +55,16 @@ func arcAdder(adder raster.Adder, x, y, rx, ry, start, angle, scale float64) ras
|
|||
if (angle < end-da/4) != clockWise {
|
||||
curX = x + math.Cos(end)*rx
|
||||
curY = y + math.Sin(end)*ry
|
||||
return raster.Point{raster.Fix32(curX * 256), raster.Fix32(curY * 256)}
|
||||
return raster.Point{
|
||||
X: raster.Fix32(curX * 256),
|
||||
Y: raster.Fix32(curY * 256)}
|
||||
}
|
||||
curX = x + math.Cos(angle)*rx
|
||||
curY = y + math.Sin(angle)*ry
|
||||
|
||||
angle += da
|
||||
adder.Add1(raster.Point{raster.Fix32(curX * 256), raster.Fix32(curY * 256)})
|
||||
adder.Add1(raster.Point{
|
||||
X: raster.Fix32(curX * 256),
|
||||
Y: raster.Fix32(curY * 256)})
|
||||
}
|
||||
return raster.Point{raster.Fix32(curX * 256), raster.Fix32(curY * 256)}
|
||||
}
|
||||
|
|
|
@ -23,9 +23,13 @@ func (vertexAdder *VertexAdder) NextCommand(cmd VertexCommand) {
|
|||
func (vertexAdder *VertexAdder) Vertex(x, y float64) {
|
||||
switch vertexAdder.command {
|
||||
case VertexStartCommand:
|
||||
vertexAdder.adder.Start(raster.Point{raster.Fix32(x * 256), raster.Fix32(y * 256)})
|
||||
vertexAdder.adder.Start(raster.Point{
|
||||
X: raster.Fix32(x * 256),
|
||||
Y: raster.Fix32(y * 256)})
|
||||
default:
|
||||
vertexAdder.adder.Add1(raster.Point{raster.Fix32(x * 256), raster.Fix32(y * 256)})
|
||||
vertexAdder.adder.Add1(raster.Point{
|
||||
X: raster.Fix32(x * 256),
|
||||
Y: raster.Fix32(y * 256)})
|
||||
}
|
||||
vertexAdder.command = VertexNoCommand
|
||||
}
|
||||
|
@ -37,7 +41,7 @@ type PathAdder struct {
|
|||
}
|
||||
|
||||
func NewPathAdder(adder raster.Adder) *PathAdder {
|
||||
return &PathAdder{adder, raster.Point{0, 0}, 1}
|
||||
return &PathAdder{adder, raster.Point{X: 0, Y: 0}, 1}
|
||||
}
|
||||
|
||||
func (pathAdder *PathAdder) Convert(paths ...*PathStorage) {
|
||||
|
@ -46,17 +50,36 @@ func (pathAdder *PathAdder) Convert(paths ...*PathStorage) {
|
|||
for _, cmd := range path.Commands {
|
||||
switch cmd {
|
||||
case MoveTo:
|
||||
pathAdder.firstPoint = raster.Point{raster.Fix32(path.Vertices[j] * 256), raster.Fix32(path.Vertices[j+1] * 256)}
|
||||
pathAdder.firstPoint = raster.Point{
|
||||
X: raster.Fix32(path.Vertices[j] * 256),
|
||||
Y: raster.Fix32(path.Vertices[j+1] * 256)}
|
||||
pathAdder.adder.Start(pathAdder.firstPoint)
|
||||
j += 2
|
||||
case LineTo:
|
||||
pathAdder.adder.Add1(raster.Point{raster.Fix32(path.Vertices[j] * 256), raster.Fix32(path.Vertices[j+1] * 256)})
|
||||
pathAdder.adder.Add1(raster.Point{
|
||||
X: raster.Fix32(path.Vertices[j] * 256),
|
||||
Y: raster.Fix32(path.Vertices[j+1] * 256)})
|
||||
j += 2
|
||||
case QuadCurveTo:
|
||||
pathAdder.adder.Add2(raster.Point{raster.Fix32(path.Vertices[j] * 256), raster.Fix32(path.Vertices[j+1] * 256)}, raster.Point{raster.Fix32(path.Vertices[j+2] * 256), raster.Fix32(path.Vertices[j+3] * 256)})
|
||||
pathAdder.adder.Add2(
|
||||
raster.Point{
|
||||
X: raster.Fix32(path.Vertices[j] * 256),
|
||||
Y: raster.Fix32(path.Vertices[j+1] * 256)},
|
||||
raster.Point{
|
||||
X: raster.Fix32(path.Vertices[j+2] * 256),
|
||||
Y: raster.Fix32(path.Vertices[j+3] * 256)})
|
||||
j += 4
|
||||
case CubicCurveTo:
|
||||
pathAdder.adder.Add3(raster.Point{raster.Fix32(path.Vertices[j] * 256), raster.Fix32(path.Vertices[j+1] * 256)}, raster.Point{raster.Fix32(path.Vertices[j+2] * 256), raster.Fix32(path.Vertices[j+3] * 256)}, raster.Point{raster.Fix32(path.Vertices[j+4] * 256), raster.Fix32(path.Vertices[j+5] * 256)})
|
||||
pathAdder.adder.Add3(
|
||||
raster.Point{
|
||||
X: raster.Fix32(path.Vertices[j] * 256),
|
||||
Y: raster.Fix32(path.Vertices[j+1] * 256)},
|
||||
raster.Point{
|
||||
X: raster.Fix32(path.Vertices[j+2] * 256),
|
||||
Y: raster.Fix32(path.Vertices[j+3] * 256)},
|
||||
raster.Point{
|
||||
X: raster.Fix32(path.Vertices[j+4] * 256),
|
||||
Y: raster.Fix32(path.Vertices[j+5] * 256)})
|
||||
j += 6
|
||||
case ArcTo:
|
||||
lastPoint := arcAdder(pathAdder.adder, path.Vertices[j], path.Vertices[j+1], path.Vertices[j+2], path.Vertices[j+3], path.Vertices[j+4], path.Vertices[j+5], pathAdder.ApproximationScale)
|
||||
|
|
|
@ -62,9 +62,13 @@ func TestFreetype(t *testing.T) {
|
|||
img := image.NewRGBA(image.Rect(0, 0, 200, 200))
|
||||
rasterizer := raster.NewRasterizer(200, 200)
|
||||
rasterizer.UseNonZeroWinding = false
|
||||
rasterizer.Start(raster.Point{raster.Fix32(10 * 256), raster.Fix32(190 * 256)})
|
||||
rasterizer.Start(raster.Point{
|
||||
X: raster.Fix32(10 * 256),
|
||||
Y: raster.Fix32(190 * 256)})
|
||||
for j := 0; j < len(poly); j = j + 2 {
|
||||
rasterizer.Add1(raster.Point{raster.Fix32(poly[j] * 256), raster.Fix32(poly[j+1] * 256)})
|
||||
rasterizer.Add1(raster.Point{
|
||||
X: raster.Fix32(poly[j] * 256),
|
||||
Y: raster.Fix32(poly[j+1] * 256)})
|
||||
}
|
||||
painter := raster.NewRGBAPainter(img)
|
||||
painter.SetColor(color)
|
||||
|
@ -84,9 +88,13 @@ func TestFreetypeNonZeroWinding(t *testing.T) {
|
|||
img := image.NewRGBA(image.Rect(0, 0, 200, 200))
|
||||
rasterizer := raster.NewRasterizer(200, 200)
|
||||
rasterizer.UseNonZeroWinding = true
|
||||
rasterizer.Start(raster.Point{raster.Fix32(10 * 256), raster.Fix32(190 * 256)})
|
||||
rasterizer.Start(raster.Point{
|
||||
X: raster.Fix32(10 * 256),
|
||||
Y: raster.Fix32(190 * 256)})
|
||||
for j := 0; j < len(poly); j = j + 2 {
|
||||
rasterizer.Add1(raster.Point{raster.Fix32(poly[j] * 256), raster.Fix32(poly[j+1] * 256)})
|
||||
rasterizer.Add1(raster.Point{
|
||||
X: raster.Fix32(poly[j] * 256),
|
||||
Y: raster.Fix32(poly[j+1] * 256)})
|
||||
}
|
||||
painter := raster.NewRGBAPainter(img)
|
||||
painter.SetColor(color)
|
||||
|
@ -139,15 +147,20 @@ func BenchmarkFreetype(b *testing.B) {
|
|||
img := image.NewRGBA(image.Rect(0, 0, 200, 200))
|
||||
rasterizer := raster.NewRasterizer(200, 200)
|
||||
rasterizer.UseNonZeroWinding = false
|
||||
rasterizer.Start(raster.Point{raster.Fix32(10 * 256), raster.Fix32(190 * 256)})
|
||||
rasterizer.Start(raster.Point{
|
||||
X: raster.Fix32(10 * 256),
|
||||
Y: raster.Fix32(190 * 256)})
|
||||
for j := 0; j < len(poly); j = j + 2 {
|
||||
rasterizer.Add1(raster.Point{raster.Fix32(poly[j] * 256), raster.Fix32(poly[j+1] * 256)})
|
||||
rasterizer.Add1(raster.Point{
|
||||
X: raster.Fix32(poly[j] * 256),
|
||||
Y: raster.Fix32(poly[j+1] * 256)})
|
||||
}
|
||||
painter := raster.NewRGBAPainter(img)
|
||||
painter.SetColor(color)
|
||||
rasterizer.Rasterize(painter)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkFreetypeNonZeroWinding(b *testing.B) {
|
||||
var p Path
|
||||
p.LineTo(10, 190)
|
||||
|
@ -160,9 +173,13 @@ func BenchmarkFreetypeNonZeroWinding(b *testing.B) {
|
|||
img := image.NewRGBA(image.Rect(0, 0, 200, 200))
|
||||
rasterizer := raster.NewRasterizer(200, 200)
|
||||
rasterizer.UseNonZeroWinding = true
|
||||
rasterizer.Start(raster.Point{raster.Fix32(10 * 256), raster.Fix32(190 * 256)})
|
||||
rasterizer.Start(raster.Point{
|
||||
X: raster.Fix32(10 * 256),
|
||||
Y: raster.Fix32(190 * 256)})
|
||||
for j := 0; j < len(poly); j = j + 2 {
|
||||
rasterizer.Add1(raster.Point{raster.Fix32(poly[j] * 256), raster.Fix32(poly[j+1] * 256)})
|
||||
rasterizer.Add1(raster.Point{
|
||||
X: raster.Fix32(poly[j] * 256),
|
||||
Y: raster.Fix32(poly[j+1] * 256)})
|
||||
}
|
||||
painter := raster.NewRGBAPainter(img)
|
||||
painter.SetColor(color)
|
||||
|
|
Loading…
Reference in a new issue