Skip to content

Modernize gfx#6

Merged
peterhellberg merged 28 commits into
masterfrom
modernize-gfx
May 28, 2026
Merged

Modernize gfx#6
peterhellberg merged 28 commits into
masterfrom
modernize-gfx

Conversation

@peterhellberg

@peterhellberg peterhellberg commented May 28, 2026

Copy link
Copy Markdown
Owner

Modernization pass though the gfx package, extracted HTTP related code into its own package (gfxhttp).

Will hopefully address what is asked for in #5

Important

⚠️ NO STABILITY GUARANTEES ⚠️

This package is just something I've made for fun.

Breaking API changes (require code edits at call sites)

Removed from root gfx — moved to new gfxhttp subpackage:

  • gfx.HTTP (type)
  • gfx.HTTPClient (var)
  • gfx.Get, gfx.GetPNG, gfx.GetImage, gfx.GetTileset
  • gfx.GeoTileServer (type)
  • gfx.GTS (constructor)
  • gfx.GeoTileServer.{GetImage, DrawTile, DrawNeighbors, DrawTileAndNeighbors}
  • gfx.GeoTile.GetImage (method on still-present GeoTile)

Replacement: import "github.com/peterhellberg/gfx/gfxhttp"

Renamed:

  • gfx.DrawCicleFast → gfx.DrawCircleFast (typo fix; no alias kept)

Signature changes:

  • gfx.SortSlice(slice any, less func(i, j int) bool)
    gfx.SortSlice[S ~[]E, E any](s S, cmp func(a, b E) int).
    • Comparator switched from index-based bool to element-pair cmp.Compare-style int
      (matches slices.SortFunc).
  • gfx.Sign, gfx.Clamp, gfx.Lerp are now generic on new gfx.Numeric /
    gfx.Signed constraints (or cmp.Ordered for Clamp).
    Float64 callers keep working via type inference.
    • Watch-out: gfx.Lerp(0, 2, 0.1) (untyped int literals) now infers T = int
      and returns 0. Pass float literals or gfx.Lerp[float64](...).
    • Anyone who captured one of these as a function value (f := gfx.Sign) now needs to
      instantiate (f := gfx.Sign[float64]).

Module floor:

  • go.mod raised from go 1.17 to go 1.25. Consumers must use Go 1.25 or newer.

Changes

  • go: Bump versions to current supported versions 1.25.x and 1.26.x
  • rand: Replaced the deprecated rand.Seed call with a package-level *rand.Rand
  • palette: Palette.Random now calls gfx.RandIntn instead of rand.Intn
  • draw: Replaced the m.X != w / m.Y != h termination with r.Min.X < r.Max.X / r.Min.Y < r.Max.Y in both DrawPalettedImage and DrawPalettedLayer
  • draw: Renamed DrawCicleFastDrawCircleFast
  • gfx: Replace interface{} with any
  • draw_int: Removed bare return statements in DrawIntRectangle and DrawIntFilledRectangle
  • image: Replaced the per-pixel DrawColorOver path with an inline premultiplied-alpha blend
  • gfx: Moved HTTP related code into new gfxhttp package
  • gfxhttp: Thread context.Context through all requests
  • math: Make Sign, Clamp, and Lerp generic via new Numeric, Signed, and cmp.Ordered constraints
  • sort: Replace SortSlice reflection wrapper with generic slices.SortFunc-backed implementation
  • license: Update copyright year
  • doc: Update copyright year
  • examples: Update examples
  • block: Color every vertex in Block.Triangles so faces render uniformly instead of partially black
  • triangle: Round Triangle.Bounds Max up so adjacent triangles meet without gaps and right/bottom edge pixels aren't skipped
  • paletted: Honor Rect.Min in Paletted.PixOffset so non-origin Paletted images index Pix correctly
  • gfx: Drop legacy // +build directives now that go.mod is on Go 1.25
  • examples: Use gfx.V and keyed SignedDistance literals to satisfy go vet, and re-embed README snippets
  • gfx: Modernize counted for loops to range-over-int (go fix)
  • examples/gfx-example-animation: Slice 5 palette colors so the flower stem renders instead of falling back to the background
  • draw: Use the triangle's first vertex color in DrawTrianglesWireframe instead of looking up the color at world origin
  • paletted: Bounds-check ColorIndexAt and SetColorIndex so out-of-range coordinates return 0 / no-op instead of panicking
  • block: Round Block.DrawBounds Max up so fractional Rect edges don't lose a column or row to int() truncation
  • gfxhttp: Add tests for raw Get response, GetImage decode path, WithHTTPClient(nil) no-op, and TileServer.DrawTile
  • doc: List WithHeader alongside the other gfxhttp options
  • gfx: Drop !tinygo build constraints from files whose imports TinyGo now supports (hopefully)

@peterhellberg peterhellberg self-assigned this May 28, 2026
…ax.X / r.Min.Y < r.Max.Y in both DrawPalettedImage and DrawPalettedLayer
…hout gaps and right/bottom edge pixels aren't skipped
@peterhellberg peterhellberg merged commit def0a2c into master May 28, 2026
2 checks passed
@peterhellberg peterhellberg deleted the modernize-gfx branch May 28, 2026 18:55
@peterhellberg peterhellberg mentioned this pull request May 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant