Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions bezier.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ func quadratic(x0, y0, x1, y1, x2, y2, t float64) (x, y float64) {
func QuadraticBezier(x0, y0, x1, y1, x2, y2 float64) []Point {
l := (math.Hypot(x1-x0, y1-y0) +
math.Hypot(x2-x1, y2-y1))
n := int(l + 0.5)
if n < 4 {
n = 4
}
n := max(int(l+0.5), 4)
d := float64(n) - 1
result := make([]Point, n)
for i := 0; i < n; i++ {
Expand All @@ -44,10 +41,7 @@ func CubicBezier(x0, y0, x1, y1, x2, y2, x3, y3 float64) []Point {
l := (math.Hypot(x1-x0, y1-y0) +
math.Hypot(x2-x1, y2-y1) +
math.Hypot(x3-x2, y3-y2))
n := int(l + 0.5)
if n < 4 {
n = 4
}
n := max(int(l+0.5), 4)
d := float64(n) - 1
result := make([]Point, n)
for i := 0; i < n; i++ {
Expand Down
4 changes: 2 additions & 2 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ func (dc *Context) DrawRoundedRectangle(x, y, w, h, r float64) {

func (dc *Context) DrawEllipticalArc(x, y, rx, ry, angle1, angle2 float64) {
const n = 16
for i := 0; i < n; i++ {
for i := range n {
p1 := float64(i+0) / n
p2 := float64(i+1) / n
a1 := angle1 + (angle2-angle1)*p1
Expand Down Expand Up @@ -646,7 +646,7 @@ func (dc *Context) DrawRegularPolygon(n int, x, y, r, rotation float64) {
rotation += angle / 2
}
dc.NewSubPath()
for i := 0; i < n; i++ {
for i := range n {
a := rotation + angle*float64(i)
dc.LineTo(x+r*math.Cos(a), y+r*math.Sin(a))
}
Expand Down
20 changes: 10 additions & 10 deletions context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func TestLines(t *testing.T) {
dc.SetRGB(0.5, 0.5, 0.5)
dc.Clear()
rnd := rand.New(rand.NewSource(99))
for i := 0; i < 100; i++ {
for range 100 {
x1 := rnd.Float64() * 100
y1 := rnd.Float64() * 100
x2 := rnd.Float64() * 100
Expand All @@ -79,7 +79,7 @@ func TestCircles(t *testing.T) {
dc.SetRGB(1, 1, 1)
dc.Clear()
rnd := rand.New(rand.NewSource(99))
for i := 0; i < 10; i++ {
for range 10 {
x := rnd.Float64() * 100
y := rnd.Float64() * 100
r := rnd.Float64()*10 + 5
Expand All @@ -99,7 +99,7 @@ func TestQuadratic(t *testing.T) {
dc.SetRGB(0.25, 0.25, 0.25)
dc.Clear()
rnd := rand.New(rand.NewSource(99))
for i := 0; i < 100; i++ {
for range 100 {
x1 := rnd.Float64() * 100
y1 := rnd.Float64() * 100
x2 := rnd.Float64() * 100
Expand All @@ -121,7 +121,7 @@ func TestCubic(t *testing.T) {
dc.SetRGB(0.75, 0.75, 0.75)
dc.Clear()
rnd := rand.New(rand.NewSource(99))
for i := 0; i < 100; i++ {
for range 100 {
x1 := rnd.Float64() * 100
y1 := rnd.Float64() * 100
x2 := rnd.Float64() * 100
Expand All @@ -145,9 +145,9 @@ func TestFill(t *testing.T) {
dc.SetRGB(1, 1, 1)
dc.Clear()
rnd := rand.New(rand.NewSource(99))
for i := 0; i < 10; i++ {
for range 10 {
dc.NewSubPath()
for j := 0; j < 10; j++ {
for range 10 {
x := rnd.Float64() * 100
y := rnd.Float64() * 100
dc.LineTo(x, y)
Expand All @@ -167,7 +167,7 @@ func TestClip(t *testing.T) {
dc.DrawCircle(50, 50, 40)
dc.Clip()
rnd := rand.New(rand.NewSource(99))
for i := 0; i < 1000; i++ {
for range 1000 {
x := rnd.Float64() * 100
y := rnd.Float64() * 100
r := rnd.Float64()*10 + 5
Expand Down Expand Up @@ -230,8 +230,8 @@ func TestSetPixel(t *testing.T) {
dc.Clear()
dc.SetRGB(0, 1, 0)
i := 0
for y := 0; y < 100; y++ {
for x := 0; x < 100; x++ {
for y := range 100 {
for x := range 100 {
if i%31 == 0 {
dc.SetPixel(x, y)
}
Expand Down Expand Up @@ -289,7 +289,7 @@ func TestDashes(t *testing.T) {
dc.SetRGB(1, 1, 1)
dc.Clear()
rnd := rand.New(rand.NewSource(99))
for i := 0; i < 100; i++ {
for range 100 {
x1 := rnd.Float64() * 100
y1 := rnd.Float64() * 100
x2 := rnd.Float64() * 100
Expand Down
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
module github.com/cloudtrust/gg

go 1.25.0

toolchain go1.26.6
go 1.27.0

require (
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0
Expand Down
4 changes: 2 additions & 2 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"image/jpeg"
_ "image/jpeg"
"image/png"
"io/ioutil"

"math"
"os"
"strings"
Expand Down Expand Up @@ -130,7 +130,7 @@ func unfix(x fixed.Int26_6) float64 {
// You can usually just use the Context.LoadFontFace function instead of
// this package-level function.
func LoadFontFace(path string, points float64) (font.Face, error) {
fontBytes, err := ioutil.ReadFile(path)
fontBytes, err := os.ReadFile(path)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion wrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func splitOnSpace(x string) []string {

func wordWrap(m measureStringer, s string, width float64) []string {
var result []string
for _, line := range strings.Split(s, "\n") {
for line := range strings.SplitSeq(s, "\n") {
fields := splitOnSpace(line)
if len(fields)%2 == 1 {
fields = append(fields, "")
Expand Down