Skip to content

Commit 7e2f75c

Browse files
authored
Fix issue with clipped Voronoi tessellation for a single right-angled triangle (#207)
1 parent a0d30a4 commit 7e2f75c

File tree

4 files changed

+32
-11
lines changed

4 files changed

+32
-11
lines changed

NEWS.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## 1.6.1
4+
- Fix issue with clipping Voronoi tessellation dual to a single right-angled triangle. See [#207](https://github.com/JuliaGeometry/DelaunayTriangulation.jl/pull/207)
5+
36
## 1.6.0
47
- Define `reverse` for `AbstractParametricCurve`s, making it easier to reverse the orientation of a curve. See [#195](https://github.com/JuliaGeometry/DelaunayTriangulation.jl/pull/195).
58
- Fixed an issue with `LineSegment` not returning the exact endpoints at `t=1`, which can be problematic when joining boundary nodes. This has been fixed. See [#195](https://github.com/JuliaGeometry/DelaunayTriangulation.jl/pull/195).

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "DelaunayTriangulation"
22
uuid = "927a84f5-c5f4-47a5-9785-b46e178433df"
33
authors = ["Daniel VandenHeuvel <[email protected]>"]
4-
version = "1.6.0"
4+
version = "1.6.1"
55

66
[deps]
77
AdaptivePredicates = "35492f91-a3bd-45ad-95db-fcad7dcfedb7"

src/algorithms/voronoi/clipped_coordinates.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ function _get_ray(vorn::VoronoiTessellation, i, ghost_vertex, predicates::Abstra
151151
m = midpoint(p, q)
152152
end
153153
mx, my = getxy(m)
154-
if r == m # It's possible for the circumcenter to lie on the edge and exactly at the midpoint (e.g. [(0.0,1.0),(-1.0,2.0),(-2.0,-1.0)]). In this case, just rotate
154+
if check_precision(dist(r, m)) # It's possible for the circumcenter to lie on the edge and exactly at the midpoint (e.g. [(0.0,1.0),(-1.0,2.0),(-2.0,-1.0)]). In this case, just rotate
155155
dx, dy = qx - mx, qy - my
156156
if is_right(point_position_relative_to_line(predicates, p, q, r))
157157
rotated_dx, rotated_dy = dy, -dx

test/voronoi/voronoi.jl

+27-9
Original file line numberDiff line numberDiff line change
@@ -1384,7 +1384,7 @@ end
13841384
@test validate_tessellation(vorn, check_convex=false)
13851385
end
13861386

1387-
@testset "Clipping to a generic convex polygon" begin
1387+
@testset "Clipping to a generic convex polygon" begin
13881388
a, b, c, d, e, f, g, h, i = (-5.0, 7.0),
13891389
(-8.0, 6.0), (-7.0, 4.0), (-4.0, 3.0), (-6.0, 6.0),
13901390
(-1.0, 6.0), (-4.0, 6.0), (-3.0, 5.0), (-2.0, 8.0)
@@ -1482,11 +1482,11 @@ end
14821482
@test DT.circular_equality(DT.get_polygon_point(vorn, vorn.polygons[7]...), pt7, )
14831483
@test DT.circular_equality(DT.get_polygon_point(vorn, vorn.polygons[8]...), pt8, )
14841484
@test DT.circular_equality(DT.get_polygon_point(vorn, vorn.polygons[9]...), pt9, )
1485-
@test validate_tessellation(vorn; check_area = false)
1485+
@test validate_tessellation(vorn; check_area=false)
14861486
@test isempty(vorn.unbounded_polygons)
14871487
@test vorn.boundary_polygons == Set((4, 6, 2, 9, 3, 1))
14881488

1489-
vorn = voronoi(tri, clip=true, clip_polygon=clip_polygon, rng=rng, smooth = true)
1489+
vorn = voronoi(tri, clip=true, clip_polygon=clip_polygon, rng=rng, smooth=true)
14901490
pt1 = [
14911491
(-5.1590315116169645, 8.028359015649276)
14921492
(-2.0329830757675342, 9.155154224395774)
@@ -1551,7 +1551,7 @@ end
15511551
(-0.15539885081025462, 7.000135534420414)
15521552
(2.0, 7.000229455337406)
15531553
]
1554-
@test validate_tessellation(vorn; check_area = false)
1554+
@test validate_tessellation(vorn; check_area=false)
15551555
@test DT.circular_equality(DT.get_polygon_point(vorn, vorn.polygons[1]...), pt1, )
15561556
@test DT.circular_equality(DT.get_polygon_point(vorn, vorn.polygons[2]...), pt2, )
15571557
@test DT.circular_equality(DT.get_polygon_point(vorn, vorn.polygons[3]...), pt3, )
@@ -1562,7 +1562,7 @@ end
15621562
@test DT.circular_equality(DT.get_polygon_point(vorn, vorn.polygons[9]...), pt9, )
15631563
for index in each_polygon_index(vorn)
15641564
c = DT.get_centroid(vorn, index)
1565-
@test c get_generator(vorn, index) rtol=1e-2 atol=1e-4
1565+
@test c get_generator(vorn, index) rtol = 1e-2 atol = 1e-4
15661566
end
15671567

15681568
J, K, L, M = (-2.0, 12.0), (-8.0, 4.0), (-4.0, 2.0), (-2.0, 10.0)
@@ -1711,7 +1711,7 @@ end
17111711
@test DT.circular_equality(DT.get_polygon_point(vorn, vorn.polygons[9]...), pt9, )
17121712
for index in each_polygon_index(vorn)
17131713
c = DT.get_centroid(vorn, index)
1714-
@test c get_generator(vorn, index) rtol=1e-2 atol=1e-4
1714+
@test c get_generator(vorn, index) rtol = 1e-2 atol = 1e-4
17151715
end
17161716
end
17171717

@@ -1722,7 +1722,7 @@ end
17221722
@test vorn == vorn
17231723
@test vorn == vorn2
17241724
g1 = vorn.generators[1]
1725-
vorn.generators[1] = vorn.generators[2]
1725+
vorn.generators[1] = vorn.generators[2]
17261726
@test vorn != vorn2
17271727
vorn.generators[1] = g1
17281728
@test vorn == vorn2
@@ -1761,8 +1761,8 @@ end
17611761
@test vorn == vorn2
17621762
end
17631763

1764-
@testset "copy/deepcopy" begin
1765-
vorn = voronoi(triangulate(rand(2, 100)), clip = true, smooth = true)
1764+
@testset "copy/deepcopy" begin
1765+
vorn = voronoi(triangulate(rand(2, 100)), clip=true, smooth=true)
17661766
vorn1 = deepcopy(vorn)
17671767
vorn2 = copy(vorn)
17681768
@test typeof(vorn1) == typeof(vorn) == typeof(vorn2)
@@ -1773,4 +1773,22 @@ end
17731773
@test !(getfield(vorn, f) === getfield(_vorn, f))
17741774
end
17751775
end
1776+
end
1777+
1778+
@testset "Issue #206" begin
1779+
Random.seed!(123)
1780+
pts = [(0.1, 0.2), (1.1, 0.2), (0.1, 1.7)]
1781+
tri = triangulate(pts)
1782+
vorn = voronoi(tri, clip=true, clip_polygon=(
1783+
[(0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 1.0)], [1, 2, 3, 4, 1]
1784+
))
1785+
@test validate_tessellation(vorn; check_area=false)
1786+
A = 0.0
1787+
for i in each_polygon_index(vorn)
1788+
A += get_area(vorn, i)
1789+
end
1790+
@test A 1.0
1791+
vorn = voronoi(tri)
1792+
poly = get_polygon_coordinates(vorn, 3, (0.0, 1.0, 0.0, 1.0))
1793+
@test poly [(0.675, 1.0), (0.0, 1.0), (0.0, 0.95), (0.6, 0.95), (0.675, 1.0)]
17761794
end

0 commit comments

Comments
 (0)