Skip to content

Commit

Permalink
bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
cormullion committed Mar 23, 2022
1 parent edd0a94 commit 77d7025
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

### Changed

- check for dodgy corners in `polysmooth()` (thanks @arbitrandomuser!)

### Removed

### Deprecated
Expand Down
18 changes: 8 additions & 10 deletions docs/src/howto/polygons.md
Original file line number Diff line number Diff line change
Expand Up @@ -1400,14 +1400,13 @@ You supply two polygons and a value `k` between 0 and 1. For example, if the val

Sometimes polygons consist of two or more loops - this is how holes work. So `polymorph()` accepts both simple polygons and arrays of polygons, but always returns an array of polygons.

In this first example, `fromshape`, the circle, is an array holding a single vector of Points (`pathtopoly()` returns an array of poygons), and `toshape`, the line, is a simple vector of points (the minimum of three points). In this case, with just simple polygons, only the first element of the result of the `polymorph()` function is needed.
In this first example, `fromshape`, the circle, is an array holding a single vector of Points (`pathtopoly()` returns an array of polygons), and `toshape`, the line, is a simple vector of points (the minimum of three points). In this case, with just simple polygons, only the first element of the result of the `polymorph()` function is needed.

```@example
using Luxor # hide
@drawsvg begin
background("black")
setline(0.5)
sethue("gold")
@drawsvg begin # hide
background("black") # hide
setline(0.5) # hide
circlepath(O, 200, :path)
fromshape = pathtopoly()
toshape = [Point(0, -250), O, Point(0, 250)] # minimum of 3
Expand All @@ -1416,15 +1415,15 @@ for i in 0:0.015:1
morph = polymorph(fromshape, toshape, i, easingfunction=easeinoutsine)
poly(first(morph), :stroke, close=true)
end
end
end # hide
```

In the next example, a square morphs into a hexagon.

```@example
using Luxor # hide
@drawsvg begin # hide
background(0.15, 0.15, 0.1)
background(0.15, 0.15, 0.1) # hide
pgon1 = ngon(O, 80, 4, vertices = true)
pgon2 = ngon(O, 270, 6, vertices = true)
sethue("cyan")
Expand All @@ -1443,8 +1442,7 @@ In the next example, an octagon with a square hole morphs into a square with an
```@example
using Luxor # hide
@drawsvg begin # hide
background(0.15, 0.15, 0.1)
background(0.15, 0.15, 0.1) # hide
# build first polygon
ngon(O + (-350, 0), 40, 8, π, :path)
newsubpath()
Expand Down Expand Up @@ -1501,4 +1499,4 @@ animate(amovie, Scene(amovie, frame, 1:120), creategif=true, pathname="/tmp/pyth

![python julia animation](../assets/figures/python-julia.gif)

The length of "Python" is 9, whereas the length of "Julia" is 8. The `polymorph()` function tries to work around this - notice how the "n" morphs down to nothing. If you don't want this to happen, set `kludge` to false. In this particular case, you could increase the number of loops in `totext` to match by using a lower-case "j".
The "Python" path has 9 loops, whereas "Julia" has 8. The `polymorph()` function tries to work around this - notice how the ninth loop, "n", morphs down to nothing. If you don't want this to happen, set the `kludge` keyword to false. In this particular case, you could increase the number of loops in `totext` to match by using a lower-case "j".
6 changes: 6 additions & 0 deletions src/polygons.jl
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,9 @@ prettypoly(pointlist, action::Symbol) = prettypoly(pointlist, () -> circle(O, 2,
vertexlabels = (n, l) -> ())

function getproportionpoint(point::Point, segment, length, dx, dy)
if isapprox(segment, 0.0) || isapprox(length, 0.0)
throw(error("getproportionpoint: impossible construction with segment $(segment) length $(length)"))
end
scalefactor = segment / length
return Point((point.x - dx * scalefactor), (point.y - dy * scalefactor))
end
Expand Down Expand Up @@ -482,6 +485,9 @@ function polysmooth(points::Array{Point,1}, radius, action::Symbol; debug = fals
p1 = points[mod1(i, l)]
p2 = points[mod1(i + 1, l)]
p3 = points[mod1(i + 2, l)]
if isapprox(distance(p1, p2), 0.0) || isapprox(distance(p2, p3), 0.0)
throw(error("polysmooth(): impossible to round the vertex at point #$(i + 1)"))
end
drawroundedcorner(p2, p1, p3, radius, temppath, debug = debug)
end
end
Expand Down

0 comments on commit 77d7025

Please sign in to comment.