From 85b71a91a3d60d708898a6aeb47337575a6b72d2 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Sat, 1 Jul 2023 03:18:31 -0400 Subject: [PATCH] Fix stretched shapes --- plot.go | 2 +- polygon.go | 2 +- rectangle.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/plot.go b/plot.go index 3e46afd..8e8d27f 100644 --- a/plot.go +++ b/plot.go @@ -23,7 +23,7 @@ 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 + index := y * context.stride + x * context.width + context.offset context.data[index] = context.color }} } diff --git a/polygon.go b/polygon.go index 3af4b8f..02e5f5e 100644 --- a/polygon.go +++ b/polygon.go @@ -65,7 +65,7 @@ func (this Image[T]) FillPolygon (fill []T, points ...image.Point) { for offset, part := range fill { for x := left; x < right; x ++ { index := - (y * this.Stride + x) * + y * this.Stride + x * this.Width + offset this.Pix[index] = part } diff --git a/rectangle.go b/rectangle.go index ae93dbe..437cd25 100644 --- a/rectangle.go +++ b/rectangle.go @@ -11,7 +11,7 @@ func (this Image[T]) FillRectangle (fill []T, rectangle image.Rectangle) { for pos.Y = rectangle.Min.Y; pos.Y < rectangle.Max.Y; pos.Y ++ { for offset, part := range fill { for pos.X = rectangle.Min.X; pos.X < rectangle.Max.X; pos.X ++ { - index := (pos.Y * this.Stride + pos.X) * this.Width + offset + index := pos.Y * this.Stride + pos.X * this.Width + offset this.Pix[index] = part }}} }