Skip to content

Commit

Permalink
Add needs_tight_limits for triplot/voronoiplot, and add bounding boxe…
Browse files Browse the repository at this point in the history
…s to both plot types
  • Loading branch information
DanielVandH committed Jul 28, 2023
1 parent 1f02ae0 commit d053626
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 14 deletions.
9 changes: 0 additions & 9 deletions ReferenceTests/src/tests/examples2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1194,15 +1194,6 @@ end
fig
end

#@reference_test "Triplot with an Observable tri" begin
# tri = triangulate([rand(2) for _ in 1:50])
# _tri = Observable(tri)
# fig, ax, sc = triplot(_tri)
# map(_tri) do tri
# refine!(tri, max_area=1e-4get_total_area(tri))
# end
#end

@reference_test "Voronoiplot for a centroidal tessellation with an automatic colormap" begin
points = [(0.0,0.0),(1.0,0.0),(1.0,1.0),(0.0,1.0)]
tri = triangulate(points; boundary_nodes = [1,2,3,4,1], rng = RNG.STABLE_RNG)
Expand Down
3 changes: 2 additions & 1 deletion ReferenceTests/src/tests/refimages.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ using ReferenceTests.LaTeXStrings
using ReferenceTests.DelimitedFiles
using ReferenceTests.Test
using ReferenceTests.Colors: RGB, N0f8
using DelaunayTriangulation: triangulate,
using DelaunayTriangulation: DelaunayTriangulation,
triangulate,
convert_boundary_points_to_indices,
each_point,
reset_representative_points!,
Expand Down
20 changes: 16 additions & 4 deletions src/basic_recipes/triplot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Plots the triangles from the provided `Triangulation` from DelaunayTriangulation
- `ghost_edge_color = :blue` sets the color of the ghost edges.
- `ghost_edge_linestyle = :solid` sets the linestyle of the ghost edges.
- `ghost_edge_linewidth = 1` sets the width of the ghost edges.
- `ghost_edge_extension_factor = 10.0` sets the extension factor for the ghost edges.
- `ghost_edge_extension_factor = 2.0` sets the extension factor for the rectangle that the exterior ghost edges are extended onto. The rectangle will be given by `[a - eΔx, b + eΔx] × [c - eΔy, d + eΔy]` where `e` is the extension factor, `Δx = b - a` and `Δy = d - c` are the lengths of the sides of the rectangle, and `[a, b] × [c, d]` is the bounding box of the triangulation.
- `constrained_edge_color = :magenta` sets the color of the constrained edges.
- `constrained_edge_linestyle = :solid` sets the linestyle of the constrained edges.
Expand Down Expand Up @@ -60,7 +60,7 @@ Plots the triangles from the provided `Triangulation` from DelaunayTriangulation
ghost_edge_color=:blue,
ghost_edge_linestyle=theme(scene, :linestyle),
ghost_edge_linewidth=theme(scene, :linewidth),
ghost_edge_extension_factor=10.0,
ghost_edge_extension_factor=2.0,

# Constrained edge settings
constrained_edge_color=:magenta,
Expand Down Expand Up @@ -100,8 +100,20 @@ function get_triangulation_triangles!(triangles, tri)
end

function get_triangulation_ghost_edges!(ghost_edges, extent, tri)
@assert extent > 0.0 "The ghost_edge_extension_factor must be positive."
empty!(ghost_edges)
sizehint!(ghost_edges, 2DelTri.num_ghost_edges(tri))
if DelTri.has_boundary_nodes(tri)
xmin, xmax, ymin, ymax = DelTri.polygon_bounds(DelTri.get_points(tri), DelTri.get_boundary_nodes(tri))
else
xmin, xmax, ymin, ymax = DelTri.polygon_bounds(DelTri.get_points(tri),
DelTri.get_convex_hull_indices(tri))
end
Δx = xmax - xmin
Δy = ymax - ymin
a, b, c, d = (xmin - extent * Δx, xmax + extent * Δx, ymin - extent * Δy, ymax + extent * Δy)
bbox = [(a, c), (b, c), (b, d), (a, d)]
bbox_order = [1, 2, 3, 4, 1]
for e in DelTri.each_ghost_edge(tri)
u, v = DelTri.edge_indices(e)
if DelTri.is_boundary_index(v)
Expand All @@ -115,8 +127,8 @@ function get_triangulation_ghost_edges!(ghost_edges, extent, tri)
if DelTri.is_interior_curve(curve_index)
ex, ey = rx, ry
else
ex = rx * (1 - extent) + extent * px
ey = ry * (1 - extent) + extent * py
e = DelTri.intersection_of_ray_with_boundary(bbox, bbox_order, representative_coordinates, p)
ex, ey = DelTri.getxy(e)
end
push!(ghost_edges, Point2f(px, py), Point2f(ex, ey))
end
Expand Down
6 changes: 6 additions & 0 deletions src/makielayout/blocks/axis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,12 @@ function needs_tight_limits(c::Contourf)
# otherwise here it could be in an arbitrary shape
return c.levels[] isa Int
end
function needs_tight_limits(p::Triplot)
return p.show_ghost_edges[]
end
function needs_tight_limits(p::Voronoiplot)
return !isempty(DelTri.get_unbounded_polygons(p[1][]))
end

function expandbboxwithfractionalmargins(bb, margins)
newwidths = bb.widths .* (1f0 .+ margins)
Expand Down

0 comments on commit d053626

Please sign in to comment.