rename Path to PathBuilder

This commit is contained in:
Laurent Le Goff 2015-04-23 18:12:31 +02:00
parent fef7265145
commit 06178b5d2d
9 changed files with 39 additions and 39 deletions

View file

@ -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()
}

View file

@ -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

8
gc.go
View file

@ -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)
}

View file

@ -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

View file

@ -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)

View file

@ -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 {

View file

@ -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 {

View file

@ -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 {

View file

@ -16,7 +16,7 @@ type StackGraphicContext struct {
type ContextStack struct {
Tr MatrixTransform
Path *PathStorage
Path *Path
LineWidth float64
Dash []float64
DashOffset float64