Merge pull request #57 from stanim/stani

Fix go vet issues
This commit is contained in:
Stani 2015-07-10 16:01:04 +02:00
commit d4e1581526
8 changed files with 79 additions and 21 deletions

10
arc.go
View file

@ -35,7 +35,6 @@ func arc(t VertexConverter, x, y, rx, ry, start, angle, scale float64) (lastX, l
angle += da angle += da
t.Vertex(curX, curY) t.Vertex(curX, curY)
} }
return curX, curY
} }
func arcAdder(adder raster.Adder, x, y, rx, ry, start, angle, scale float64) raster.Point { 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 { if (angle < end-da/4) != clockWise {
curX = x + math.Cos(end)*rx curX = x + math.Cos(end)*rx
curY = y + math.Sin(end)*ry 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 curX = x + math.Cos(angle)*rx
curY = y + math.Sin(angle)*ry curY = y + math.Sin(angle)*ry
angle += da 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)}
} }

View file

@ -1,3 +1,6 @@
// Copyright 2015 The draw2d Authors. All rights reserved.
// created: 26/06/2015 by Stani Michiels
package draw2dpdf package draw2dpdf
import "github.com/jung-kurt/gofpdf" import "github.com/jung-kurt/gofpdf"

View file

@ -1,6 +1,6 @@
// Copyright 2015 The draw2d Authors. All rights reserved. // Copyright 2015 The draw2d Authors. All rights reserved.
// created: 26/06/2015 by Stani Michiels // created: 26/06/2015 by Stani Michiels
// TODO: fonts, dpi // TODO: dashed line
package draw2dpdf package draw2dpdf
@ -88,7 +88,7 @@ func NewGraphicContext(pdf *gofpdf.Fpdf) *GraphicContext {
// TODO: add type (tp) as parameter to argument list? // TODO: add type (tp) as parameter to argument list?
func (gc *GraphicContext) DrawImage(image image.Image) { func (gc *GraphicContext) DrawImage(image image.Image) {
name := strconv.Itoa(int(imageCount)) name := strconv.Itoa(int(imageCount))
imageCount += 1 imageCount++
tp := "PNG" // "JPG", "JPEG", "PNG" and "GIF" tp := "PNG" // "JPG", "JPEG", "PNG" and "GIF"
b := &bytes.Buffer{} b := &bytes.Buffer{}
png.Encode(b, image) png.Encode(b, image)

View file

@ -1,3 +1,5 @@
// Copyright 2015 The draw2d Authors. All rights reserved.
// created: 26/06/2015 by Stani Michiels
// See also test_test.go // See also test_test.go
package draw2dpdf_test package draw2dpdf_test

View file

@ -1,3 +1,6 @@
// Copyright 2015 The draw2d Authors. All rights reserved.
// created: 26/06/2015 by Stani Michiels
// Package draw2dpdf_test gives test coverage with the command: // Package draw2dpdf_test gives test coverage with the command:
// go test -cover ./... | grep -v "no test" // go test -cover ./... | grep -v "no test"
// (It should be run from its parent draw2d directory.) // (It should be run from its parent draw2d directory.)

View file

@ -23,9 +23,13 @@ func (vertexAdder *VertexAdder) NextCommand(cmd VertexCommand) {
func (vertexAdder *VertexAdder) Vertex(x, y float64) { func (vertexAdder *VertexAdder) Vertex(x, y float64) {
switch vertexAdder.command { switch vertexAdder.command {
case VertexStartCommand: 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: 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 vertexAdder.command = VertexNoCommand
} }
@ -37,7 +41,7 @@ type PathAdder struct {
} }
func NewPathAdder(adder raster.Adder) *PathAdder { 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) { func (pathAdder *PathAdder) Convert(paths ...*PathStorage) {
@ -46,17 +50,36 @@ func (pathAdder *PathAdder) Convert(paths ...*PathStorage) {
for _, cmd := range path.Commands { for _, cmd := range path.Commands {
switch cmd { switch cmd {
case MoveTo: 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) pathAdder.adder.Start(pathAdder.firstPoint)
j += 2 j += 2
case LineTo: 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 j += 2
case QuadCurveTo: 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 j += 4
case CubicCurveTo: 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 j += 6
case ArcTo: 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) 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)

View file

@ -62,9 +62,13 @@ func TestFreetype(t *testing.T) {
img := image.NewRGBA(image.Rect(0, 0, 200, 200)) img := image.NewRGBA(image.Rect(0, 0, 200, 200))
rasterizer := raster.NewRasterizer(200, 200) rasterizer := raster.NewRasterizer(200, 200)
rasterizer.UseNonZeroWinding = false 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 { 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 := raster.NewRGBAPainter(img)
painter.SetColor(color) painter.SetColor(color)
@ -84,9 +88,13 @@ func TestFreetypeNonZeroWinding(t *testing.T) {
img := image.NewRGBA(image.Rect(0, 0, 200, 200)) img := image.NewRGBA(image.Rect(0, 0, 200, 200))
rasterizer := raster.NewRasterizer(200, 200) rasterizer := raster.NewRasterizer(200, 200)
rasterizer.UseNonZeroWinding = true 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 { 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 := raster.NewRGBAPainter(img)
painter.SetColor(color) painter.SetColor(color)
@ -139,15 +147,20 @@ func BenchmarkFreetype(b *testing.B) {
img := image.NewRGBA(image.Rect(0, 0, 200, 200)) img := image.NewRGBA(image.Rect(0, 0, 200, 200))
rasterizer := raster.NewRasterizer(200, 200) rasterizer := raster.NewRasterizer(200, 200)
rasterizer.UseNonZeroWinding = false 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 { 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 := raster.NewRGBAPainter(img)
painter.SetColor(color) painter.SetColor(color)
rasterizer.Rasterize(painter) rasterizer.Rasterize(painter)
} }
} }
func BenchmarkFreetypeNonZeroWinding(b *testing.B) { func BenchmarkFreetypeNonZeroWinding(b *testing.B) {
var p Path var p Path
p.LineTo(10, 190) p.LineTo(10, 190)
@ -160,9 +173,13 @@ func BenchmarkFreetypeNonZeroWinding(b *testing.B) {
img := image.NewRGBA(image.Rect(0, 0, 200, 200)) img := image.NewRGBA(image.Rect(0, 0, 200, 200))
rasterizer := raster.NewRasterizer(200, 200) rasterizer := raster.NewRasterizer(200, 200)
rasterizer.UseNonZeroWinding = true 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 { 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 := raster.NewRGBAPainter(img)
painter.SetColor(color) painter.SetColor(color)

8
test Executable file
View file

@ -0,0 +1,8 @@
echo golint
golint ./... | grep "draw2dpdf\|samples"
echo
echo go vet
go vet ./...
echo
echo go test
go test -cover ./... | grep -v "no test"