From 06178b5d2de8d18b081ae7f49917809d21c73f90 Mon Sep 17 00:00:00 2001 From: Laurent Le Goff Date: Thu, 23 Apr 2015 18:12:31 +0200 Subject: [PATCH] rename Path to PathBuilder --- advanced_path.go | 8 ++++---- draw2dgl/gc.go | 6 +++--- gc.go | 8 ++++---- image.go | 6 +++--- path.go | 2 +- path_adder.go | 2 +- path_converter.go | 2 +- path_storage.go | 42 +++++++++++++++++++++--------------------- stack_gc.go | 2 +- 9 files changed, 39 insertions(+), 39 deletions(-) diff --git a/advanced_path.go b/advanced_path.go index 68f1d78..c5d8984 100644 --- a/advanced_path.go +++ b/advanced_path.go @@ -9,7 +9,7 @@ import ( //high level path creation -func Rect(path Path, x1, y1, x2, y2 float64) { +func Rect(path PathBuilder, x1, y1, x2, y2 float64) { path.MoveTo(x1, y1) path.LineTo(x2, y1) path.LineTo(x2, y2) @@ -17,7 +17,7 @@ func Rect(path Path, x1, y1, x2, y2 float64) { path.Close() } -func RoundRect(path Path, x1, y1, x2, y2, arcWidth, arcHeight float64) { +func RoundRect(path PathBuilder, x1, y1, x2, y2, arcWidth, arcHeight float64) { arcWidth = arcWidth / 2 arcHeight = arcHeight / 2 path.MoveTo(x1, y1+arcHeight) @@ -31,12 +31,12 @@ func RoundRect(path Path, x1, y1, x2, y2, arcWidth, arcHeight float64) { path.Close() } -func Ellipse(path Path, cx, cy, rx, ry float64) { +func Ellipse(path PathBuilder, cx, cy, rx, ry float64) { path.ArcTo(cx, cy, rx, ry, 0, -math.Pi*2) path.Close() } -func Circle(path Path, cx, cy, radius float64) { +func Circle(path PathBuilder, cx, cy, radius float64) { path.ArcTo(cx, cy, radius, radius, 0, -math.Pi*2) path.Close() } diff --git a/draw2dgl/gc.go b/draw2dgl/gc.go index b0a0a07..24faa69 100644 --- a/draw2dgl/gc.go +++ b/draw2dgl/gc.go @@ -182,7 +182,7 @@ func (gc *GraphicContext) paint(rasterizer *raster.Rasterizer, color color.Color gc.painter.Flush() } -func (gc *GraphicContext) Stroke(paths ...*draw2d.PathStorage) { +func (gc *GraphicContext) Stroke(paths ...*draw2d.Path) { paths = append(paths, gc.Current.Path) gc.strokeRasterizer.UseNonZeroWinding = true @@ -202,7 +202,7 @@ func (gc *GraphicContext) Stroke(paths ...*draw2d.PathStorage) { gc.Current.Path.Clear() } -func (gc *GraphicContext) Fill(paths ...*draw2d.PathStorage) { +func (gc *GraphicContext) Fill(paths ...*draw2d.Path) { paths = append(paths, gc.Current.Path) gc.fillRasterizer.UseNonZeroWinding = gc.Current.FillRule.UseNonZeroWinding() @@ -214,7 +214,7 @@ func (gc *GraphicContext) Fill(paths ...*draw2d.PathStorage) { gc.Current.Path.Clear() } -func (gc *GraphicContext) FillStroke(paths ...*draw2d.PathStorage) { +func (gc *GraphicContext) FillStroke(paths ...*draw2d.Path) { gc.fillRasterizer.UseNonZeroWinding = gc.Current.FillRule.UseNonZeroWinding() gc.strokeRasterizer.UseNonZeroWinding = true diff --git a/gc.go b/gc.go index 66dc508..c00cba0 100644 --- a/gc.go +++ b/gc.go @@ -16,7 +16,7 @@ const ( ) type GraphicContext interface { - Path + PathBuilder // Create a new path BeginPath() GetMatrixTransform() MatrixTransform @@ -49,7 +49,7 @@ type GraphicContext interface { FillStringAt(text string, x, y float64) (cursor float64) StrokeString(text string) (cursor float64) StrokeStringAt(text string, x, y float64) (cursor float64) - Stroke(paths ...*PathStorage) - Fill(paths ...*PathStorage) - FillStroke(paths ...*PathStorage) + Stroke(paths ...*Path) + Fill(paths ...*Path) + FillStroke(paths ...*Path) } diff --git a/image.go b/image.go index 952dc2c..73dcb49 100644 --- a/image.go +++ b/image.go @@ -275,7 +275,7 @@ func (gc *ImageGraphicContext) paint(rasterizer *raster.Rasterizer, color color. } /**** second method ****/ -func (gc *ImageGraphicContext) Stroke(paths ...*PathStorage) { +func (gc *ImageGraphicContext) Stroke(paths ...*Path) { paths = append(paths, gc.Current.Path) gc.strokeRasterizer.UseNonZeroWinding = true @@ -295,7 +295,7 @@ func (gc *ImageGraphicContext) Stroke(paths ...*PathStorage) { } /**** second method ****/ -func (gc *ImageGraphicContext) Fill(paths ...*PathStorage) { +func (gc *ImageGraphicContext) Fill(paths ...*Path) { paths = append(paths, gc.Current.Path) gc.fillRasterizer.UseNonZeroWinding = gc.Current.FillRule.UseNonZeroWinding() @@ -308,7 +308,7 @@ func (gc *ImageGraphicContext) Fill(paths ...*PathStorage) { } /* second method */ -func (gc *ImageGraphicContext) FillStroke(paths ...*PathStorage) { +func (gc *ImageGraphicContext) FillStroke(paths ...*Path) { gc.fillRasterizer.UseNonZeroWinding = gc.Current.FillRule.UseNonZeroWinding() gc.strokeRasterizer.UseNonZeroWinding = true diff --git a/path.go b/path.go index 8d69dd0..232cf76 100644 --- a/path.go +++ b/path.go @@ -4,7 +4,7 @@ package draw2d // PathBuilder define method that create path -type Path interface { +type PathBuilder interface { // Return the current point of the current path LastPoint() (x, y float64) diff --git a/path_adder.go b/path_adder.go index 696cf89..a958a57 100644 --- a/path_adder.go +++ b/path_adder.go @@ -42,7 +42,7 @@ func NewPathAdder(adder raster.Adder) *PathAdder { return &PathAdder{adder, raster.Point{0, 0}, 1} } -func (pathAdder *PathAdder) Convert(paths ...*PathStorage) { +func (pathAdder *PathAdder) Convert(paths ...*Path) { for _, path := range paths { j := 0 for _, cmd := range path.commands { diff --git a/path_converter.go b/path_converter.go index 90bf415..dd96853 100644 --- a/path_converter.go +++ b/path_converter.go @@ -18,7 +18,7 @@ func NewPathConverter(converter LineBuilder) *PathConverter { return &PathConverter{converter, 1, 0, 0, 0, 0} } -func (c *PathConverter) Convert(paths ...*PathStorage) { +func (c *PathConverter) Convert(paths ...*Path) { for _, path := range paths { i := 0 for _, cmd := range path.commands { diff --git a/path_storage.go b/path_storage.go index 5fc8890..3725730 100644 --- a/path_storage.go +++ b/path_storage.go @@ -19,32 +19,32 @@ const ( Close ) -type PathStorage struct { +type Path struct { commands []PathCmd vertices []float64 x, y float64 } -func NewPathStorage() (p *PathStorage) { - p = new(PathStorage) +func NewPathStorage() (p *Path) { + p = new(Path) p.commands = make([]PathCmd, 0, 256) p.vertices = make([]float64, 0, 256) return } -func (p *PathStorage) Clear() { +func (p *Path) Clear() { p.commands = p.commands[0:0] p.vertices = p.vertices[0:0] return } -func (p *PathStorage) appendToPath(cmd PathCmd, vertices ...float64) { +func (p *Path) appendToPath(cmd PathCmd, vertices ...float64) { p.commands = append(p.commands, cmd) p.vertices = append(p.vertices, vertices...) } -func (src *PathStorage) Copy() (dest *PathStorage) { - dest = new(PathStorage) +func (src *Path) Copy() (dest *Path) { + dest = new(Path) dest.commands = make([]PathCmd, len(src.commands)) copy(dest.commands, src.commands) dest.vertices = make([]float64, len(src.vertices)) @@ -52,31 +52,31 @@ func (src *PathStorage) Copy() (dest *PathStorage) { return dest } -func (p *PathStorage) LastPoint() (x, y float64) { +func (p *Path) LastPoint() (x, y float64) { return p.x, p.y } -func (p *PathStorage) IsEmpty() bool { +func (p *Path) IsEmpty() bool { return len(p.commands) == 0 } -func (p *PathStorage) Close() { +func (p *Path) Close() { p.appendToPath(Close) } -func (p *PathStorage) MoveTo(x, y float64) { +func (p *Path) MoveTo(x, y float64) { p.appendToPath(MoveTo, x, y) p.x = x p.y = y } -func (p *PathStorage) RMoveTo(dx, dy float64) { +func (p *Path) RMoveTo(dx, dy float64) { x, y := p.LastPoint() p.MoveTo(x+dx, y+dy) } -func (p *PathStorage) LineTo(x, y float64) { +func (p *Path) LineTo(x, y float64) { if len(p.commands) == 0 { //special case when no move has been done p.MoveTo(0, 0) } @@ -85,12 +85,12 @@ func (p *PathStorage) LineTo(x, y float64) { p.y = y } -func (p *PathStorage) RLineTo(dx, dy float64) { +func (p *Path) RLineTo(dx, dy float64) { x, y := p.LastPoint() p.LineTo(x+dx, y+dy) } -func (p *PathStorage) QuadCurveTo(cx, cy, x, y float64) { +func (p *Path) QuadCurveTo(cx, cy, x, y float64) { if len(p.commands) == 0 { //special case when no move has been done p.MoveTo(0, 0) } @@ -99,12 +99,12 @@ func (p *PathStorage) QuadCurveTo(cx, cy, x, y float64) { p.y = y } -func (p *PathStorage) RQuadCurveTo(dcx, dcy, dx, dy float64) { +func (p *Path) RQuadCurveTo(dcx, dcy, dx, dy float64) { x, y := p.LastPoint() p.QuadCurveTo(x+dcx, y+dcy, x+dx, y+dy) } -func (p *PathStorage) CubicCurveTo(cx1, cy1, cx2, cy2, x, y float64) { +func (p *Path) CubicCurveTo(cx1, cy1, cx2, cy2, x, y float64) { if len(p.commands) == 0 { //special case when no move has been done p.MoveTo(0, 0) } @@ -113,12 +113,12 @@ func (p *PathStorage) CubicCurveTo(cx1, cy1, cx2, cy2, x, y float64) { p.y = y } -func (p *PathStorage) RCubicCurveTo(dcx1, dcy1, dcx2, dcy2, dx, dy float64) { +func (p *Path) RCubicCurveTo(dcx1, dcy1, dcx2, dcy2, dx, dy float64) { x, y := p.LastPoint() p.CubicCurveTo(x+dcx1, y+dcy1, x+dcx2, y+dcy2, x+dx, y+dy) } -func (p *PathStorage) ArcTo(cx, cy, rx, ry, startAngle, angle float64) { +func (p *Path) ArcTo(cx, cy, rx, ry, startAngle, angle float64) { endAngle := startAngle + angle clockWise := true if angle < 0 { @@ -146,12 +146,12 @@ func (p *PathStorage) ArcTo(cx, cy, rx, ry, startAngle, angle float64) { p.y = cy + math.Sin(endAngle)*ry } -func (p *PathStorage) RArcTo(dcx, dcy, rx, ry, startAngle, angle float64) { +func (p *Path) RArcTo(dcx, dcy, rx, ry, startAngle, angle float64) { x, y := p.LastPoint() p.ArcTo(x+dcx, y+dcy, rx, ry, startAngle, angle) } -func (p *PathStorage) String() string { +func (p *Path) String() string { s := "" j := 0 for _, cmd := range p.commands { diff --git a/stack_gc.go b/stack_gc.go index 3741328..ee26f61 100644 --- a/stack_gc.go +++ b/stack_gc.go @@ -16,7 +16,7 @@ type StackGraphicContext struct { type ContextStack struct { Tr MatrixTransform - Path *PathStorage + Path *Path LineWidth float64 Dash []float64 DashOffset float64