Skip to content

Commit a0bbae6

Browse files
committed
vector: bug fix: paths were unexpectedly clipped
Closes #3357
1 parent 353b07a commit a0bbae6

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

vector/atlas.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ func (a *atlas) setPaths(dstBounds image.Rectangle, paths []*Path, antialias boo
104104
var currentPosition image.Point
105105
for i := range a.atlasRegions {
106106
pb := a.pathRenderingBounds[a.atlasRegions[i].pathIndex]
107+
// TODO: What if s already exceeds maxImageSize (#3357)?
107108
s := pb.Size()
108109
// An additional image for antialiasing must be on the same atlas,
109110
// so extend the width and use it as a sub image.
@@ -113,15 +114,14 @@ func (a *atlas) setPaths(dstBounds image.Rectangle, paths []*Path, antialias boo
113114
if i == 0 {
114115
currentRowHeight = s.Y
115116
} else if currentPosition.X+s.X > maxImageSize {
117+
// Try the next row.
116118
currentPosition.X = 0
119+
currentPosition.Y += currentRowHeight
117120
if currentPosition.Y+s.Y > maxImageSize {
118121
atlasImageIndex++
119122
a.atlasSizes = append(a.atlasSizes, image.Point{})
120123
currentPosition.Y = 0
121-
} else {
122-
currentPosition.Y += currentRowHeight
123124
}
124-
currentRowHeight = s.Y
125125
}
126126
a.atlasRegions[i].imageIndex = atlasImageIndex
127127
a.atlasRegions[i].imageBounds = image.Rectangle{

vector/util_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,3 +196,32 @@ func TestFillPathSubImageAndImage(t *testing.T) {
196196
}
197197
}
198198
}
199+
200+
// Issue #3357
201+
func TestFillRects(t *testing.T) {
202+
dsts := []*ebiten.Image{
203+
ebiten.NewImage(1920, 1080),
204+
ebiten.NewImage(1920, 1080),
205+
}
206+
for _, dst := range dsts {
207+
defer dst.Deallocate()
208+
}
209+
210+
for i, antialias := range []bool{true, false} {
211+
dst := dsts[i]
212+
vector.FillRect(dst, 593, -609, 1144, 1969, color.RGBA{0x10, 0x00, 0x00, 0x10}, antialias)
213+
vector.FillRect(dst, 613, -146, 1124, 446, color.RGBA{0x10, 0x00, 0x00, 0x10}, antialias)
214+
vector.FillRect(dst, 634, -80, 1103, 190, color.RGBA{0x10, 0x00, 0x00, 0x10}, antialias)
215+
vector.FillRect(dst, 634, 110, 1103, 190, color.RGBA{0x10, 0x00, 0x00, 0x10}, antialias)
216+
vector.FillRect(dst, 613, 300, 1124, 998, color.RGBA{0x10, 0x00, 0x00, 0x10}, antialias)
217+
vector.FillRect(dst, 634, 433, 1104, 865, color.RGBA{0x10, 0x00, 0x00, 0x10}, antialias)
218+
vector.FillRect(dst, 654, 495, 1084, 741, color.RGBA{0x10, 0x00, 0x00, 0x10}, antialias)
219+
vector.FillRect(dst, 674, 592, 1063, 644, color.RGBA{0x10, 0x00, 0x00, 0x10}, antialias)
220+
}
221+
222+
got := dsts[0].At(800, 0)
223+
want := dsts[1].At(800, 0)
224+
if got != want {
225+
t.Errorf("got: %v, want: %v", got, want)
226+
}
227+
}

0 commit comments

Comments
 (0)