replace LineEndMarker by End() Method
This commit is contained in:
parent
ceb331894d
commit
4fa829a373
10 changed files with 93 additions and 82 deletions
11
dasher.go
11
dasher.go
|
@ -21,11 +21,12 @@ func NewDashConverter(dash []float64, dashOffset float64, converter LineBuilder)
|
|||
return &dasher
|
||||
}
|
||||
|
||||
func (dasher *DashVertexConverter) End() {
|
||||
dasher.next.End()
|
||||
}
|
||||
|
||||
func (dasher *DashVertexConverter) NextCommand(cmd LineMarker) {
|
||||
dasher.command = cmd
|
||||
if dasher.command == LineEndMarker {
|
||||
dasher.next.NextCommand(LineEndMarker)
|
||||
}
|
||||
}
|
||||
|
||||
func (dasher *DashVertexConverter) LineTo(x, y float64) {
|
||||
|
@ -57,7 +58,7 @@ func (dasher *DashVertexConverter) lineTo(x, y float64) {
|
|||
dasher.next.LineTo(lx, ly)
|
||||
} else {
|
||||
// gap
|
||||
dasher.next.NextCommand(LineEndMarker)
|
||||
dasher.next.End()
|
||||
dasher.next.MoveTo(lx, ly)
|
||||
}
|
||||
d = d - rest
|
||||
|
@ -71,7 +72,7 @@ func (dasher *DashVertexConverter) lineTo(x, y float64) {
|
|||
dasher.next.LineTo(x, y)
|
||||
} else {
|
||||
// gap
|
||||
dasher.next.NextCommand(LineEndMarker)
|
||||
dasher.next.End()
|
||||
dasher.next.MoveTo(x, y)
|
||||
}
|
||||
if dasher.distance >= dasher.dash[dasher.currentDash] {
|
||||
|
|
|
@ -1,30 +0,0 @@
|
|||
// Copyright 2010 The draw2d Authors. All rights reserved.
|
||||
// created: 13/12/2010 by Laurent Le Goff
|
||||
|
||||
package draw2d
|
||||
|
||||
type DemuxConverter struct {
|
||||
converters []LineBuilder
|
||||
}
|
||||
|
||||
func NewDemuxConverter(converters ...LineBuilder) *DemuxConverter {
|
||||
return &DemuxConverter{converters}
|
||||
}
|
||||
|
||||
func (dc *DemuxConverter) NextCommand(cmd LineMarker) {
|
||||
for _, converter := range dc.converters {
|
||||
converter.NextCommand(cmd)
|
||||
}
|
||||
}
|
||||
|
||||
func (dc *DemuxConverter) MoveTo(x, y float64) {
|
||||
for _, converter := range dc.converters {
|
||||
converter.MoveTo(x, y)
|
||||
}
|
||||
}
|
||||
|
||||
func (dc *DemuxConverter) LineTo(x, y float64) {
|
||||
for _, converter := range dc.converters {
|
||||
converter.LineTo(x, y)
|
||||
}
|
||||
}
|
|
@ -223,7 +223,7 @@ func (gc *GraphicContext) FillStroke(paths ...*draw2d.PathStorage) {
|
|||
stroker := draw2d.NewLineStroker(gc.Current.Cap, gc.Current.Join, draw2d.NewVertexMatrixTransform(gc.Current.Tr, draw2d.NewVertexAdder(gc.strokeRasterizer)))
|
||||
stroker.HalfLineWidth = gc.Current.LineWidth / 2
|
||||
|
||||
demux := draw2d.NewDemuxConverter(filler, stroker)
|
||||
demux := draw2d.NewLineBuilders(filler, stroker)
|
||||
paths = append(paths, gc.Current.Path)
|
||||
pathConverter := draw2d.NewPathConverter(demux)
|
||||
pathConverter.ApproximationScale = gc.Current.Tr.GetScale() // From agg code
|
||||
|
|
2
image.go
2
image.go
|
@ -317,7 +317,7 @@ func (gc *ImageGraphicContext) FillStroke(paths ...*PathStorage) {
|
|||
stroker := NewLineStroker(gc.Current.Cap, gc.Current.Join, NewVertexMatrixTransform(gc.Current.Tr, NewVertexAdder(gc.strokeRasterizer)))
|
||||
stroker.HalfLineWidth = gc.Current.LineWidth / 2
|
||||
|
||||
demux := NewDemuxConverter(filler, stroker)
|
||||
demux := NewLineBuilders(filler, stroker)
|
||||
paths = append(paths, gc.Current.Path)
|
||||
pathConverter := NewPathConverter(demux)
|
||||
pathConverter.ApproximationScale = gc.Current.Tr.GetScale()
|
||||
|
|
54
line.go
Normal file
54
line.go
Normal file
|
@ -0,0 +1,54 @@
|
|||
// Copyright 2010 The draw2d Authors. All rights reserved.
|
||||
// created: 21/11/2010 by Laurent Le Goff
|
||||
|
||||
package draw2d
|
||||
|
||||
type LineMarker byte
|
||||
|
||||
const (
|
||||
LineNoneMarker LineMarker = iota
|
||||
// Mark the current point of the line as a join to it can draw some specific join Bevel, Miter, Rount
|
||||
LineJoinMarker
|
||||
// Mark the current point of the line as closed so it draw a line from the current
|
||||
// position to the point specified by the last start marker.
|
||||
LineCloseMarker
|
||||
)
|
||||
|
||||
type LineBuilder interface {
|
||||
NextCommand(cmd LineMarker)
|
||||
MoveTo(x, y float64)
|
||||
LineTo(x, y float64)
|
||||
End()
|
||||
}
|
||||
|
||||
type LineBuilders struct {
|
||||
builders []LineBuilder
|
||||
}
|
||||
|
||||
func NewLineBuilders(builders ...LineBuilder) *LineBuilders {
|
||||
return &LineBuilders{builders}
|
||||
}
|
||||
|
||||
func (dc *LineBuilders) NextCommand(cmd LineMarker) {
|
||||
for _, converter := range dc.builders {
|
||||
converter.NextCommand(cmd)
|
||||
}
|
||||
}
|
||||
|
||||
func (dc *LineBuilders) MoveTo(x, y float64) {
|
||||
for _, converter := range dc.builders {
|
||||
converter.MoveTo(x, y)
|
||||
}
|
||||
}
|
||||
|
||||
func (dc *LineBuilders) LineTo(x, y float64) {
|
||||
for _, converter := range dc.builders {
|
||||
converter.LineTo(x, y)
|
||||
}
|
||||
}
|
||||
|
||||
func (dc *LineBuilders) End() {
|
||||
for _, converter := range dc.builders {
|
||||
converter.End()
|
||||
}
|
||||
}
|
|
@ -27,6 +27,9 @@ func (vertexAdder *VertexAdder) LineTo(x, y float64) {
|
|||
vertexAdder.adder.Add1(raster.Point{raster.Fix32(x * 256), raster.Fix32(y * 256)})
|
||||
}
|
||||
|
||||
func (vertexAdder *VertexAdder) End() {
|
||||
}
|
||||
|
||||
type PathAdder struct {
|
||||
adder raster.Adder
|
||||
firstPoint raster.Point
|
||||
|
|
|
@ -27,7 +27,7 @@ func (c *PathConverter) Convert(paths ...*PathStorage) {
|
|||
c.x, c.y = path.vertices[i], path.vertices[i+1]
|
||||
c.startX, c.startY = c.x, c.y
|
||||
if i != 0 {
|
||||
c.converter.NextCommand(LineEndMarker)
|
||||
c.converter.End()
|
||||
}
|
||||
c.converter.MoveTo(c.x, c.y)
|
||||
i += 2
|
||||
|
@ -67,7 +67,7 @@ func (c *PathConverter) Convert(paths ...*PathStorage) {
|
|||
c.converter.LineTo(c.startX, c.startY)
|
||||
}
|
||||
}
|
||||
c.converter.NextCommand(LineEndMarker)
|
||||
c.converter.End()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -78,7 +78,7 @@ func (c *PathConverter) convertCommand(cmd PathCmd, vertices ...float64) int {
|
|||
func (c *PathConverter) MoveTo(x, y float64) *PathConverter {
|
||||
c.x, c.y = x, y
|
||||
c.startX, c.startY = c.x, c.y
|
||||
c.converter.NextCommand(LineEndMarker)
|
||||
c.converter.End()
|
||||
c.converter.MoveTo(c.x, c.y)
|
||||
return c
|
||||
}
|
||||
|
|
|
@ -44,7 +44,9 @@ func NewLineStroker(c Cap, j Join, converter LineBuilder) *LineStroker {
|
|||
|
||||
func (l *LineStroker) NextCommand(command LineMarker) {
|
||||
l.command = command
|
||||
if command == LineEndMarker {
|
||||
}
|
||||
|
||||
func (l *LineStroker) End() {
|
||||
if len(l.vertices) > 1 {
|
||||
l.Next.MoveTo(l.vertices[0], l.vertices[1])
|
||||
for i, j := 2, 3; j < len(l.vertices); i, j = i+2, j+2 {
|
||||
|
@ -60,12 +62,12 @@ func (l *LineStroker) NextCommand(command LineMarker) {
|
|||
l.Next.NextCommand(LineNoneMarker)
|
||||
l.Next.LineTo(l.vertices[0], l.vertices[1])
|
||||
}
|
||||
l.Next.NextCommand(LineEndMarker)
|
||||
l.Next.End()
|
||||
// reinit vertices
|
||||
l.vertices = l.vertices[0:0]
|
||||
l.rewind = l.rewind[0:0]
|
||||
l.x, l.y, l.nx, l.ny = 0, 0, 0, 0
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (l *LineStroker) MoveTo(x, y float64) {
|
||||
|
|
|
@ -278,6 +278,10 @@ func (vmt *VertexMatrixTransform) LineTo(x, y float64) {
|
|||
vmt.Next.LineTo(u, v)
|
||||
}
|
||||
|
||||
func (vmt *VertexMatrixTransform) End() {
|
||||
vmt.Next.End()
|
||||
}
|
||||
|
||||
// this adder apply a Matrix transformation to points
|
||||
type MatrixTransformAdder struct {
|
||||
tr MatrixTransform
|
||||
|
|
23
vertex2d.go
23
vertex2d.go
|
@ -1,23 +0,0 @@
|
|||
// Copyright 2010 The draw2d Authors. All rights reserved.
|
||||
// created: 21/11/2010 by Laurent Le Goff
|
||||
|
||||
package draw2d
|
||||
|
||||
type LineMarker byte
|
||||
|
||||
const (
|
||||
LineNoneMarker LineMarker = iota
|
||||
// Mark the current point of the line as a join to it can draw some specific join Bevel, Miter, Rount
|
||||
LineJoinMarker
|
||||
// Mark the current point of the line as closed so it draw a line from the current
|
||||
// position to the point specified by the last start marker.
|
||||
LineCloseMarker
|
||||
// Mark the current point of the line as finished. This ending maker allow caps to be drawn
|
||||
LineEndMarker
|
||||
)
|
||||
|
||||
type LineBuilder interface {
|
||||
NextCommand(cmd LineMarker)
|
||||
MoveTo(x, y float64)
|
||||
LineTo(x, y float64)
|
||||
}
|
Loading…
Reference in a new issue