diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f93f9ae..84b7e7d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,7 +13,7 @@ - switched to Graham Scan algorithm for polyhull() -- isapprox allow kwargs +- allow use to change tolerance for isapprox() ### Removed diff --git a/src/Path.jl b/src/Path.jl index e9558f2b..9f64a610 100644 --- a/src/Path.jl +++ b/src/Path.jl @@ -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() diff --git a/src/bezierpath.jl b/src/bezierpath.jl index 592b4488..a2e47545 100644 --- a/src/bezierpath.jl +++ b/src/bezierpath.jl @@ -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) @@ -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) diff --git a/src/curves.jl b/src/curves.jl index 6c734c57..d8c19196 100644 --- a/src/curves.jl +++ b/src/curves.jl @@ -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) @@ -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; @@ -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, @@ -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) @@ -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, @@ -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; diff --git a/src/juliagraphics.jl b/src/juliagraphics.jl index 91ddf425..ea914e60 100644 --- a/src/juliagraphics.jl +++ b/src/juliagraphics.jl @@ -56,6 +56,8 @@ julialogo(action=:path) sethue("red") strokepath() ``` + +TODO Return something more useful than a Boolean. """ function julialogo(; action = :fill, @@ -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 = [ diff --git a/src/point.jl b/src/point.jl index 743bd1d6..036fc0ce 100644 --- a/src/point.jl +++ b/src/point.jl @@ -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) diff --git a/src/polygons.jl b/src/polygons.jl index 828583cf..743600b8 100644 --- a/src/polygons.jl +++ b/src/polygons.jl @@ -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[] diff --git a/src/shapes.jl b/src/shapes.jl index 7aadcc02..e500c334 100644 --- a/src/shapes.jl +++ b/src/shapes.jl @@ -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) = diff --git a/src/text.jl b/src/text.jl index e5a8adac..938c074b 100644 --- a/src/text.jl +++ b/src/text.jl @@ -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, @@ -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, diff --git a/test/triangles.jl b/test/triangles.jl index 6c9ab27f..9e983cd1 100644 --- a/test/triangles.jl +++ b/test/triangles.jl @@ -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 diff --git a/test/various-points-tests.jl b/test/various-points-tests.jl index ed24e7e7..28f40268 100644 --- a/test/various-points-tests.jl +++ b/test/various-points-tests.jl @@ -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 π