Skip to content

Commit

Permalink
minor fixes suggested by JET
Browse files Browse the repository at this point in the history
  • Loading branch information
cormullion committed Jun 5, 2023
1 parent 261f2d2 commit 5d2f3ed
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 12 deletions.
2 changes: 1 addition & 1 deletion docs/src/tutorial/pixels.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ end
for r in 1:size(A, 1), c in 1:size(A, 2)
A[r, c] = pixelcolor(r, c, rows = 400, cols = 800)
end
A
finish()
A
```

## Rows and columns, height and width
Expand Down
14 changes: 7 additions & 7 deletions src/drawings.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ mutable struct Drawing
elseif stype == :image
the_surface = Cairo.CairoImageSurface(w, h, Cairo.FORMAT_ARGB32)
else
error("Unknown Luxor surface type" \ "$stype\"")
error("Unknown Luxor surface type \"$stype\"")
end
the_cr = Cairo.CairoContext(the_surface)
# @info("drawing '$f' ($w w x $h h) created in $(pwd())")
Expand Down Expand Up @@ -672,20 +672,20 @@ end
@doc raw"""
_adjust_background_rects(buffer::UInt8[]; addmarker = true)
See issue https://github.com/JuliaGraphics/Luxor.jl/issues/150 for discussion details.\
See issue https://github.com/JuliaGraphics/Luxor.jl/issues/150 for discussion details.
Setting backgrounds in a recording surface (:rec) and creating a svg from it result in elements as
```
<rect x="0" y="0" width="16777215" height="16777215" .../>
```
independent of an existing transformation matrix (e.g. set with origin(...) or snapshot with a crop bounding box).\
independent of an existing transformation matrix (e.g. set with origin(...) or snapshot with a crop bounding box).
An existing transformation matrix manifests in the svg file as
```
<use xlink:href="#surface199" transform="matrix(3 1 -1 3 30 40)"/>
```
which is applied to every element including the background rects.\
which is applied to every element including the background rects.
This transformation needs to be inversed for the background rects which is added in this function.
If `addmarker` is not set to false, a class property is set as marker:
Expand Down Expand Up @@ -766,13 +766,13 @@ end
@doc raw"""
_split_string_into_head_mid_tail(s::String,id::String)
splits s into head, mid and tail string.\
Example:\
splits s into head, mid and tail string.
Example:
```
s="head...<g id="\$id">...</g>...tail"
```
results in\
results in
```
head="head..."
Expand Down
2 changes: 2 additions & 0 deletions src/point.jl
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,8 @@ polar(r, theta) = Point(r * cos(theta), r * sin(theta))
Find the point where two lines intersect.
Return `(resultflag, resultip)`, where `resultflag` is a Boolean, and `resultip` is a Point.
If `crossingonly == true` the point of intersection must lie on both lines.
If `crossingonly == false` the point of intersection can be where the lines meet
Expand Down
19 changes: 15 additions & 4 deletions src/polygons.jl
Original file line number Diff line number Diff line change
Expand Up @@ -948,6 +948,9 @@ than `value`, and the difference value. Array is assumed to be sorted.
"""
function nearestindex(a::Array{T,1} where {T<:Real}, val)
ind = findlast(v -> (v < val), a)
if isnothing(ind)
throw(error("nearestindex: no index"))
end
surplus = 0.0
if ind > 0.0
surplus = val - a[ind]
Expand All @@ -958,7 +961,9 @@ function nearestindex(a::Array{T,1} where {T<:Real}, val)
end

"""
polyportion(p::Array{Point, 1}, portion=0.5; closed=true, pdist=[])
polyportion(p::Array{Point, 1}, portion=0.5;
closed=true,
pdist = Array{Real, 1}[])
Return a portion of a polygon, starting at a value between
0.0 (the beginning) and 1.0 (the end). 0.5 returns the first
Expand All @@ -976,7 +981,9 @@ using `polydistances(p, closed=closed)`.
Use the complementary `polyremainder()` function to return
the other part.
"""
function polyportion(p::Array{Point,1}, portion = 0.5; closed = true, pdist = [])
function polyportion(p::Array{Point,1}, portion = 0.5;
closed = true,
pdist = Array{Real,1}[])
# portion is 0 to 1
if isempty(pdist)
pdist = polydistances(p, closed = closed)
Expand Down Expand Up @@ -1011,7 +1018,9 @@ function polyportion(p::Array{Point,1}, portion = 0.5; closed = true, pdist = []
end

"""
polyremainder(p::Array{Point, 1}, portion=0.5; closed=true, pdist=[])
polyremainder(p::Array{Point, 1}, portion=0.5;
closed=true,
pdist=Array{Real, 1}[])
Return the rest of a polygon, starting at a value between 0.0 (the beginning)
and 1.0 (the end). 0.5 returns the last half of the polygon, 0.25 the last three
Expand All @@ -1026,7 +1035,9 @@ calculated afresh, using `polydistances(p, closed=closed)`.
Use the complementary `polyportion()` function to return the other part.
"""
function polyremainder(p::Array{Point,1}, portion = 0.5; closed = true, pdist = [])
function polyremainder(p::Array{Point,1}, portion = 0.5;
closed = true,
pdist = Array{Real, 1}[])
# portion is 0 to 1
if isempty(pdist)
pdist = polydistances(p, closed = closed)
Expand Down

0 comments on commit 5d2f3ed

Please sign in to comment.