freetype/raster: fix some style nits.

This code dates from before Go 1.0.

LGTM=crawshaw
R=crawshaw
CC=golang-codereviews
https://codereview.appspot.com/206860043
This commit is contained in:
Nigel Tao 2015-02-24 10:52:08 +11:00
parent cf94cb9b43
commit 78edcde0f3
4 changed files with 24 additions and 64 deletions

View file

@ -101,7 +101,7 @@ func (p Point) Len() Fix32 {
func (p Point) Norm(length Fix32) Point {
d := p.Len()
if d == 0 {
return Point{0, 0}
return Point{}
}
s, t := int64(length), int64(d)
x := int64(p.X) * s / t
@ -204,74 +204,34 @@ func (p Path) String() string {
return s
}
// grow adds n elements to p.
func (p *Path) grow(n int) {
n += len(*p)
if n > cap(*p) {
old := *p
*p = make([]Fix32, n, 2*n+8)
copy(*p, old)
return
}
*p = (*p)[0:n]
}
// Clear cancels any previous calls to p.Start or p.AddXxx.
func (p *Path) Clear() {
*p = (*p)[0:0]
*p = (*p)[:0]
}
// Start starts a new curve at the given point.
func (p *Path) Start(a Point) {
n := len(*p)
p.grow(4)
(*p)[n] = 0
(*p)[n+1] = a.X
(*p)[n+2] = a.Y
(*p)[n+3] = 0
*p = append(*p, 0, a.X, a.Y, 0)
}
// Add1 adds a linear segment to the current curve.
func (p *Path) Add1(b Point) {
n := len(*p)
p.grow(4)
(*p)[n] = 1
(*p)[n+1] = b.X
(*p)[n+2] = b.Y
(*p)[n+3] = 1
*p = append(*p, 1, b.X, b.Y, 1)
}
// Add2 adds a quadratic segment to the current curve.
func (p *Path) Add2(b, c Point) {
n := len(*p)
p.grow(6)
(*p)[n] = 2
(*p)[n+1] = b.X
(*p)[n+2] = b.Y
(*p)[n+3] = c.X
(*p)[n+4] = c.Y
(*p)[n+5] = 2
*p = append(*p, 2, b.X, b.Y, c.X, c.Y, 2)
}
// Add3 adds a cubic segment to the current curve.
func (p *Path) Add3(b, c, d Point) {
n := len(*p)
p.grow(8)
(*p)[n] = 3
(*p)[n+1] = b.X
(*p)[n+2] = b.Y
(*p)[n+3] = c.X
(*p)[n+4] = c.Y
(*p)[n+5] = d.X
(*p)[n+6] = d.Y
(*p)[n+7] = 3
*p = append(*p, 3, b.X, b.Y, c.X, c.Y, d.X, d.Y, 3)
}
// AddPath adds the Path q to p.
func (p *Path) AddPath(q Path) {
n, m := len(*p), len(q)
p.grow(m)
copy((*p)[n:n+m], q)
*p = append(*p, q...)
}
// AddStroke adds a stroked Path.

View file

@ -208,11 +208,11 @@ func (m *MonochromePainter) Paint(ss []Span, done bool) {
if j < len(ss) {
ss[j] = finalSpan
j++
m.Painter.Paint(ss[0:j], true)
m.Painter.Paint(ss[:j], true)
} else if j == len(ss) {
m.Painter.Paint(ss, false)
if cap(ss) > 0 {
ss = ss[0:1]
ss = ss[:1]
} else {
ss = make([]Span, 1)
}
@ -224,7 +224,7 @@ func (m *MonochromePainter) Paint(ss []Span, done bool) {
// Reset the accumulator, so that this Painter can be re-used.
m.y, m.x0, m.x1 = 0, 0, 0
} else {
m.Painter.Paint(ss[0:j], false)
m.Painter.Paint(ss[:j], false)
}
}
@ -253,11 +253,11 @@ func (g *GammaCorrectionPainter) Paint(ss []Span, done bool) {
M = 0x1010101 // 255*M == 1<<32-1
N = 0x8080 // N = M>>9, and N < 1<<16-1
)
for i, _ := range ss {
if ss[i].A == 0 || ss[i].A == 1<<32-1 {
for i, s := range ss {
if s.A == 0 || s.A == 1<<32-1 {
continue
}
p, q := ss[i].A/M, (ss[i].A%M)>>9
p, q := s.A/M, (s.A%M)>>9
// The resultant alpha is a linear interpolation of g.a[p] and g.a[p+1].
a := uint32(g.a[p])*(N-q) + uint32(g.a[p+1])*q
a = (a + N/2) / N

View file

@ -327,8 +327,8 @@ func (r *Rasterizer) Add2(b, c Point) {
s := sStack[i]
p := pStack[2*i:]
if s > 0 {
// Split the quadratic curve p[0:3] into an equivalent set of two shorter curves:
// p[0:3] and p[2:5]. The new p[4] is the old p[2], and p[0] is unchanged.
// Split the quadratic curve p[:3] into an equivalent set of two shorter curves:
// p[:3] and p[2:5]. The new p[4] is the old p[2], and p[0] is unchanged.
mx := p[1].X
p[4].X = p[2].X
p[3].X = (p[4].X + mx) / 2
@ -385,8 +385,8 @@ func (r *Rasterizer) Add3(b, c, d Point) {
s := sStack[i]
p := pStack[3*i:]
if s > 0 {
// Split the cubic curve p[0:4] into an equivalent set of two shorter curves:
// p[0:4] and p[3:7]. The new p[6] is the old p[3], and p[0] is unchanged.
// Split the cubic curve p[:4] into an equivalent set of two shorter curves:
// p[:4] and p[3:7]. The new p[6] is the old p[3], and p[0] is unchanged.
m01x := (p[0].X + p[1].X) / 2
m12x := (p[1].X + p[2].X) / 2
m23x := (p[2].X + p[3].X) / 2
@ -519,22 +519,22 @@ func (r *Rasterizer) Rasterize(p Painter) {
}
}
if s > len(r.spanBuf)-2 {
p.Paint(r.spanBuf[0:s], false)
p.Paint(r.spanBuf[:s], false)
s = 0
}
}
}
p.Paint(r.spanBuf[0:s], true)
p.Paint(r.spanBuf[:s], true)
}
// Clear cancels any previous calls to r.Start or r.AddXxx.
func (r *Rasterizer) Clear() {
r.a = Point{0, 0}
r.a = Point{}
r.xi = 0
r.yi = 0
r.area = 0
r.cover = 0
r.cell = r.cell[0:0]
r.cell = r.cell[:0]
for i := 0; i < len(r.cellIndex); i++ {
r.cellIndex[i] = -1
}
@ -562,11 +562,11 @@ func (r *Rasterizer) SetBounds(width, height int) {
r.width = width
r.splitScale2 = ss2
r.splitScale3 = ss3
r.cell = r.cellBuf[0:0]
r.cell = r.cellBuf[:0]
if height > len(r.cellIndexBuf) {
r.cellIndex = make([]int, height)
} else {
r.cellIndex = r.cellIndexBuf[0:height]
r.cellIndex = r.cellIndexBuf[:height]
}
r.Clear()
}

View file

@ -401,7 +401,7 @@ func (k *stroker) stroke(q Path) {
// The left-hand-side path is added immediately to k.p; the right-hand-side
// path is accumulated in k.r. Once we've finished adding the LHS to k.p,
// we add the RHS in reverse order.
k.r = Path(make([]Fix32, 0, len(q)))
k.r = make(Path, 0, len(q))
k.a = Point{q[1], q[2]}
for i := 4; i < len(q); {
switch q[i] {