-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpolygon_test.py
More file actions
43 lines (36 loc) · 925 Bytes
/
polygon_test.py
File metadata and controls
43 lines (36 loc) · 925 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from plot import Plot
from plot.polygon import Polygon
from plot.utils import vec2
def draw_poly(p: Plot, poly: Polygon):
p.goto(*poly.points[0])
for point in poly.points[1:]:
p.lineto(*point)
p.lineto(*poly.points[0])
def main(p: Plot):
p.setup()
poly = Polygon([
vec2(30, 30),
vec2(70, 30),
vec2(70, 70),
vec2(30, 70),
])
clip_poly = Polygon([
vec2(50, 50),
vec2(80, 50),
vec2(80, 80),
vec2(50, 80),
])
# draw_poly(p, poly)
# draw_poly(p, clip_poly)
poly.clip(clip_poly)
draw_poly(p, poly)
# sp1 = vec2(10, 10)
# sp2 = vec2(30, 20)
# cp1 = vec2(15, 15)
# cp2 = vec2(30, 45)
# p.goto(*cp1)
# p.lineto(*cp2)
# p.goto(*sp1)
# p.lineto(*sp2)
# p.dot(*Polygon._do_clip_intersection(cp1, cp2, sp1, sp2))
# print(Polygon._inside_clip(cp1, cp2, vec2(50, 40)))