ggfx/plot.go

30 lines
719 B
Go

package ggfx
import "image"
type plottingContext[T any] struct {
data []T
stride int
color T
weight int
bounds image.Rectangle
width int
offset int
}
func (context plottingContext[T]) square (center image.Point) (square image.Rectangle) {
return image.Rect(0, 0, context.weight, context.weight).
Sub(image.Pt(context.weight / 2, context.weight / 2)).
Add(center).
Intersect(context.bounds)
}
func (context plottingContext[T]) plot (center image.Point) {
square := context.square(center)
for y := square.Min.Y; y < square.Max.Y; y ++ {
for x := square.Min.X; x < square.Max.X; x ++ {
index := y * context.stride + x * context.width + context.offset
context.data[index] = context.color
}}
}