Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More Optimized Stroke Text #203

Open
alaninnovates opened this issue Feb 3, 2025 · 0 comments
Open

More Optimized Stroke Text #203

alaninnovates opened this issue Feb 3, 2025 · 0 comments

Comments

@alaninnovates
Copy link

alaninnovates commented Feb 3, 2025

In the example given in the meme.go demonstration for text with stroke width, the code inefficiently loops in an O(n^2) loop.

gg/examples/meme.go

Lines 15 to 26 in 8febc0f

n := 6 // "stroke" size
for dy := -n; dy <= n; dy++ {
for dx := -n; dx <= n; dx++ {
if dx*dx+dy*dy >= n*n {
// give it rounded corners
continue
}
x := S/2 + float64(dx)
y := S/2 + float64(dy)
dc.DrawStringAnchored(s, x, y, 0.5, 0.5)
}
}

In this case, when n=6, the maximum iterations that this could use is (6*2)^2 = 144 calls to DrawStringAnchored! This is wildly inefficient and requires a lot of CPU power.

I am wondering if there is an alternative and less intensive way to create a similar text stroke effect, or if such a function could be added. Thanks!

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

No branches or pull requests

1 participant