11import pyclipper2
22
3+
34def test_point64 ():
45 """Test Point64 creation and attributes"""
56 p = pyclipper2 .Point64 (100 , 200 )
67 assert p .x == 100
78 assert p .y == 200
89 print (f"✓ Point64: { p } " )
9-
10+
11+
1012def test_pointd ():
1113 """Test PointD creation and attributes"""
1214 p = pyclipper2 .PointD (10.5 , 20.7 )
1315 assert p .x == 10.5
1416 assert p .y == 20.7
1517 print (f"✓ PointD: { p } " )
1618
19+
1720def test_enums ():
1821 """Test enum values"""
19- assert pyclipper2 .ClipType .Union
20- assert pyclipper2 .FillRule .EvenOdd
21- assert pyclipper2 .JoinType .Round
22- assert pyclipper2 .EndType .Polygon
22+ assert pyclipper2 .ClipType .UNION
23+ assert pyclipper2 .ClipType .DIFFERENCE
24+ assert pyclipper2 .ClipType .INTERSECTION
25+ assert pyclipper2 .ClipType .XOR
26+ assert pyclipper2 .FillRule .NON_ZERO
27+ assert pyclipper2 .FillRule .POSITIVE
28+ assert pyclipper2 .FillRule .NEGATIVE
29+ assert pyclipper2 .FillRule .EVEN_ODD
30+ assert pyclipper2 .EndType .POLYGON
31+ assert pyclipper2 .EndType .JOINED
32+ assert pyclipper2 .EndType .BUTT
33+ assert pyclipper2 .EndType .SQUARE
34+ assert pyclipper2 .EndType .ROUND
35+ assert pyclipper2 .PathType .SUBJECT
36+ assert pyclipper2 .PathType .CLIP
37+ assert pyclipper2 .JoinWith .NO_JOIN
38+ assert pyclipper2 .JoinWith .LEFT
39+ assert pyclipper2 .JoinWith .RIGHT
40+ assert pyclipper2 .PointInPolygonResult .IS_INSIDE
41+ assert pyclipper2 .PointInPolygonResult .IS_OUTSIDE
42+ assert pyclipper2 .PointInPolygonResult .IS_ON
43+ assert pyclipper2 .JoinType .ROUND
44+ assert pyclipper2 .JoinType .SQUARE
45+ assert pyclipper2 .JoinType .BEVEL
46+ assert pyclipper2 .JoinType .MITER
2347 print ("✓ Enums work" )
2448
49+
2550def test_rect64 ():
2651 """Test Rect64"""
2752 r = pyclipper2 .Rect64 (0 , 0 , 100 , 100 )
2853 assert r .left == 0
2954 assert r .right == 100
3055 print ("✓ Rect64 works" )
3156
57+
3258def test_area ():
3359 """Test area calculation"""
3460 # Create a simple square path
3561 square = [
3662 pyclipper2 .Point64 (0 , 0 ),
3763 pyclipper2 .Point64 (100 , 0 ),
3864 pyclipper2 .Point64 (100 , 100 ),
39- pyclipper2 .Point64 (0 , 100 )
65+ pyclipper2 .Point64 (0 , 100 ),
4066 ]
4167 area = pyclipper2 .area (square )
4268 print (f"✓ Area of square: { area } " )
4369 assert area != 0 # Should be 10000
4470
71+
4572def test_is_positive ():
4673 """Test is_positive orientation"""
4774 # Clockwise square (should be negative in typical coordinate systems)
4875 square = [
4976 pyclipper2 .Point64 (0 , 0 ),
5077 pyclipper2 .Point64 (100 , 0 ),
5178 pyclipper2 .Point64 (100 , 100 ),
52- pyclipper2 .Point64 (0 , 100 )
79+ pyclipper2 .Point64 (0 , 100 ),
5380 ]
5481 result = pyclipper2 .is_positive (square )
5582 print (f"✓ is_positive: { result } " )
5683
84+
5785def test_clipper_offset ():
5886 """Test ClipperOffset"""
5987 offset = pyclipper2 .ClipperOffset ()
6088 print ("✓ ClipperOffset created" )
61-
89+
6290 # Create a simple path
6391 path = [
6492 pyclipper2 .Point64 (0 , 0 ),
6593 pyclipper2 .Point64 (100 , 0 ),
6694 pyclipper2 .Point64 (100 , 100 ),
67- pyclipper2 .Point64 (0 , 100 )
95+ pyclipper2 .Point64 (0 , 100 ),
6896 ]
69-
70- offset .add_path (path , pyclipper2 .JoinType .Round , pyclipper2 .EndType .Polygon )
97+
98+ offset .add_path (path , pyclipper2 .JoinType .ROUND , pyclipper2 .EndType .POLYGON )
7199 print ("✓ Path added to offset" )
72-
100+
73101 result = []
74102 offset .execute (10.0 , result )
75103 print (f"✓ Offset executed, result paths: { len (result )} " )
76104
105+
77106def test_version ():
78107 """Test version constant"""
79108 version = pyclipper2 .VERSION
80109 print (f"✓ Clipper2 version: { version } " )
81110
82- if __name__ == "__main__" :
83- print ("Testing Clipper2 Python bindings...\n " )
84-
85- test_point64 ()
86- test_pointd ()
87- test_enums ()
88- test_rect64 ()
89- test_area ()
90- test_is_positive ()
91- test_clipper_offset ()
92- test_version ()
93-
94- print ("\n ✅ All tests passed!" )
111+
112+ def test_point_in_polygon ():
113+ """Test point_in_polygon function"""
114+ polygon = [
115+ pyclipper2 .Point64 (0 , 0 ),
116+ pyclipper2 .Point64 (100 , 0 ),
117+ pyclipper2 .Point64 (100 , 100 ),
118+ pyclipper2 .Point64 (0 , 100 ),
119+ ]
120+ inside_point = pyclipper2 .Point64 (50 , 50 )
121+ outside_point = pyclipper2 .Point64 (150 , 150 )
122+
123+ inside_result = pyclipper2 .point_in_polygon (inside_point , polygon )
124+ outside_result = pyclipper2 .point_in_polygon (outside_point , polygon )
125+
126+ print (f"✓ point_in_polygon (inside): { inside_result } " )
127+ print (f"✓ point_in_polygon (outside): { outside_result } " )
128+ assert inside_result == pyclipper2 .PointInPolygonResult .IS_INSIDE
129+ assert outside_result == pyclipper2 .PointInPolygonResult .IS_OUTSIDE
0 commit comments