Skip to content

Commit 2f79346

Browse files
souma4juliohm
andauthored
Implementing isconvex(Hexahedron) (#1259)
* first commit for isconvex(Hexahedron). * simplify isconvex using all() Co-authored-by: Júlio Hoffimann <[email protected]> * added condition 2 for hexahedron convexity check * cleanup and optimization * simplifying for our hexahedron implementation * Refactor tests --------- Co-authored-by: Júlio Hoffimann <[email protected]>
1 parent e72f2fd commit 2f79346

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed

src/predicates/isconvex.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ _isconvex(p::Polygon, ::Val{2}) = Set(eachvertex(convexhull(p))) == Set(eachvert
6464

6565
_isconvex(p::Polygon, ::Val{3}) = isconvex(proj2D(p))
6666

67+
isconvex(h::Hexahedron) = all(isconvex, boundary(h))
68+
6769
isconvex(m::Multi) = isapproxequal(measure(convexhull(m)), measure(m))
6870

6971
# --------------

test/predicates.jl

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,87 @@ 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+
h = Hexahedron(
251+
cart(0, 0, 0),
252+
cart(1, 0, 0),
253+
cart(1, 1, 0),
254+
cart(0, 1, 0),
255+
cart(0, 0, 1),
256+
cart(1, 0, 1),
257+
cart(1, 1, 1),
258+
cart(0, 1, 1)
259+
)
260+
@test isconvex(h)
261+
h = Hexahedron(
262+
cart(0, 0, 0),
263+
cart(1, 0, 0),
264+
cart(0.9, 0.9, 0),
265+
cart(0, 1, 0),
266+
cart(0, 0, 1),
267+
cart(1, 0, 1),
268+
cart(1, 1, 1),
269+
cart(0, 1, 1)
270+
)
271+
@test !isconvex(h)
272+
h = Hexahedron(
273+
cart(0, 0, 0),
274+
cart(1, 0, 0),
275+
cart(1, 1, 0),
276+
cart(0, 1, 0),
277+
cart(0.25, 0.25, 0.2),
278+
cart(0.75, 0.25, 0.2),
279+
cart(0.75, 0.26, 0.2),
280+
cart(0.25, 0.26, 0.2)
281+
)
282+
@test isconvex(h)
283+
h = Hexahedron(
284+
cart(0, 0, 0),
285+
cart(1, 0, 0),
286+
cart(1, 1, 0),
287+
cart(0, 1, 0),
288+
cart(0.25, 0.25, 0.2),
289+
cart(0.75, 0.25, 0.2),
290+
cart(0.75, 0.25, 0.21),
291+
cart(0.25, 0.25, 0.21)
292+
)
293+
@test !isconvex(h)
294+
h = Hexahedron(
295+
cart(0, 0, 0.1),
296+
cart(1, 0, 0.1),
297+
cart(1, 1, 0.1),
298+
cart(0, 1, 0.1),
299+
cart(0, 0, 0.3),
300+
cart(1, 0, 0.2),
301+
cart(1, 1, 0.3),
302+
cart(0, 1, 0.2)
303+
)
304+
@test !isconvex(h)
305+
h = Hexahedron(
306+
cart(0, 0, 0),
307+
cart(1, 0, 0),
308+
cart(1, 1, 0),
309+
cart(0, 1, 0),
310+
cart(0, 0, 1),
311+
cart(1, 0, 1),
312+
cart(1, 1, -1),
313+
cart(0, 1, -1)
314+
)
315+
@test !isconvex(h)
316+
h0 = Hexahedron(
317+
cart(0, 0, 0),
318+
cart(1, 0, 0),
319+
cart(1, 1, 0),
320+
cart(0, 1, 0),
321+
cart(0.25, 0.25, 0.2),
322+
cart(0.75, 0.25, 0.2),
323+
cart(0.75, 0.26, 0.2),
324+
cart(0.25, 0.26, 0.2)
325+
)
326+
h1 = h0 |> Affine(AngleAxis(T(0.75), T(1.0), T(0.5), T(0.25)), T[-5, 2, 2])
327+
h2 = h0 |> Stretch(T(1.0), T(2.0), T(5.0))
328+
@test isconvex(h0)
329+
@test isconvex(h1)
330+
@test isconvex(h2)
250331
end
251332

252333
@testitem "issubset" setup = [Setup] begin

0 commit comments

Comments
 (0)