Skip to content

Commit

Permalink
hexagon tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cormullion committed Jul 13, 2022
1 parent 4a719d5 commit 7bda7bd
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 22 deletions.
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Changelog

## [v3.4.0] - forthcoming
## [v3.4.0] - 2022-07-13 09:01:18

### Added

- BoundingBox() can be used on Tables and table cells (needs tests)

- first pass at hexagon constructors
- hexagon constructors

### Changed

Expand All @@ -18,6 +18,8 @@

### Removed

- some old unused stuff

### Deprecated

# ────────────────────────────────────────────────────────────────────────────────────
Expand Down
19 changes: 19 additions & 0 deletions docs/src/howto/tables-grids.md
Original file line number Diff line number Diff line change
Expand Up @@ -416,3 +416,22 @@ for i in 1:10
end
end # hide
```

### Spiralling hexagons

```@example
using Luxor # hide
using Colors # hide
@drawsvg begin # hide
background("black")
hexagon = HexagonOffsetEvenR(0, 0, 16)
setline(0.75)
for h in hexspiral(hexagon, 10)
sethue(HSB(mod1(5n, 360), 0.8, 0.8))
poly(hextile(h), :fillpreserve)
sethue("black")
strokepath()
end
end 600 600 # hide
```
2 changes: 1 addition & 1 deletion src/Luxor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export Drawing,
HexagonAxial, HexagonCubic, HexagonOffsetOddR, HexagonOffsetEvenR,
# hexagon,
hexcenter, hexcube_round, hexcube_linedraw,
HexagonVertexIterator, hextile,
HexagonVertexIterator, hextile, hexspiral,
HexagonNeighborIterator, hexneighbors,
HexagonDiagonalIterator, hexdiagonals,
HexagonDistanceIterator, hexagons_within,
Expand Down
36 changes: 19 additions & 17 deletions src/hexagons.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,6 @@ struct HexagonCubic <: Hexagon
height::Float64
end

# """
# hexagon(q::Int64, r::Int64, s::Int64)

# calls HexagonCubic(q, r, s, Point(0, 0), 10.0, 10.0)
# """
# hexagon(q::Int64, r::Int64, s::Int64) = HexagonCubic(q, r, s, Point(0, 0), 10.0, 10.0)

# """
# hexagon(q::Int64, r::Int64)

# calls HexagonAxial(q, r, Point(0, 0), 10.0, 10.0)
# """
# hexagon(q::Int64, r::Int64) = HexagonAxial(q, r, Point(0, 0), 10.0, 10.0)

HexagonAxial(q, r) = HexagonAxial(q, r, Point(0, 0), 10.0, 10.0)
HexagonAxial(q, r, o::Point) = HexagonAxial(q, r, o, 10.0, 10.0)
HexagonAxial(q, r, w) = HexagonAxial(q, r, Point(0, 0), w, w)
Expand Down Expand Up @@ -352,8 +338,7 @@ hexring(hex::Hexagon, n::Int) = hexring(n, hex)

Base.length(it::HexagonRingIterator) = it.n * 6

function Base.iterate(it::HexagonRingIterator,
state::(Tuple{Int,HexagonCubic}) = (1, hexneighbor(it.hex, 5, it.n)))
function Base.iterate(it::HexagonRingIterator, state::(Tuple{Int,HexagonCubic}) = (1, hexneighbor(it.hex, 5, it.n)))
hex_i, cur_hex = state
hex_i > length(it) && return nothing
ring_part = div(hex_i - 1, it.n) + 1
Expand All @@ -365,6 +350,23 @@ function Base.collect(it::HexagonRingIterator)
collect(HexagonCubic, it)
end

"""
hexspiral(hex, n)
Return an array of hexagons to spiral around a central hexagon forming `n` rings.
"""
function hexspiral(hex, nrings)
result = Luxor.Hexagon[]
ringn = 1
while ringn < nrings
hexes = collect(hexring(hex, ringn))
circshift!(hexes, 1)
append!(result, hexes)
ringn += 1
end
return result
end

"""
distance(h1::Hexagon, h2::Hexagon)
Expand Down Expand Up @@ -402,7 +404,7 @@ end
"""
hexcube_linedraw(hexa::Hexagon, hexb::Hexagon)
Find and return the hexagons that lie (mostly) on a straight line between `hexa` and `hexb`.
Find and return the hexagons that lie (mostly) on a straight line between `hexa` and `hexb`. If you filled/stroked them appropriately, you'd get a jagged line.
"""
function hexcube_linedraw(a::Hexagon, b::Hexagon)
hexa = convert(HexagonCubic, a)
Expand Down
1 change: 0 additions & 1 deletion test/grid-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ function grid_test(fname)
background("white")

panes = Tiler(Luxor.current_width(), Luxor.current_height(), 1, 2)
@show panes
@layer begin
translate(first(panes[1]))
circle(O, 10, :fill)
Expand Down
1 change: 0 additions & 1 deletion test/tiling-images.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ function get_png_files()
folder = dirname(dirname(pathof(Luxor))) * "/docs/src/assets/figures/"
imagelist = filter(f -> !startswith(f, ".") && endswith(f, "png"), readdir(folder))
imagepathlist = map(fn -> folder * "/" * fn, imagelist)
@show imagepathlist
return imagepathlist
end

Expand Down

0 comments on commit 7bda7bd

Please sign in to comment.