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

force specialization on argument f::Function #114

Merged
merged 1 commit into from
Jan 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/background.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ struct Background <: AbstractShape end

get_drawing_optimization_style(::Background) = PUT_PIXEL_UNCHECKED

function draw!(f::Function, image::AbstractMatrix, shape::Background, color)
function draw!(f::F, image::AbstractMatrix, shape::Background, color) where {F <: Function}
for j in axes(image, 2)
for i in axes(image, 1)
f(image, i, j, color)
Expand Down
2 changes: 1 addition & 1 deletion src/bitmap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ end

get_drawing_optimization_style(::Bitmap) = CLIP

function draw!(f::Function, image::AbstractMatrix, shape::Bitmap, color)
function draw!(f::F, image::AbstractMatrix, shape::Bitmap, color) where {F <: Function}
position = shape.position
bitmap = shape.bitmap

Expand Down
2 changes: 1 addition & 1 deletion src/character.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function draw!(image::AbstractMatrix, shape::Character{I, C, Terminus_32_16} whe
return nothing
end

function draw!(f::Function, image::AbstractMatrix, shape::Character{I, C, Terminus_32_16} where {I, C}, color)
function draw!(f::F, image::AbstractMatrix, shape::Character{I, C, Terminus_32_16} where {I, C}, color) where {F <: Function}
@assert is_valid(shape) "Cannot draw invalid shape $(shape)"

position = shape.position
Expand Down
22 changes: 11 additions & 11 deletions src/circle.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ get_drawing_optimization_style(::AbstractCircleOctant) = CHECK_BOUNDS
##### CircleOctant
#####

function draw!(f::Function, image::AbstractMatrix, shape::CircleOctant, color)
function draw!(f::F, image::AbstractMatrix, shape::CircleOctant, color) where {F <: Function}
@assert is_valid(shape) "Cannot draw invalid shape $(shape)"

center = shape.center
Expand Down Expand Up @@ -142,7 +142,7 @@ function draw!(image::AbstractMatrix, shape::ThickCircleOctant, color)
return nothing
end

function draw!(f::Function, image::AbstractMatrix, shape::ThickCircleOctant, color)
function draw!(f::F, image::AbstractMatrix, shape::ThickCircleOctant, color) where {F <: Function}
@assert is_valid(shape) "Cannot draw invalid shape $(shape)"

center = shape.center
Expand Down Expand Up @@ -237,7 +237,7 @@ get_drawing_optimization_style(::AbstractCircle) = CHECK_BOUNDS

is_valid(shape::OddCircle) = isodd(shape.diameter) && shape.diameter > zero(shape.diameter)

function draw!(f::Function, image::AbstractMatrix, shape::OddCircle, color)
function draw!(f::F, image::AbstractMatrix, shape::OddCircle, color) where {F <: Function}
@assert is_valid(shape) "Cannot draw invalid shape $(shape)"

center, radius = get_center_radius(shape)
Expand All @@ -255,7 +255,7 @@ end

is_valid(shape::EvenCircle) = iseven(shape.diameter) && shape.diameter > zero(shape.diameter)

function draw!(f::Function, image::AbstractMatrix, shape::EvenCircle, color)
function draw!(f::F, image::AbstractMatrix, shape::EvenCircle, color) where {F <: Function}
@assert is_valid(shape) "Cannot draw invalid shape $(shape)"

center, radius = get_center_radius(shape)
Expand Down Expand Up @@ -286,7 +286,7 @@ function draw!(image::AbstractMatrix, shape::Circle, color)
return nothing
end

function draw!(f::Function, image::AbstractMatrix, shape::Circle, color)
function draw!(f::F, image::AbstractMatrix, shape::Circle, color) where {F <: Function}
@assert is_valid(shape) "Cannot draw invalid shape $(shape)"

position = shape.position
Expand All @@ -307,7 +307,7 @@ end

is_valid(shape::OddFilledCircle) = is_valid(OddCircle(shape.position, shape.diameter))

function draw!(f::Function, image::AbstractMatrix, shape::OddFilledCircle, color)
function draw!(f::F, image::AbstractMatrix, shape::OddFilledCircle, color) where {F <: Function}
@assert is_valid(shape) "Cannot draw invalid shape $(shape)"

center, radius = get_center_radius(shape)
Expand All @@ -325,7 +325,7 @@ end

is_valid(shape::EvenFilledCircle) = is_valid(EvenCircle(shape.position, shape.diameter))

function draw!(f::Function, image::AbstractMatrix, shape::EvenFilledCircle, color)
function draw!(f::F, image::AbstractMatrix, shape::EvenFilledCircle, color) where {F <: Function}
@assert is_valid(shape) "Cannot draw invalid shape $(shape)"

position = shape.position
Expand Down Expand Up @@ -372,7 +372,7 @@ function draw!(image::AbstractMatrix, shape::FilledCircle, color)
return nothing
end

function draw!(f::Function, image::AbstractMatrix, shape::FilledCircle, color)
function draw!(f::F, image::AbstractMatrix, shape::FilledCircle, color) where {F <: Function}
@assert is_valid(shape) "Cannot draw invalid shape $(shape)"

position = shape.position
Expand Down Expand Up @@ -400,7 +400,7 @@ function is_valid(shape::OddThickCircle)
return isodd(diameter) && diameter > zero(I) && thickness > zero(I) && convert(I, 2) * thickness <= diameter + one(I)
end

function draw!(f::Function, image::AbstractMatrix, shape::OddThickCircle, color)
function draw!(f::F, image::AbstractMatrix, shape::OddThickCircle, color) where {F <: Function}
@assert is_valid(shape) "Cannot draw invalid shape $(shape)"

thickness = shape.thickness
Expand All @@ -427,7 +427,7 @@ function is_valid(shape::EvenThickCircle)
return iseven(diameter) && diameter > zero(I) && thickness > zero(I) && convert(I, 2) * thickness <= diameter
end

function draw!(f::Function, image::AbstractMatrix, shape::EvenThickCircle, color)
function draw!(f::F, image::AbstractMatrix, shape::EvenThickCircle, color) where {F <: Function}
@assert is_valid(shape) "Cannot draw invalid shape $(shape)"

thickness = shape.thickness
Expand Down Expand Up @@ -473,7 +473,7 @@ function draw!(image::AbstractMatrix, shape::ThickCircle, color)
return nothing
end

function draw!(f::Function, image::AbstractMatrix, shape::ThickCircle, color)
function draw!(f::F, image::AbstractMatrix, shape::ThickCircle, color) where {F <: Function}
@assert is_valid(shape) "Cannot draw invalid shape $(shape)"

position = shape.position
Expand Down
8 changes: 4 additions & 4 deletions src/line.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ clip(image::AbstractMatrix, shape::VerticalLine) = VerticalLine(max(get_i_min(sh

get_drawing_optimization_style(::VerticalLine) = CLIP

function draw!(f::Function, image::AbstractMatrix, shape::VerticalLine, color)
function draw!(f::F, image::AbstractMatrix, shape::VerticalLine, color) where {F <: Function}
@assert is_valid(shape) "Cannot draw invalid shape $(shape)"

i_min = shape.i_min
Expand Down Expand Up @@ -69,7 +69,7 @@ clip(image::AbstractMatrix, shape::HorizontalLine) = HorizontalLine(shape.i, max

get_drawing_optimization_style(::HorizontalLine) = CLIP

function draw!(f::Function, image::AbstractMatrix, shape::HorizontalLine, color)
function draw!(f::F, image::AbstractMatrix, shape::HorizontalLine, color) where {F <: Function}
@assert is_valid(shape) "Cannot draw invalid shape $(shape)"

i = shape.i
Expand Down Expand Up @@ -97,7 +97,7 @@ get_j_extrema(shape::Line) = minmax(shape.point1.j, shape.point2.j)

get_drawing_optimization_style(::Line) = CHECK_BOUNDS

function draw!(f::Function, image::AbstractMatrix, shape::Line, color)
function draw!(f::F, image::AbstractMatrix, shape::Line, color) where {F <: Function}
point1 = shape.point1
point2 = shape.point2

Expand Down Expand Up @@ -183,7 +183,7 @@ end

get_drawing_optimization_style(::ThickLine) = CHECK_BOUNDS

function draw!(f::Function, image::AbstractMatrix, shape::ThickLine, color)
function draw!(f::F, image::AbstractMatrix, shape::ThickLine, color) where {F <: Function}
@assert is_valid(shape) "Cannot draw invalid shape $(shape)"

point1 = shape.point1
Expand Down
2 changes: 1 addition & 1 deletion src/point.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ get_j_max(shape::Point) = shape.j

get_drawing_optimization_style(::Point) = PUT_PIXEL

function draw!(f::Function, image::AbstractMatrix, shape::Point, color)
function draw!(f::F, image::AbstractMatrix, shape::Point, color) where {F <: Function}
f(image, shape.i, shape.j, color)
return nothing
end
6 changes: 3 additions & 3 deletions src/rectangle.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ get_drawing_optimization_style(::AbstractRectangle) = CHECK_BOUNDS
##### Rectangle
#####

function draw!(f::Function, image::AbstractMatrix, shape::Rectangle, color)
function draw!(f::F, image::AbstractMatrix, shape::Rectangle, color) where {F <: Function}
@assert is_valid(shape) "Cannot draw invalid shape $(shape)"

i_min, i_max = get_i_extrema(shape)
Expand Down Expand Up @@ -75,7 +75,7 @@ end

get_drawing_optimization_style(::FilledRectangle) = CLIP

function draw!(f::Function, image::AbstractMatrix, shape::FilledRectangle, color)
function draw!(f::F, image::AbstractMatrix, shape::FilledRectangle, color) where {F <: Function}
@assert is_valid(shape) "Cannot draw invalid shape $(shape)"

i_min, i_max = get_i_extrema(shape)
Expand Down Expand Up @@ -104,7 +104,7 @@ function is_valid(shape::ThickRectangle)
return height > zero(I) && width > zero(I) && thickness > zero(I) && thickness <= min(height, width)
end

function draw!(f::Function, image::AbstractMatrix, shape::ThickRectangle, color)
function draw!(f::F, image::AbstractMatrix, shape::ThickRectangle, color) where {F <: Function}
@assert is_valid(shape) "Cannot draw invalid shape $(shape)"

position = shape.position
Expand Down
12 changes: 6 additions & 6 deletions src/symmetry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ function get_j_extrema(shape::OddOctantSymmetricShape)
return (min(get_j_min(generator), get_j_min(generator_reflected)), max(get_j_max(generator), get_j_max(generator_reflected)))
end

function draw!(f::Function, image::AbstractMatrix, shape::OddOctantSymmetricShape{I, Point{I}}, color) where {I}
function draw!(f::F, image::AbstractMatrix, shape::OddOctantSymmetricShape{I, Point{I}}, color) where {F <: Function, I}
@assert is_valid(shape) "Cannot draw invalid shape $(shape)"

origin = shape.origin
Expand All @@ -129,7 +129,7 @@ function draw!(f::Function, image::AbstractMatrix, shape::OddOctantSymmetricShap
return nothing
end

function draw!(f::Function, image::AbstractMatrix, shape::OddOctantSymmetricShape{I, VerticalLine{I}}, color) where {I}
function draw!(f::F, image::AbstractMatrix, shape::OddOctantSymmetricShape{I, VerticalLine{I}}, color) where {F <: Function, I}
@assert is_valid(shape) "Cannot draw invalid shape $(shape)"

origin = shape.origin
Expand Down Expand Up @@ -204,7 +204,7 @@ function get_j_extrema(shape::EvenOctantSymmetricShape)
return (min(get_j_min(generator), get_j_min(generator_reflected)), max(get_j_max(generator), get_j_max(generator_reflected)))
end

function draw!(f::Function, image::AbstractMatrix, shape::EvenOctantSymmetricShape{I, Point{I}}, color) where {I}
function draw!(f::F, image::AbstractMatrix, shape::EvenOctantSymmetricShape{I, Point{I}}, color) where {F <: Function, I}
@assert is_valid(shape) "Cannot draw invalid shape $(shape)"

origin = shape.origin
Expand All @@ -230,7 +230,7 @@ function draw!(f::Function, image::AbstractMatrix, shape::EvenOctantSymmetricSha
return nothing
end

function draw!(f::Function, image::AbstractMatrix, shape::EvenOctantSymmetricShape{I, VerticalLine{I}}, color) where {I}
function draw!(f::F, image::AbstractMatrix, shape::EvenOctantSymmetricShape{I, VerticalLine{I}}, color) where {F <: Function, I}
@assert is_valid(shape) "Cannot draw invalid shape $(shape)"

origin = shape.origin
Expand Down Expand Up @@ -291,7 +291,7 @@ function get_j_extrema(shape::OddSymmetricVerticalLines4)
return (get_odd_reflection_vertical_line(diagonally_reflected_point, shape.origin.j).j, diagonally_reflected_point.j)
end

function draw!(f::Function, image::AbstractMatrix, shape::OddSymmetricVerticalLines4, color)
function draw!(f::F, image::AbstractMatrix, shape::OddSymmetricVerticalLines4, color) where {F <: Function}
@assert is_valid(shape) "Cannot draw invalid shape $(shape)"

origin = shape.origin
Expand Down Expand Up @@ -345,7 +345,7 @@ function get_j_extrema(shape::EvenSymmetricVerticalLines4)
return (get_even_reflection_vertical_line(diagonally_reflected_point, shape.origin.j).j, diagonally_reflected_point.j)
end

function draw!(f::Function, image::AbstractMatrix, shape::EvenSymmetricVerticalLines4, color)
function draw!(f::F, image::AbstractMatrix, shape::EvenSymmetricVerticalLines4, color) where {F <: Function}
@assert is_valid(shape) "Cannot draw invalid shape $(shape)"

origin = shape.origin
Expand Down
2 changes: 1 addition & 1 deletion src/text.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ is_valid(shape::TextLine) = all(x -> has_char(shape.font, x), shape.text)

get_drawing_optimization_style(::TextLine) = PUT_PIXEL

function draw!(f::Function, image::AbstractMatrix, shape::TextLine, color)
function draw!(f::F, image::AbstractMatrix, shape::TextLine, color) where {F <: Function}
@assert is_valid(shape) "Cannot draw invalid shape $(shape)"

position = shape.position
Expand Down