Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
cormullion committed Oct 30, 2023
2 parents 5c7517e + 316d061 commit 4264f86
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 14 deletions.
2 changes: 0 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
FFMPEG = "c87230d0-a227-11e9-1b43-d7ebe4e7570a"
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
Juno = "e5e0dc1b-0480-54bc-9374-aad01c23163d"
LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f"
MathTeXEngine = "0a4f8689-d25c-4efe-a92b-7142dfc1aa53"
PolygonAlgorithms = "32a0d02f-32d9-4438-b5ed-3a2932b48f96"
Expand All @@ -32,7 +31,6 @@ Colors = "0.9, 0.10, 0.11, 0.12, 0.13, 0.14, 0.15, 0.16, 0.17, 1.0"
DataStructures = "0.18"
FFMPEG = "0.4"
FileIO = "1"
Juno = "0.7, 0.8"
LaTeXStrings = "1.1, 1.2, 1.3"
MathTeXEngine = "0.5"
PolygonAlgorithms = "0.1"
Expand Down
2 changes: 1 addition & 1 deletion docs/src/explanation/basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ In some situations you'll want to explicitly return the current drawing to the c

# Working in IDEs and notebooks

You can use an environment such as a Jupyter or Pluto notebook or the Juno or VS Code IDEs, and load Luxor at the start of a session. The first drawing will take a few seconds, because the Cairo graphics engine needs to warm up. Subsequent drawings are then much quicker. (This is true of much graphics and plotting work. Julia compiles each function when it first encounters it, and then calls the compiled versions for the rest of the session.)
You can use an environment such as a Jupyter or Pluto notebook or VS Code IDEs, and load Luxor at the start of a session. The first drawing will take a few seconds, because the Cairo graphics engine needs to warm up. Subsequent drawings are then much quicker. (This is true of much graphics and plotting work. Julia compiles each function when it first encounters it, and then calls the compiled versions for the rest of the session.)

## Working in Jupyter

Expand Down
1 change: 0 additions & 1 deletion src/Luxor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ using Cairo
using Colors
using Dates
using FFMPEG
using Juno
using Rsvg

import PolygonAlgorithms as PA
Expand Down
4 changes: 2 additions & 2 deletions src/drawings.jl
Original file line number Diff line number Diff line change
Expand Up @@ -428,10 +428,10 @@ function Base.show(io::IO, ::MIME"text/plain", d::Drawing)
@debug "show MIME:text/plain"
returnvalue = d.filename

# IJulia and Juno call the `show` function twice: once for
# IJulia call the `show` function twice: once for
# the image MIME and a second time for the text/plain MIME.
# We check if this is such a 'second call':
if (get(io, :jupyter, false) || Juno.isactive()) &&
if get(io, :jupyter, false) &&
(d.surfacetype == :svg || d.surfacetype == :png)
return d.filename
end
Expand Down
19 changes: 12 additions & 7 deletions src/polygons.jl
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,8 @@ function drawroundedcorner(cornerpoint::Point, p1::Point, p2::Point, radius, pat
end

"""
polysmooth(points, radius, action=:action; debug=false)
polysmooth(points, radius; action=:none, debug=false)
polysmooth(points, radius, action=:action; debug=false, close=true)
polysmooth(points, radius; action=:none, debug=false, close=true)
Make a closed path from the `points` and round the corners by making them arcs with the
given radius. Execute the action when finished.
Expand All @@ -373,14 +373,14 @@ 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)
function polysmooth(points::Array{Point,1}, radius, action::Symbol; debug = false, close = true)
temppath = Tuple[]
l = length(points)
if l < 3
# there are less than three points to smooth
return nothing
else
@inbounds for i in 1:l
@inbounds for i in 1:(close ? l : l-2)
p1 = points[mod1(i, l)]
p2 = points[mod1(i + 1, l)]
p3 = points[mod1(i + 2, l)]
Expand All @@ -391,7 +391,12 @@ function polysmooth(points::Array{Point,1}, radius, action::Symbol; debug = fals
end
end
# need to close by joining to first point
push!(temppath, temppath[1])
if close
push!(temppath, temppath[1])
else
pushfirst!(temppath, (:line, points[1]))
push!(temppath, (:line, points[end]))
end
# draw the path
for (c, p) in temppath
if c == :line
Expand All @@ -405,8 +410,8 @@ function polysmooth(points::Array{Point,1}, radius, action::Symbol; debug = fals
do_action(action)
end

polysmooth(points::Array{Point,1}, radius; action = :none, debug = false) =
polysmooth(points, radius, action; debug = debug)
polysmooth(points::Array{Point,1}, radius; action = :none, debug = false, close = true) =
polysmooth(points, radius, action; debug = debug, close = close)

"""
offsetpoly(plist::Array{Point, 1}, d) where T<:Number
Expand Down
2 changes: 1 addition & 1 deletion test/interactive-tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# this test isn't run by Pkg.test

# it can be run to test Juno/Jupyter integration...
# it can be run to test Jupyter integration...

using Luxor

Expand Down
1 change: 1 addition & 0 deletions test/polysmooth-tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ function star_test(fname)
p = star(pos, tiles.tilewidth/2 - 10, randomsides, randomratio, 0, vertices=true)
prettypoly(p, close=true, :stroke)
polysmooth(p, randomsmoothing, :fill, debug=true)
polysmooth(p, randomsmoothing, :fill, debug=true, close=false)
end
@test finish() == true
println("...finished test: output in $(fname)")
Expand Down

0 comments on commit 4264f86

Please sign in to comment.