This commit is contained in:
redstarcoder 2017-05-14 10:09:31 +00:00 committed by GitHub
commit f36420b56c
2 changed files with 35 additions and 0 deletions

View File

@ -165,6 +165,10 @@ func (gc *StackGraphicContext) ArcTo(cx, cy, rx, ry, startAngle, angle float64)
gc.Current.Path.ArcTo(cx, cy, rx, ry, startAngle, angle)
}
func (gc *StackGraphicContext) Shift(x, y float64) {
gc.Current.Path.Shift(x, y)
}
func (gc *StackGraphicContext) Close() {
gc.Current.Path.Close()
}

31
path.go
View File

@ -22,6 +22,8 @@ type PathBuilder interface {
CubicCurveTo(cx1, cy1, cx2, cy2, x, y float64)
// ArcTo adds an arc to the current subpath
ArcTo(cx, cy, rx, ry, startAngle, angle float64)
// Shift moves every point in the path by x and y
Shift(x, y float64)
// Close creates a line from the current point to the last MoveTo
// point (if not the same) and mark the path as closed so the
// first and last lines join nicely.
@ -163,6 +165,35 @@ func (p *Path) IsEmpty() bool {
return len(p.Components) == 0
}
// Shift moves every point in the path by x and y
func (p *Path) Shift(x, y float64) {
j := 0
for _, cmd := range p.Components {
if cmd == CloseCmp {
continue
}
p.Points[j] += x
p.Points[j+1] += y
j += 2
switch cmd {
case QuadCurveToCmp:
p.Points[j] += x
p.Points[j+1] += y
j += 2
case CubicCurveToCmp:
p.Points[j] += x
p.Points[j+1] += y
p.Points[j+2] += x
p.Points[j+3] += y
j += 4
case ArcToCmp:
p.Points[j] += x
p.Points[j+1] += y
j += 4
}
}
}
// String returns a debug text view of the path
func (p *Path) String() string {
s := ""