Skip to content

Commit

Permalink
fix #78 (#79)
Browse files Browse the repository at this point in the history
* fix #78

* replaced tabs with spaces

* fixed to 4 spaces
  • Loading branch information
yakir12 authored Dec 12, 2023
1 parent 8b2a4f1 commit 79008c3
Showing 1 changed file with 18 additions and 22 deletions.
40 changes: 18 additions & 22 deletions src/ellipse2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,22 @@ Ellipse(p::CartesianIndex{2}, args...; kwargs...) = Ellipse(Point(p), args...; k
Ellipse(circle::CirclePointRadius) = Ellipse(circle.center, circle.ρ, circle.ρ; thickness = circle.thickness, fill = circle.fill)

function draw!(img::AbstractArray{T, 2}, ellipse::Ellipse, color::T) where T<:Colorant
ys = Int[]
xs = Int[]
break_point = 0
if ellipse.fill == false
break_point = ((ellipse.ρy - ellipse.thickness) / ellipse.ρy) ^ 2 + ((ellipse.ρx - ellipse.thickness) / ellipse.ρx) ^ 2
end
for i in ellipse.center.y : ellipse.center.y + ellipse.ρy
for j in ellipse.center.x : ellipse.center.x + ellipse.ρx
val = ((i - ellipse.center.y) / ellipse.ρy) ^ 2 + ((j - ellipse.center.x) / ellipse.ρx) ^ 2
if val < 1 && val >= break_point
push!(ys, i)
push!(xs, j)
end
end
end
for (yi, xi) in zip(ys, xs)
drawifinbounds!(img, yi, xi, color)
drawifinbounds!(img, 2 * ellipse.center.y - yi, xi, color)
drawifinbounds!(img, yi, 2 * ellipse.center.x - xi, color)
drawifinbounds!(img, 2 * ellipse.center.y - yi, 2 * ellipse.center.x - xi, color)
end
img
break_point = 0
if ellipse.fill == false
break_point = ((ellipse.ρy - ellipse.thickness) / ellipse.ρy) ^ 2 + ((ellipse.ρx - ellipse.thickness) / ellipse.ρx) ^ 2
end
for i in ellipse.center.y : ellipse.center.y + ellipse.ρy
for j in ellipse.center.x : ellipse.center.x + ellipse.ρx
val = ((i - ellipse.center.y) / ellipse.ρy) ^ 2 + ((j - ellipse.center.x) / ellipse.ρx) ^ 2
if val < 1 && val >= break_point
yi = Int(i)
xi = Int(j)
drawifinbounds!(img, yi, xi, color)
drawifinbounds!(img, 2 * ellipse.center.y - yi, xi, color)
drawifinbounds!(img, yi, 2 * ellipse.center.x - xi, color)
drawifinbounds!(img, 2 * ellipse.center.y - yi, 2 * ellipse.center.x - xi, color)
end
end
end
img
end

0 comments on commit 79008c3

Please sign in to comment.