Skip to content

Commit

Permalink
added between methods for ranges and arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
cormullion committed Mar 7, 2024
1 parent 80a780b commit 90d006b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Changelog

## [v4.0] - 2024-02-17
## [v4.0] - 2024-

LaTeX support is still under development.
See https://github.com/JuliaGraphics/Cairo.jl/pull/357.
Expand All @@ -23,6 +23,7 @@ See https://github.com/JuliaGraphics/Cairo.jl/pull/357.
- documents now built to https://github.com/JuliaGraphics/LuxorManual
- fixed bug in `box(pt, w, h, cr, :path)` (don't create new path)
- removed some invalid Point methods (#294)
- `between` has more methods for ranges and arrays

### Removed

Expand Down
8 changes: 4 additions & 4 deletions docs/src/explanation/pathspolygons.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ d = @drawsvg begin
make_path()
clip()
sethue("green")
# -> 3.9
# Luxor <= "v3.8"
# rule.(between.(O - (250, 0), O + (250, 0), 0:0.01:1), -π/3)
# 4.0
rule.(between.(Ref(O - (250, 0)), Ref(O + (250, 0)), 0:0.01:1), -π/3)
# Luxor >= "v4.0"
rule.(between(O - (250, 0), O + (250, 0), 0:0.01:1), -π/3)
end 800 500
```

Expand Down Expand Up @@ -113,7 +113,7 @@ also convert the path to a clipping path using
As you can see, a single path can contain multiple separate graphic shapes.

### Holes

beetween
If you want a path to contain holes,
you add the hole shapes to the current path after reversing
their direction. For example, to put a square hole inside a
Expand Down
2 changes: 1 addition & 1 deletion docs/src/howto/polygons.md
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ background("white") # hide
setline(2) # hide
setlinejoin("round") # hide
spine = between.(Ref(O - (200, 0)), Ref(O + (200, 0)), 0:0.025:1)
spine = between(O - (200, 0), O + (200, 0), 0:0.025:1)
sethue("red")
prettypoly(spine, action = :stroke)
Expand Down
18 changes: 18 additions & 0 deletions src/point.jl
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,24 @@ function between(couple::NTuple{2,Point}, x)
return p1 + (x * (p2 - p1))
end

"""
between(p1::Point, p2::Point, r:range)
between(p1::Point, p2::Point, a:array)
Return an array of Points between point `p1` and point `p2` for
every `x` in range `r` or array `a`.
If `x` is 0.0, that point will be at `p1`; if `x` is 1.0, that point will be at `p2`.
When `x` is 0.5, that point is the midpoint between `p1` and `p2`.
"""
function Luxor.between(pt1::Point, pt2::Point, r::AbstractRange)
[between(pt1, pt2, e) for e in r]
end

function Luxor.between(pt1::Point, pt2::Point, a::AbstractArray)
[between(pt1, pt2, e) for e in a]
end

"""
perpendicular(p1::Point, p2::Point, p3::Point)
Expand Down

0 comments on commit 90d006b

Please sign in to comment.