From 55b5c931cf59817bb0ab58e7a47bdd0cdf29d711 Mon Sep 17 00:00:00 2001 From: Stani Date: Fri, 10 Jul 2015 16:58:36 +0200 Subject: [PATCH] golint fixes --- curve/curve_test.go | 20 ++++++++++---------- raster/raster_test.go | 18 +++++++++--------- rgba_interpolation.go | 5 +++++ test | 2 +- vertex2d.go | 7 +++++++ 5 files changed, 32 insertions(+), 20 deletions(-) diff --git a/curve/curve_test.go b/curve/curve_test.go index c101e6a..1196761 100644 --- a/curve/curve_test.go +++ b/curve/curve_test.go @@ -15,8 +15,8 @@ import ( ) var ( - flattening_threshold float64 = 0.5 - testsCubicFloat64 = []CubicCurveFloat64{ + flatteningThreshold = 0.5 + testsCubicFloat64 = []CubicCurveFloat64{ CubicCurveFloat64{100, 100, 200, 100, 100, 200, 200, 200}, CubicCurveFloat64{100, 100, 300, 200, 200, 200, 300, 100}, CubicCurveFloat64{100, 100, 0, 300, 200, 0, 300, 300}, @@ -110,7 +110,7 @@ func TestCubicCurveRec(t *testing.T) { for i, curve := range testsCubicFloat64 { var p Path p.LineTo(curve[0], curve[1]) - curve.SegmentRec(&p, flattening_threshold) + curve.SegmentRec(&p, flatteningThreshold) img := image.NewNRGBA(image.Rect(0, 0, 300, 300)) raster.PolylineBresenham(img, color.NRGBA{0xff, 0, 0, 0xff}, curve[:]...) raster.PolylineBresenham(img, image.Black, p.points...) @@ -126,7 +126,7 @@ func TestCubicCurve(t *testing.T) { for i, curve := range testsCubicFloat64 { var p Path p.LineTo(curve[0], curve[1]) - curve.Segment(&p, flattening_threshold) + curve.Segment(&p, flatteningThreshold) img := image.NewNRGBA(image.Rect(0, 0, 300, 300)) raster.PolylineBresenham(img, color.NRGBA{0xff, 0, 0, 0xff}, curve[:]...) raster.PolylineBresenham(img, image.Black, p.points...) @@ -174,7 +174,7 @@ func TestCubicCurveParabolic(t *testing.T) { for i, curve := range testsCubicFloat64 { var p Path p.LineTo(curve[0], curve[1]) - curve.ParabolicSegment(&p, flattening_threshold) + curve.ParabolicSegment(&p, flatteningThreshold) img := image.NewNRGBA(image.Rect(0, 0, 300, 300)) raster.PolylineBresenham(img, color.NRGBA{0xff, 0, 0, 0xff}, curve[:]...) raster.PolylineBresenham(img, image.Black, p.points...) @@ -190,7 +190,7 @@ func TestQuadCurve(t *testing.T) { for i, curve := range testsQuadFloat64 { var p Path p.LineTo(curve[0], curve[1]) - curve.Segment(&p, flattening_threshold) + curve.Segment(&p, flatteningThreshold) img := image.NewNRGBA(image.Rect(0, 0, 300, 300)) raster.PolylineBresenham(img, color.NRGBA{0xff, 0, 0, 0xff}, curve[:]...) raster.PolylineBresenham(img, image.Black, p.points...) @@ -207,7 +207,7 @@ func BenchmarkCubicCurveRec(b *testing.B) { for _, curve := range testsCubicFloat64 { p := Path{make([]float64, 0, 32)} p.LineTo(curve[0], curve[1]) - curve.SegmentRec(&p, flattening_threshold) + curve.SegmentRec(&p, flatteningThreshold) } } } @@ -217,7 +217,7 @@ func BenchmarkCubicCurve(b *testing.B) { for _, curve := range testsCubicFloat64 { p := Path{make([]float64, 0, 32)} p.LineTo(curve[0], curve[1]) - curve.Segment(&p, flattening_threshold) + curve.Segment(&p, flatteningThreshold) } } } @@ -247,7 +247,7 @@ func BenchmarkCubicCurveParabolic(b *testing.B) { for _, curve := range testsCubicFloat64 { p := Path{make([]float64, 0, 32)} p.LineTo(curve[0], curve[1]) - curve.ParabolicSegment(&p, flattening_threshold) + curve.ParabolicSegment(&p, flatteningThreshold) } } } @@ -257,7 +257,7 @@ func BenchmarkQuadCurve(b *testing.B) { for _, curve := range testsQuadFloat64 { p := Path{make([]float64, 0, 32)} p.LineTo(curve[0], curve[1]) - curve.Segment(&p, flattening_threshold) + curve.Segment(&p, flatteningThreshold) } } } diff --git a/raster/raster_test.go b/raster/raster_test.go index 7a70968..40dc3a9 100644 --- a/raster/raster_test.go +++ b/raster/raster_test.go @@ -13,7 +13,7 @@ import ( "github.com/llgcode/draw2d/curve" ) -var flattening_threshold float64 = 0.5 +var flatteningThreshold = 0.5 func savepng(filePath string, m image.Image) { f, err := os.Create(filePath) @@ -55,7 +55,7 @@ func TestFreetype(t *testing.T) { var p Path p.LineTo(10, 190) c := curve.CubicCurveFloat64{10, 190, 10, 10, 190, 10, 190, 190} - c.Segment(&p, flattening_threshold) + c.Segment(&p, flatteningThreshold) poly := Polygon(p.points) color := color.RGBA{0, 0, 0, 0xff} @@ -81,7 +81,7 @@ func TestFreetypeNonZeroWinding(t *testing.T) { var p Path p.LineTo(10, 190) c := curve.CubicCurveFloat64{10, 190, 10, 10, 190, 10, 190, 190} - c.Segment(&p, flattening_threshold) + c.Segment(&p, flatteningThreshold) poly := Polygon(p.points) color := color.RGBA{0, 0, 0, 0xff} @@ -108,7 +108,7 @@ func TestRasterizer(t *testing.T) { var p Path p.LineTo(10, 190) c := curve.CubicCurveFloat64{10, 190, 10, 10, 190, 10, 190, 190} - c.Segment(&p, flattening_threshold) + c.Segment(&p, flatteningThreshold) poly := Polygon(p.points) color := color.RGBA{0, 0, 0, 0xff} tr := [6]float64{1, 0, 0, 1, 0, 0} @@ -124,7 +124,7 @@ func TestRasterizerNonZeroWinding(t *testing.T) { var p Path p.LineTo(10, 190) c := curve.CubicCurveFloat64{10, 190, 10, 10, 190, 10, 190, 190} - c.Segment(&p, flattening_threshold) + c.Segment(&p, flatteningThreshold) poly := Polygon(p.points) color := color.RGBA{0, 0, 0, 0xff} tr := [6]float64{1, 0, 0, 1, 0, 0} @@ -139,7 +139,7 @@ func BenchmarkFreetype(b *testing.B) { var p Path p.LineTo(10, 190) c := curve.CubicCurveFloat64{10, 190, 10, 10, 190, 10, 190, 190} - c.Segment(&p, flattening_threshold) + c.Segment(&p, flatteningThreshold) poly := Polygon(p.points) color := color.RGBA{0, 0, 0, 0xff} @@ -165,7 +165,7 @@ func BenchmarkFreetypeNonZeroWinding(b *testing.B) { var p Path p.LineTo(10, 190) c := curve.CubicCurveFloat64{10, 190, 10, 10, 190, 10, 190, 190} - c.Segment(&p, flattening_threshold) + c.Segment(&p, flatteningThreshold) poly := Polygon(p.points) color := color.RGBA{0, 0, 0, 0xff} @@ -191,7 +191,7 @@ func BenchmarkRasterizerNonZeroWinding(b *testing.B) { var p Path p.LineTo(10, 190) c := curve.CubicCurveFloat64{10, 190, 10, 10, 190, 10, 190, 190} - c.Segment(&p, flattening_threshold) + c.Segment(&p, flatteningThreshold) poly := Polygon(p.points) color := color.RGBA{0, 0, 0, 0xff} tr := [6]float64{1, 0, 0, 1, 0, 0} @@ -206,7 +206,7 @@ func BenchmarkRasterizer(b *testing.B) { var p Path p.LineTo(10, 190) c := curve.CubicCurveFloat64{10, 190, 10, 10, 190, 10, 190, 190} - c.Segment(&p, flattening_threshold) + c.Segment(&p, flatteningThreshold) poly := Polygon(p.points) color := color.RGBA{0, 0, 0, 0xff} tr := [6]float64{1, 0, 0, 1, 0, 0} diff --git a/rgba_interpolation.go b/rgba_interpolation.go index 92534e7..1265fe0 100644 --- a/rgba_interpolation.go +++ b/rgba_interpolation.go @@ -11,11 +11,15 @@ import ( "math" ) +// ImageFilter defines sampling filter (linear, bilinear or bicubic) type ImageFilter int const ( + // LinearFilter uses linear interpolation LinearFilter ImageFilter = iota + // BilinearFilter uses bilinear interpolation BilinearFilter + // BicubicFilter uses bicubic interpolation BicubicFilter ) @@ -103,6 +107,7 @@ func cubic(offset, v0, v1, v2, v3 float64) uint32 { (-9*v0+9*v2))*offset + (v0 + 16*v1 + v2)) / 18.0) } +// DrawImage draws a source image on an destination image. func DrawImage(src image.Image, dest draw.Image, tr MatrixTransform, op draw.Op, filter ImageFilter) { bounds := src.Bounds() x0, y0, x1, y1 := float64(bounds.Min.X), float64(bounds.Min.Y), float64(bounds.Max.X), float64(bounds.Max.Y) diff --git a/test b/test index f643b46..2a387e6 100755 --- a/test +++ b/test @@ -1,5 +1,5 @@ echo golint -golint ./... | grep "draw2dpdf\|samples" +golint ./... | grep "draw2dpdf\|samples\|^advanced_path\|^arc\|draw2d[.]\|fileutil\|^gc\|math\|^path[.]\|rgba_interpolation\|test\|vertex2d" echo echo go vet go vet ./... diff --git a/vertex2d.go b/vertex2d.go index 4e4d4fd..5bc2f52 100644 --- a/vertex2d.go +++ b/vertex2d.go @@ -3,16 +3,23 @@ package draw2d +// VertexCommand defines different commands to describe the vertex of a path. type VertexCommand byte const ( + // VertexNoCommand does nothing VertexNoCommand VertexCommand = iota + // VertexStartCommand starts a (sub)path VertexStartCommand + // VertexJoinCommand joins the two edges at the vertex VertexJoinCommand + // VertexCloseCommand closes the subpath VertexCloseCommand + // VertexStopCommand is the endpoint of the path. VertexStopCommand ) +// VertexConverter allows to convert vertices. type VertexConverter interface { NextCommand(cmd VertexCommand) Vertex(x, y float64)