Skip to content

Commit c77de7e

Browse files
committed
Post go fix
1 parent a9b0a1b commit c77de7e

File tree

10 files changed

+30
-32
lines changed

10 files changed

+30
-32
lines changed

color/hsl.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ func Monochrome(col Color, n int) []HSL {
131131
res := make([]HSL, n)
132132
dl := 1.0 / float64(n-1)
133133
l := dl
134-
for i := 0; i < n; i++ {
134+
for i := range n {
135135
hsl := NewHSL(col)
136136
hsl.L = l
137137
res[i] = hsl

image/color.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,7 @@ type cstop struct {
2525
func NewColorizer(img Image, c1, c2 color.Color, stops []int, colors []color.Color, post bool) *Colorizer {
2626
lut := make([]color.RGBA, 256)
2727

28-
sc := len(colors)
29-
if sc > 254 {
30-
sc = 254
31-
}
28+
sc := min(len(colors), 254)
3229
if stops != nil && len(stops) < sc {
3330
sc = len(stops)
3431
}
@@ -62,7 +59,7 @@ func NewColorizer(img Image, c1, c2 color.Color, stops []int, colors []color.Col
6259
// Build lut - simple lerp between c1, stops and c2, unless post set
6360
if post {
6461
ci := 0
65-
for i := 0; i < 256; i++ {
62+
for i := range 256 {
6663
lut[i] = csl[ci].c
6764
if i != 255 && i+1 == csl[ci+1].s {
6865
ci++
@@ -71,7 +68,7 @@ func NewColorizer(img Image, c1, c2 color.Color, stops []int, colors []color.Col
7168
} else {
7269
ci := 0
7370
ls := 0
74-
for i := 0; i < 256; i++ {
71+
for i := range 256 {
7572
if i == csl[ci].s {
7673
lut[i] = csl[ci].c
7774
if i != 255 {

image/patch.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ func NewPatch(colors [][]color.Color) (*Patch, error) {
1919
h := len(colors)
2020
w := len(colors[0])
2121
rgba := make([][]color.RGBA, h)
22-
for i := 0; i < h; i++ {
22+
for i := range h {
2323
if len(colors[i]) != w {
2424
return nil, fmt.Errorf("row %d has different length %d vs %d", i, len(colors[i]), w)
2525
}
2626
rgba[i] = make([]color.RGBA, w)
27-
for j := 0; j < w; j++ {
27+
for j := range w {
2828
rgba[i][j], _ = color.RGBAModel.Convert(colors[i][j]).(color.RGBA)
2929
}
3030
}

path.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -187,14 +187,14 @@ type Part [][]float64
187187

188188
// String converts a part into a string.
189189
func (p Part) String() string {
190-
res := ""
190+
var res strings.Builder
191191
for i, pt := range p {
192192
if i != 0 {
193-
res += " "
193+
res.WriteString(" ")
194194
}
195-
res += fmt.Sprintf("%.2f,%.2f", pt[0], pt[1])
195+
res.WriteString(fmt.Sprintf("%.2f,%.2f", pt[0], pt[1]))
196196
}
197-
return res
197+
return res.String()
198198
}
199199

200200
// AddParts adds parts to the path and returns it.
@@ -890,18 +890,19 @@ func (p *Path) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
890890
// P %f,%f[ %d[ %f,%f]][ C]
891891
func (p *Path) MarshalText() ([]byte, error) {
892892
step := p.steps[0]
893-
str := fmt.Sprintf("P %f,%f", step[0][0], step[0][1])
893+
var str strings.Builder
894+
str.WriteString(fmt.Sprintf("P %f,%f", step[0][0], step[0][1]))
894895
for i := 1; i < len(p.steps); i++ {
895896
step = p.steps[i]
896-
str += fmt.Sprintf(" %d", len(step))
897+
str.WriteString(fmt.Sprintf(" %d", len(step)))
897898
for _, pts := range step {
898-
str += fmt.Sprintf(" %f,%f", pts[0], pts[1])
899+
str.WriteString(fmt.Sprintf(" %f,%f", pts[0], pts[1]))
899900
}
900901
}
901902
if p.closed {
902-
str += " C"
903+
str.WriteString(" C")
903904
}
904-
return []byte(str), nil
905+
return []byte(str.String()), nil
905906
}
906907

907908
// UnmarshalText implements the encoding.TextUnmarshaler interface.

shape.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,12 +224,13 @@ func (s *Shape) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
224224
// MarshalText implements the encoding.TextMarshaler interface.
225225
// S[ P %f,%f[ %d[ %f,%f]][ C]]
226226
func (s *Shape) MarshalText() ([]byte, error) {
227-
str := "S"
227+
var str strings.Builder
228+
str.WriteString("S")
228229
for _, path := range s.paths {
229-
str += " " + path.String()
230+
str.WriteString(" " + path.String())
230231
}
231232

232-
return []byte(str), nil
233+
return []byte(str.String()), nil
233234
}
234235

235236
// UnmarshalText implements the encoding.TextUnmarshaler interface.

svg/cmd/house.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func main() {
9090
}
9191

9292
func MakeHouse() *g2d.Renderable {
93-
// Order is important - furthest from eye obejcts first
93+
// Order is important - furthest from eye objects first
9494
res := MakeChimney()
9595
res.AddRenderable(MakeFirstFloor(), nil)
9696
res.AddRenderable(MakeSecondFloor(), nil)

util/bcroots.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package util
22

33
import (
44
"fmt"
5+
"maps"
56
"math"
67
"sort"
78
)
@@ -115,9 +116,7 @@ func CalcExtremities(points [][]float64) []float64 {
115116

116117
// Add map2 to map1
117118
func addMap(map1, map2 map[string]bool) {
118-
for k, v := range map2 {
119-
map1[k] = v
120-
}
119+
maps.Copy(map1, map2)
121120
}
122121

123122
func calcRoots(f, df func(float64) float64, tmap map[string]bool) {
@@ -137,7 +136,7 @@ func calcRoots(f, df func(float64) float64, tmap map[string]bool) {
137136
func NRM(start float64, f, df func(float64) float64) (float64, error) {
138137
t := start
139138

140-
for i := 0; i < 100; i++ {
139+
for range 100 {
141140
d := df(t)
142141
if Equals(d, 0) {
143142
return 0, fmt.Errorf("zero derivative at %f", t)

util/boundingbox.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func BoundingBox(pts ...[]float64) [][]float64 {
1818
res[0] = make([]float64, d)
1919
res[1] = make([]float64, d)
2020

21-
for i := 0; i < d; i++ {
21+
for i := range d {
2222
res[0][i], res[1][i] = math.MaxFloat64, -math.MaxFloat64
2323
}
2424

@@ -42,7 +42,7 @@ func BoundingBox(pts ...[]float64) [][]float64 {
4242
// BBOverlap returns true if bb1 and bb2 overlap at the smallest dimensionality.
4343
func BBOverlap(bb1, bb2 [][]float64) bool {
4444
md := min(len(bb1[0]), len(bb2[0]))
45-
for i := 0; i < md; i++ {
45+
for i := range md {
4646
if bb1[0][i] > bb2[1][i] || bb2[0][i] > bb1[1][i] {
4747
return false
4848
}
@@ -54,7 +54,7 @@ func BBOverlap(bb1, bb2 [][]float64) bool {
5454
func BBIntersection(bb1, bb2 [][]float64) [][]float64 {
5555
md := min(len(bb1[0]), len(bb2[0]))
5656
res := [][]float64{make([]float64, md), make([]float64, md)}
57-
for i := 0; i < md; i++ {
57+
for i := range md {
5858
if bb1[0][i] > bb2[1][i] || bb2[0][i] > bb1[1][i] {
5959
return nil
6060
}
@@ -68,7 +68,7 @@ func BBIntersection(bb1, bb2 [][]float64) [][]float64 {
6868
// BBContains returns true if p is in bb at the smallest dimensionality.
6969
func BBContains(p []float64, bb [][]float64) bool {
7070
md := min(len(bb[0]), len(p))
71-
for i := 0; i < md; i++ {
71+
for i := range md {
7272
if p[i] < bb[0][i] || p[i] > bb[1][i] {
7373
return false
7474
}

util/curves.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func DeCasteljau(pts [][]float64, t float64) []float64 {
9292
}
9393
npts := make([][]float64, len(pts)-1)
9494
omt := 1 - t
95-
for i := 0; i < len(npts); i++ {
95+
for i := range npts {
9696
npts[i] = []float64{
9797
omt*pts[i][0] + t*pts[i+1][0], omt*pts[i][1] + t*pts[i+1][1],
9898
pts[i+1][0] - pts[i][0], pts[i+1][1] - pts[i][1]}

util/math.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ func Centroid(pts ...[]float64) []float64 {
201201
}
202202
}
203203
// Scale
204-
for i := 0; i < d; i++ {
204+
for i := range d {
205205
res[i] /= float64(n)
206206
}
207207
return res

0 commit comments

Comments
 (0)