Fix stretched shapes

This commit is contained in:
Sasha Koshka 2023-07-01 03:18:31 -04:00
parent 70a8567646
commit 85b71a91a3
3 changed files with 3 additions and 3 deletions

View File

@ -23,7 +23,7 @@ func (context plottingContext[T]) plot (center image.Point) {
square := context.square(center) square := context.square(center)
for y := square.Min.Y; y < square.Max.Y; y ++ { for y := square.Min.Y; y < square.Max.Y; y ++ {
for x := square.Min.X; x < square.Max.X; x ++ { 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 context.data[index] = context.color
}} }}
} }

View File

@ -65,7 +65,7 @@ func (this Image[T]) FillPolygon (fill []T, points ...image.Point) {
for offset, part := range fill { for offset, part := range fill {
for x := left; x < right; x ++ { for x := left; x < right; x ++ {
index := index :=
(y * this.Stride + x) * y * this.Stride + x *
this.Width + offset this.Width + offset
this.Pix[index] = part this.Pix[index] = part
} }

View File

@ -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 pos.Y = rectangle.Min.Y; pos.Y < rectangle.Max.Y; pos.Y ++ {
for offset, part := range fill { for offset, part := range fill {
for pos.X = rectangle.Min.X; pos.X < rectangle.Max.X; pos.X ++ { 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 this.Pix[index] = part
}}} }}}
} }