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

Ellipse/Circle thickness with fill=false is broken #71

Open
elronayellin opened this issue Aug 18, 2022 · 1 comment
Open

Ellipse/Circle thickness with fill=false is broken #71

elronayellin opened this issue Aug 18, 2022 · 1 comment

Comments

@elronayellin
Copy link

eg:

img = zeros(RGB, (200,200));
draw(img, Ellipse(100, 100, 100, 100; thickness=29, fill=false), RGB(1,1,0))

will not draw anything because the code is using a bogus normalized distance for the inner ellipse.

@ndgnuh
Copy link

ndgnuh commented Nov 9, 2022

Quick workaround for circles:

function circle!(image, x0, y0, rad, color; thickness=1)
	rad2 = rad^2
	for d1 in -rad:rad
		d2 = trunc(Int, sqrt(rad2 - d1^2))
		ImageDraw.drawifinbounds!(image, CartesianIndex(x0 + d1, y0 + d2), color)
		ImageDraw.drawifinbounds!(image, CartesianIndex(x0 + d1, y0 - d2), color)
		ImageDraw.drawifinbounds!(image, CartesianIndex(x0 + d2, y0 + d1), color)
		ImageDraw.drawifinbounds!(image, CartesianIndex(x0 - d2, y0 + d1), color)
	end
	if thickness > 1
		delta = trunc(Int, thickness / 2)
		drange = ((-delta + (thickness + 1) % 2):delta)

		for d in drange
			circle!(image, x0, y0, rad + d, color; thickness=1)
		end
	end
	image
end

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

2 participants