5555 @test Polygon (p) == Polygon (Array (p))
5656 end
5757end
58+
59+ @testset " triangulation" begin
60+ tri = Triangle (Point2f (- 0.5 , - 0.5 ), Point2f (0.8 , 0 ), Point2f (0 , 0.8 ))
61+ for phi in rand (0 : 2pi , 10 )
62+ @test ! in (Point2f (cos (phi), sin (phi)), tri)
63+ end
64+ for phi in rand (0 : 2pi , 10 )
65+ @test in (0.2 * Point2f (cos (phi), sin (phi)), tri)
66+ end
67+ @test Point2f (0 ) in tri # sanity check
68+
69+ # corner cases
70+ @test Point2f (- 0.5 ) in tri
71+ @test Point2f (0 , 0.8 ) in tri
72+ @test Point2f (0.8 , 0 ) in tri
73+
74+ # TODO : test snip directly?
75+ ps = Point2f[(0 ,0 ), (1 ,0 ), (1 ,1 ), (0 ,1 )]
76+ @test decompose (GLTriangleFace, ps) == GLTriangleFace[(4 ,1 ,2 ), (2 ,3 ,4 )]
77+
78+ ps = [Point2f (cos (phi), sin (phi)) for phi in range (0 , 2pi , length= 8 )[1 : end - 1 ]]
79+ fs = decompose (GLTriangleFace, ps)
80+ @test fs == GLTriangleFace[(7 ,1 ,2 ), (2 ,3 ,4 ), (4 ,5 ,6 ), (6 ,7 ,2 ), (2 ,4 ,6 )]
81+ lfs = decompose (LineFace{Int32}, fs)
82+ for i in 1 : 7
83+ @test (LineFace (i, mod1 (i+ 1 , 7 )) in lfs) || (LineFace (mod1 (i+ 1 , 7 ), i) in lfs)
84+ end
85+
86+ @testset " earcut" begin
87+ ps = Point2i[(- 1 ,- 1 ), (1 ,- 1 ), (1 ,1 ), (- 1 ,1 )]
88+ @test GeometryBasics. earcut_triangulate ([Point {2, Int32} .(ps)]) == GLTriangleFace[(3 ,4 ,1 ), (1 ,2 ,3 )]
89+ @test GeometryBasics. earcut_triangulate ([Point {2, Int64} .(ps)]) == GLTriangleFace[(3 ,4 ,1 ), (1 ,2 ,3 )]
90+ @test GeometryBasics. earcut_triangulate ([Point {2, Float32} .(ps)]) == GLTriangleFace[(3 ,4 ,1 ), (1 ,2 ,3 )]
91+ @test GeometryBasics. earcut_triangulate ([Point {2, Float64} .(ps)]) == GLTriangleFace[(3 ,4 ,1 ), (1 ,2 ,3 )]
92+
93+ ps2 = Point2i[(0 ,- 1 ), (1 ,0 ), (0 ,1 ), (- 1 ,0 )]
94+ @test faces (Polygon (Point2 {Int32} .(ps), [Point2 {Int32} .(ps2)])) == GLTriangleFace[(4 ,8 ,7 ), (5 ,8 ,1 ), (6 ,5 ,2 ), (3 ,7 ,6 )]
95+ @test faces (Polygon (Point2 {Int64} .(ps), [Point2 {Int64} .(ps2)])) == GLTriangleFace[(4 ,8 ,7 ), (5 ,8 ,1 ), (6 ,5 ,2 ), (3 ,7 ,6 )]
96+ @test faces (Polygon (Point2 {Int8} .(ps), [Point2 {Int8} .(ps2)])) == GLTriangleFace[(4 ,8 ,7 ), (5 ,8 ,1 ), (6 ,5 ,2 ), (3 ,7 ,6 )]
97+ @test faces (Polygon (Point2 {Float32} .(ps), [Point2 {Float32} .(ps2)])) == GLTriangleFace[(4 ,8 ,7 ), (5 ,8 ,1 ), (6 ,5 ,2 ), (3 ,7 ,6 )]
98+ @test faces (Polygon (Point2 {Float64} .(ps), [Point2 {Float64} .(ps2)])) == GLTriangleFace[(4 ,8 ,7 ), (5 ,8 ,1 ), (6 ,5 ,2 ), (3 ,7 ,6 )]
99+ @test faces (Polygon (Point2 {Float16} .(ps), [Point2 {Float16} .(ps2)])) == GLTriangleFace[(4 ,8 ,7 ), (5 ,8 ,1 ), (6 ,5 ,2 ), (3 ,7 ,6 )]
100+ end
101+ end
0 commit comments