Skip to content

Commit aca5503

Browse files
authored
isconvex fix. Old implementation used convex hull, which leads to pathological incorrect cases. now we use the literal convexity definition (interior angles all <= pi-radians) (#1270)
1 parent 6afcab1 commit aca5503

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/predicates/isconvex.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,11 @@ isconvex(::Tetrahedron) = true
6060

6161
isconvex(p::Polygon) = _isconvex(p, Val(embeddim(p)))
6262

63-
_isconvex(p::Polygon, ::Val{2}) = Set(eachvertex(convexhull(p))) == Set(eachvertex(p))
63+
function _isconvex(p::Polygon, ::Val{2})
64+
hasholes(p) && return false
65+
r = first(rings(p))
66+
all-> θ oftype(θ, π), innerangles(r))
67+
end
6468

6569
_isconvex(p::Polygon, ::Val{3}) = isconvex(proj2D(p))
6670

test/predicates.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,11 @@ end
247247
@test !isconvex(poly2)
248248
poly = PolyArea(cart.([(0, 0), (1, 0), (1, 1), (0.5, 0.5), (0, 1)]))
249249
@test !isconvex(poly)
250+
poly1 = PolyArea(cart.([(0, 0), (4, 0), (0, 4), (4, 4)]))
251+
poly2 = PolyArea(cart.([(0, 0), (4, 0), (4, 4), (2, 3), (0, 4)]))
252+
@test !isconvex(poly1)
253+
@test !isconvex(poly2)
254+
250255
h = Hexahedron(
251256
cart(0, 0, 0),
252257
cart(1, 0, 0),

0 commit comments

Comments
 (0)