Skip to content

Commit

Permalink
add TODOs re return values
Browse files Browse the repository at this point in the history
  • Loading branch information
cormullion committed Jan 10, 2022
1 parent 5875f44 commit f787a87
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 10 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

- switched to Graham Scan algorithm for polyhull()

- isapprox allow kwargs
- allow use to change tolerance for isapprox()

### Removed

Expand Down
2 changes: 2 additions & 0 deletions src/Path.jl
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ function.
By default, `startnewpath=true`, which starts a new path,
discarding any existing path contents.
TODO Return something more useful than a Boolean!
"""
function drawpath(cp::Path; action=:none, startnewpath=true)
startnewpath && newpath()
Expand Down
4 changes: 4 additions & 0 deletions src/bezierpath.jl
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ end
Draw the Bézier path, and apply the action, such as `:none`, `:stroke`, `:fill`,
etc. By default the path is closed.
TODO Return something more useful than a Boolean.
"""
function drawbezierpath(bezierpath::BezierPath, action; close=true)
move(bezierpath[1].p1)
Expand All @@ -206,6 +208,8 @@ drawbezierpath(bezierpath; action=:none, close=true) =
Draw the Bézier path segment, and apply the action, such as `:none`, `:stroke`,
`:fill`, etc. By default the path is open.
TODO Return something more useful than a Boolean.
"""
function drawbezierpath(bps::BezierPathSegment,
action=:none; close=false)
Expand Down
10 changes: 9 additions & 1 deletion src/curves.jl
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ ellipse(xc::Real, yc::Real, w::Real, h::Real, action::Symbol) =
Make an ellipse, centered at `centerpoint`, with width `w`, and height `h`.
Returns a tuple of two points, the corners of a bounding box that encloses the ellipse.
Returns a tuple of two points, the corners of a bounding box that encloses the ellipse.
"""
ellipse(c::Point, w::Real, h::Real; action=:none) = ellipse(c.x, c.y, w, h, action=action)

Expand Down Expand Up @@ -284,6 +284,7 @@ end
Draw an annular sector centered at `centerpoint`.
TODO - return something more useful than a Boolean
"""
function sector(centerpoint::Point, innerradius::Real, outerradius::Real,
startangle::Real, endangle::Real;
Expand Down Expand Up @@ -330,6 +331,8 @@ centered at `centerpoint`.
TODO: The results aren't 100% accurate at the moment. There are small
discontinuities where the curves join.
TODO - return something more useful than a Boolean
The cornerradius is reduced from the supplied value if neceesary to prevent overshoots.
"""
function sector(centerpoint::Point, innerradius::Real, outerradius::Real, startangle::Real,
Expand Down Expand Up @@ -424,6 +427,8 @@ sector(innerradius::Real, outerradius::Real, startangle::Real, endangle::Real, c
Draw a pie shape centered at `x`/`y`. Angles start at the positive x-axis and
are measured clockwise.
TODO - return something more useful than a Boolean
"""
function pie(x::Real, y::Real, radius::Real, startangle::Real, endangle::Real;
action=:none)
Expand Down Expand Up @@ -489,6 +494,8 @@ option to draw the circle clockwise rather than
`circle`'s counterclockwise.
The magic value, `kappa`, is `4.0 * (sqrt(2.0) - 1.0) / 3.0`.
Return two points, the corners of a bounding box.
"""
function circlepath(center::Point, radius;
action=:none,
Expand Down Expand Up @@ -547,6 +554,7 @@ function circlepath(center::Point, radius;
easttonorth(center, radius, kappa)
end
do_action(action)
return (center - (radius, radius), center + (radius, radius))
end

circlepath(center::Point, radius, action::Symbol; reversepath=false, kappa = 0.5522847498307936) = circlepath(center, radius;
Expand Down
7 changes: 6 additions & 1 deletion src/juliagraphics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ julialogo(action=:path)
sethue("red")
strokepath()
```
TODO Return something more useful than a Boolean.
"""
function julialogo(;
action = :fill,
Expand All @@ -68,7 +70,10 @@ function julialogo(;
end

# save current color
r, g, b, a = Luxor.get_current_redvalue(), Luxor.get_current_greenvalue(), Luxor.get_current_bluevalue(), Luxor.get_current_alpha()
r, g, b, a = Luxor.get_current_redvalue(),
Luxor.get_current_greenvalue(),
Luxor.get_current_bluevalue(),
Luxor.get_current_alpha()

# "j" without dot
_j = [
Expand Down
6 changes: 3 additions & 3 deletions src/point.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ end

isequal(p1::Point, p2::Point) = isapprox(p1.x, p2.x, atol=0.00000001) && (isapprox(p1.y, p2.y, atol=0.00000001))

isapprox(p1::Point, p2::Point) = isapprox(p1.x, p2.x, atol=0.00000001) && (isapprox(p1.y, p2.y, atol=0.00000001))

# allow kwargs
isapprox(p1::Point, p2::Point; kwargs...) = isapprox(p1.x, p2.x; kwargs...) && (isapprox(p1.y, p2.y; kwargs...))
function Base.isapprox(p1::Point, p2::Point; atol=1e-6, kwargs...)
return isapprox(p1.x, p2.x; atol=atol, kwargs...) && isapprox(p1.y, p2.y; atol=atol, kwargs...)
end

isless(p1::Point, p2::Point) = (p1.x < p2.x || (isapprox(p1.x, p2.x) && p1.y < p2.y))
!=(p1::Point, p2::Point) = !isequal(p1, p2)
Expand Down
2 changes: 2 additions & 0 deletions src/polygons.jl
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,8 @@ shortest side, the arc can't be drawn at its full radius and is therefore drawn
possible (as large as the shortest side allows).
The `debug` option also draws the construction circles at each corner.
TODO Return something more useful than a Boolean.
"""
function polysmooth(points::Array{Point, 1}, radius, action::Symbol; debug=false)
temppath = Tuple[]
Expand Down
2 changes: 2 additions & 0 deletions src/shapes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,8 @@ function box(centerpoint::Point, width, height, cornerradii::Array;
closepath()
grestore()
do_action(action)
return Point(centerpoint.x - width/2, centerpoint.y - height/2),
Point(centerpoint.x + width/2, centerpoint.y + height/2)
end

box(centerpoint::Point, width, height, cornerradii::Array, action::Symbol) =
Expand Down
4 changes: 4 additions & 0 deletions src/text.jl
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ end
startnewpath=true)
Convert the text in string `s` to paths and apply the action.
TODO Return something more useful than a Boolean.
"""
function textpath(s::AbstractString, pos::Point;
action=:none,
Expand Down Expand Up @@ -234,6 +236,8 @@ Convert text to polygons and apply `action`.
By default this function discards any current path, unless you use `startnewpath=false`
See also `textpath()`.
TODO Return something more useful than a Boolean.
"""
function textoutlines(s::AbstractString, pos::Point;
action=:none,
Expand Down
6 changes: 3 additions & 3 deletions test/triangles.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ function triangle_tests(fname)
circle.((orthocenter, incenter, center, circumcenter), 2, :fill)

# all centers are the same
@test isapprox(orthocenter, incenter)
@test isapprox(orthocenter, center)
@test isapprox(orthocenter, circumcenter)
@test isapprox(orthocenter, incenter, atol=1.0e-12)
@test isapprox(orthocenter, center, atol=1.0e-12)
@test isapprox(orthocenter, circumcenter, atol=1.0e-12)
end

@layer begin
Expand Down
2 changes: 1 addition & 1 deletion test/various-points-tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function rotate_points_test(fname)

# they should be equal
for pr in zip(pts, pts1)
@test first(pr) last(pr)
@test isapprox(first(pr), last(pr), atol=1.0e-12)
end

# now rotate each point by π
Expand Down

0 comments on commit f787a87

Please sign in to comment.