-
Notifications
You must be signed in to change notification settings - Fork 16
Thickness and In Bounds check - keyword args #31
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
Open
Codyk12
wants to merge
16
commits into
JuliaImages:master
Choose a base branch
from
Codyk12:thickness
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
502d6a5
Added checkbounds() testing to all draw!() functions as to not throw …
Codyk12 40bda80
Changed Test Files to no longer check for Exception thrown for drawin…
Codyk12 de36083
Fixed spacing and deleted unnecessary code
Codyk12 d90b811
Merge remote-tracking branch 'upstream/master'
Codyk12 d84042d
Fix
Codyk12 108996c
Added ability to draw lines with thickness
Codyk12 f0b0b3b
Updated Version Number
Codyk12 8b2c592
Made in bounds and thickness into keyword args
Codyk12 ff5c7f9
Added keywords to multi drawable function
Codyk12 9e936c9
thickness changed to Union{Integer,Nothing}. Changed multiple object …
Codyk12 3c0b12e
Added thickness and in_bounds keyargs to draw() function. Fixed thick…
Codyk12 2a898cb
Adjusted default for in_bounds and thickness.
Codyk12 dc607a3
draw function more flexible without keyword args
Codyk12 33aebc7
Added thickness and in_bounds tests. Made draw logic more clear
Codyk12 f5cac40
Indent fix
Codyk12 2b9cb4f
Thickness algorithm takes care of thickness=1
Codyk12 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,8 +14,42 @@ struct Point <: Drawable | |
| y::Int | ||
| end | ||
|
|
||
| abstract type Line <: Drawable end | ||
| abstract type Circle <: Drawable end | ||
| abstract type AbstractPath <: Drawable end | ||
| abstract type AbstractLine <: Drawable end | ||
| abstract type AbstractShape <: Drawable end | ||
| abstract type AbstractBackground <: Drawable end | ||
|
|
||
|
|
||
| abstract type AbstractPolygon <: AbstractShape end | ||
| abstract type AbstractEllipse <: AbstractShape end | ||
| abstract type AbstractCircle <: AbstractEllipse end | ||
|
|
||
| """ | ||
| background = SolidBackground(color) | ||
|
|
||
| A `Drawable` background that will fill the 'background' of an image with | ||
| the set color | ||
| """ | ||
|
|
||
| struct SolidBackground{T<:Colorant} <: AbstractBackground | ||
| color::T | ||
| end | ||
|
|
||
| """ | ||
| background = StripedBackground(color) | ||
|
|
||
| A `Drawable` background that will fill the 'background' of an image with | ||
| the given colors at the intervals given at the given angle | ||
| """ | ||
|
|
||
| struct StripedBackground{T<:Colorant, U<:Real, V<:Real} <: AbstractBackground | ||
| colors::Vector{T} | ||
| distances::Vector{U} | ||
| θ::V | ||
| end | ||
|
|
||
|
|
||
| struct NoisyBackground <: AbstractBackground end | ||
|
|
||
|
|
||
| """ | ||
|
|
@@ -24,7 +58,7 @@ abstract type Circle <: Drawable end | |
| A `Drawable` infinite length line passing through the two points | ||
| `p1` and `p2`. | ||
| """ | ||
| struct LineTwoPoints <: Line | ||
| struct LineTwoPoints <: AbstractLine | ||
| p1::Point | ||
| p2::Point | ||
| end | ||
|
|
@@ -36,7 +70,7 @@ A `Drawable` infinte length line having perpendicular length `ρ` from | |
| origin and angle `θ` between the perpendicular and x-axis | ||
|
|
||
| """ | ||
| struct LineNormal{T<:Real, U<:Real} <: Line | ||
| struct LineNormal{T<:Real, U<:Real} <: AbstractLine | ||
| ρ::T | ||
| θ::U | ||
| end | ||
|
|
@@ -46,7 +80,7 @@ end | |
|
|
||
| A `Drawable` circle passing through points `p1`, `p2` and `p3` | ||
| """ | ||
| struct CircleThreePoints <: Circle | ||
| struct CircleThreePoints <: AbstractCircle | ||
| p1::Point | ||
| p2::Point | ||
| p3::Point | ||
|
|
@@ -57,7 +91,7 @@ end | |
|
|
||
| A `Drawable` circle having center `center` and radius `ρ` | ||
| """ | ||
| struct CirclePointRadius{T<:Real} <: Circle | ||
| struct CirclePointRadius{T<:Real} <: AbstractCircle | ||
| center::Point | ||
| ρ::T | ||
| end | ||
|
|
@@ -67,7 +101,7 @@ end | |
|
|
||
| A `Drawable` finite length line between `p1` and `p2` | ||
| """ | ||
| struct LineSegment <: Drawable | ||
| struct LineSegment <: AbstractLine | ||
| p1::Point | ||
| p2::Point | ||
| end | ||
|
|
@@ -80,7 +114,7 @@ of points in `[point]`. | |
| !!! note | ||
| This will create a non-closed path. For a closed path, see `Polygon` | ||
| """ | ||
| struct Path <: Drawable | ||
| struct Path <: AbstractPath | ||
| vertices::Vector{Point} | ||
| end | ||
|
|
||
|
|
@@ -90,7 +124,7 @@ end | |
| A `Drawable` ellipse with center `center` and parameters `ρx` and `ρy` | ||
|
|
||
| """ | ||
| struct Ellipse{T<:Real, U<:Real} <: Drawable | ||
| struct Ellipse{T<:Real, U<:Real} <: AbstractEllipse | ||
| center::Point | ||
| ρx::T | ||
| ρy::U | ||
|
|
@@ -104,7 +138,7 @@ consecutive points in `[vertex]` along with the first and last point. | |
| !!! note | ||
| This will create a closed path. For a non-closed path, see `Path` | ||
| """ | ||
| struct Polygon <: Drawable | ||
| struct Polygon <: AbstractPolygon | ||
| vertices::Vector{Point} | ||
| end | ||
|
|
||
|
|
@@ -120,7 +154,7 @@ A `Drawable` regular polygon. | |
| * `θ::Real` : orientation of the polygon w.r.t x-axis (in radians) | ||
|
|
||
| """ | ||
| struct RegularPolygon{T<:Real, U<:Real} <: Drawable | ||
| struct RegularPolygon{T<:Real, U<:Real} <: AbstractPolygon | ||
| center::Point | ||
| side_count::Int | ||
| side_length::T | ||
|
|
@@ -131,19 +165,31 @@ end | |
| cross = Cross(c, range::UnitRange{Int}) | ||
| A `Drawable` cross passing through the point `c` with arms ranging across `range`. | ||
| """ | ||
| struct Cross <: Drawable | ||
| struct Cross <: AbstractPath | ||
| c::Point | ||
| range::UnitRange{Int} | ||
| end | ||
|
|
||
| """ | ||
| img_map = ImageMap(img, x, y) | ||
|
|
||
| Overlays an image on an larger image. (x, y) is the center for placing the image | ||
| """ | ||
| struct ImageMap <: Drawable | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the usage of this? I can't find anywhere this struct is used in your PR. |
||
| image | ||
| x | ||
| y | ||
| end | ||
|
|
||
| """ | ||
| img = draw!(img, drawable, color) | ||
| img = draw!(img, drawable) | ||
|
|
||
| Draws `drawable` on `img` using color `color` which | ||
| defaults to `oneunit(eltype(img))` | ||
| """ | ||
| draw!(img::AbstractArray{T,2}, object::Drawable) where {T<:Colorant} = draw!(img, object, oneunit(T)) | ||
| draw!(img::AbstractArray{T,2}, object::Drawable; in_bounds::Bool=false, thickness::Integer=-1) where {T<:Colorant} = | ||
| draw!(img, object, oneunit(T), in_bounds=in_bounds, thickness=thickness) | ||
|
|
||
|
|
||
| """ | ||
|
|
@@ -156,12 +202,13 @@ corresponding colors from `[color]` which defaults to `oneunit(eltype(img))` | |
| If only a single color `color` is specified then all objects will be | ||
| colored with that color. | ||
|
Codyk12 marked this conversation as resolved.
Outdated
|
||
| """ | ||
| function draw!(img::AbstractArray{T,2}, objects::AbstractVector{U}, colors::AbstractVector{V}) where {T<:Colorant, U<:Drawable, V<:Colorant} | ||
| function draw!(img::AbstractArray{T,2}, objects::AbstractVector{U}, colors::AbstractVector{V}; in_bounds::AbstractVector{Bool}=[false], thickness::AbstractVector{<:Integer}=[-1]) where {T<:Colorant, U<:Drawable, V<:Colorant} | ||
| colors = copy(colors) | ||
| while length(colors) < length(objects) | ||
| push!(colors, oneunit(T)) | ||
| end | ||
| foreach((object, color) -> draw!(img, object, color), objects, colors) | ||
| while length(colors) < length(objects) push!(colors, oneunit(T)) end | ||
|
Codyk12 marked this conversation as resolved.
Outdated
|
||
| while length(in_bounds) < length(objects) push!(in_bounds, false) end | ||
| while length(thickness) < length(objects) push!(thickness, -1) end | ||
|
|
||
| foreach((object, color, in_b, thick) -> draw!(img, object, color), objects, colors, in_bounds, thickness) | ||
| img | ||
| end | ||
|
|
||
|
|
@@ -181,15 +228,24 @@ draw(img::AbstractArray{T,2}, args...) where {T<:Colorant} = draw!(copy(img), ar | |
| Point(τ::Tuple{Int, Int}) = Point(τ...) | ||
| Point(p::CartesianIndex) = Point(p[2], p[1]) | ||
|
|
||
| function draw!(img::AbstractArray{T,2}, point::Point, color::T) where T<:Colorant | ||
| drawifinbounds!(img, point, color) | ||
| # Base.convert(::Type{Point}, t::Tuple{Int, Int}) = Point(t...) | ||
| # Base.convert(::Type{Point}, p::CartesianIndex) = Point(p[2], p[1]) | ||
|
|
||
| draw!(img::AbstractArray{T,2}, p::Point, color::T = oneunit(T); in_bounds::Bool=false, thickness::Integer=-1) where {T<:Colorant} = | ||
| draw!(img, p.y, p.x, color, in_bounds=in_bounds, thickness=thickness) | ||
| draw!(img::AbstractArray{T,2}, p::CartesianIndex{2}, color::T = oneunit(T); in_bounds::Bool=false, thickness::Integer=-1) where {T<:Colorant} = | ||
| draw!(img, Point(p), color, in_bounds=in_bounds, thickness=thickness) | ||
|
|
||
| function draw!(img::AbstractArray{T,2}, y::Integer, x::Integer, color::T; in_bounds::Bool=false, thickness::Integer=-1) where T<:Colorant | ||
| in_bounds ? img[point.y, point.x] = color : drawifinbounds!(img, y, x, color) | ||
| thickness != -1 && drawwiththickness!(img, y, x, color, in_bounds, thickness) | ||
| img | ||
| end | ||
|
|
||
| """ | ||
|
|
||
| img_new = drawifinbounds!(img, y, x, color) | ||
| img_new = drawifinbounds!(img, Point, color) | ||
| img_new = drawifinbounds!(img, CartesianIndex, color) | ||
| img_new = drawifinbounds!(img, point, color) | ||
| img_new = drawifinbounds!(img, cartesianIndex, color) | ||
|
|
||
| Draws a single point after checkbounds() for coordinate in the image. | ||
| Color Defaults to oneunit(T) | ||
|
|
@@ -200,6 +256,35 @@ drawifinbounds!(img::AbstractArray{T,2}, p::Point, color::T = oneunit(T)) where | |
| drawifinbounds!(img::AbstractArray{T,2}, p::CartesianIndex{2}, color::T = oneunit(T)) where {T<:Colorant} = drawifinbounds!(img, Point(p), color) | ||
|
|
||
| function drawifinbounds!(img::AbstractArray{T,2}, y::Int, x::Int, color::T) where {T<:Colorant} | ||
| if checkbounds(Bool, img, y, x) img[y, x] = color end | ||
| checkbounds(Bool, img, y, x) && (img[y, x] = color) | ||
| img | ||
| end | ||
|
|
||
| """ | ||
| img_new = drawwiththickness!(img, y, x, color, thickness) | ||
| img_new = drawwiththickness!(img, point, color, thickness) | ||
| img_new = drawwiththickness!(img, cartesianIndex, color, thickness) | ||
|
|
||
| Draws pixel with given thickness | ||
| Color Defaults to oneunit(T) | ||
| Thickness defaults to 1 | ||
|
|
||
| """ | ||
|
|
||
| drawwiththickness!(img::AbstractArray{T,2}, p::Point, color::T, in_bounds::Bool, thickness::Integer) where {T<:Colorant} = drawwiththickness!(img, p.y, p.x, color, in_bounds, thickness) | ||
| drawwiththickness!(img::AbstractArray{T,2}, p::CartesianIndex{2}, color::T, in_bounds::Bool, thickness::Integer) where {T<:Colorant} = drawifinbounds!(img, Point(p), color, in_bounds, thickness) | ||
|
|
||
| function drawwiththickness!(img::AbstractArray{T,2}, y0::Int, x0::Int, color::T, in_bounds::Bool, thickness::Int) where {T<:Colorant} | ||
|
Codyk12 marked this conversation as resolved.
Outdated
|
||
| n = Int(round(thickness / 2)) | ||
| evn = thickness % 2 == 1 ? 0 : 1 | ||
| pixels = [i for i = -(n-evn):n] | ||
|
|
||
| for (x,y) in Combinatorics.combinations(pixels, 2) | ||
| draw!(img, y0+y, x0+x, color, in_bounds=in_bounds) | ||
|
Codyk12 marked this conversation as resolved.
|
||
| draw!(img, y0+y, x0-x, color, in_bounds=in_bounds) | ||
| draw!(img, y0-y, x0+x, color, in_bounds=in_bounds) | ||
| draw!(img, y0-y, x0-x, color, in_bounds=in_bounds) | ||
| end | ||
| draw!(img, y0, x0, color, in_bounds=in_bounds) | ||
| img | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.