JuliaImages / ImageDraw.jl

Drawing Package for JuliaImages
Other
27 stars 17 forks source link

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

Open elronayellin opened 2 years ago

elronayellin commented 2 years ago

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 commented 1 year ago

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