-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathtest_gfxpoly.py
More file actions
36 lines (31 loc) · 1.16 KB
/
test_gfxpoly.py
File metadata and controls
36 lines (31 loc) · 1.16 KB
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
import gfxpoly
# basic functionality
p = gfxpoly.GfxPoly(gridsize=0.1)
assert p.gridsize == 0.1
assert p.area() == 0.0
assert p.union(p).area() == 0.0
assert p.intersect(p).area() == 0.0
assert p.bbox() == [0., 0., 0., 0.]
assert p.decompose() == []
# canvas
c = gfxpoly.GfxCanvas(gridsize=0.1)
c.moveTo(100, 150)
c.lineTo(200, 150)
c.lineTo(200, 250)
c.lineTo(100, 250)
c.lineTo(100, 150)
c.close()
p = c.result()
# intersection
p2 = p.move(50, 51)
i = p.intersect(p2)
assert i.bbox() == [150.0, 201.0, 200.0, 250.0]
assert i.decompose() == [('m', 150.0, 201.0), ('l', 150.0, 250.0), ('l', 200.0, 250.0), ('l', 200.0, 201.0), ('l', 150.0, 201.0)]
# union
i = p.union(p2)
assert i.bbox() == [100.0, 150.0, 250.0, 301.0]
assert i.decompose() == [('m', 100.0, 150.0), ('l', 100.0, 250.0), ('l', 150.0, 250.0), ('l', 150.0, 301.0), ('l', 250.0, 301.0), ('l', 250.0, 201.0), ('l', 200.0, 201.0), ('l', 200.0, 150.0), ('l', 100.0, 150.0)]
# subtract
i = p.subtract(p2)
assert i.bbox() == [100.0, 150.0, 200.0, 250.0]
assert i.decompose() == [('m', 100.0, 150.0), ('l', 100.0, 250.0), ('l', 150.0, 250.0), ('l', 150.0, 201.0), ('l', 200.0, 201.0), ('l', 200.0, 150.0), ('l', 100.0, 150.0)]