|
1 | | -# from compas_cgal.straight_skeleton_2 import interior_straight_skeleton |
2 | | -# from compas_cgal.straight_skeleton_2 import interior_straight_skeleton_with_holes |
3 | | -# from compas_cgal.straight_skeleton_2 import offset_polygon |
4 | | -# from compas_cgal.straight_skeleton_2 import offset_polygon_with_holes |
5 | | -# from compas_cgal.straight_skeleton_2 import weighted_offset_polygon |
| 1 | +from compas_cgal.straight_skeleton_2 import interior_straight_skeleton |
| 2 | +from compas_cgal.straight_skeleton_2 import interior_straight_skeleton_with_holes |
| 3 | +from compas_cgal.straight_skeleton_2 import offset_polygon |
| 4 | +from compas_cgal.straight_skeleton_2 import offset_polygon_with_holes |
| 5 | +from compas_cgal.straight_skeleton_2 import weighted_offset_polygon |
6 | 6 |
|
7 | 7 |
|
8 | | -# def test_straight_polygon(): |
9 | | -# points = [ |
10 | | -# (-1, -1, 0), |
11 | | -# (0, -12, 0), |
12 | | -# (1, -1, 0), |
13 | | -# (12, 0, 0), |
14 | | -# (1, 1, 0), |
15 | | -# (0, 12, 0), |
16 | | -# (-1, 1, 0), |
17 | | -# (-12, 0, 0), |
18 | | -# ] |
19 | | -# graph = interior_straight_skeleton(points) |
20 | | -# assert graph.number_of_edges() == 16 |
| 8 | +def test_straight_polygon(): |
| 9 | + points = [ |
| 10 | + (-1, -1, 0), |
| 11 | + (0, -12, 0), |
| 12 | + (1, -1, 0), |
| 13 | + (12, 0, 0), |
| 14 | + (1, 1, 0), |
| 15 | + (0, 12, 0), |
| 16 | + (-1, 1, 0), |
| 17 | + (-12, 0, 0), |
| 18 | + ] |
| 19 | + graph = interior_straight_skeleton(points) |
| 20 | + assert graph.number_of_edges() == 16 |
21 | 21 |
|
22 | 22 |
|
23 | | -# def test_straight_skeleton_with_holes(): |
24 | | -# points = [ |
25 | | -# (-1, -1, 0), |
26 | | -# (0, -12, 0), |
27 | | -# (1, -1, 0), |
28 | | -# (12, 0, 0), |
29 | | -# (1, 1, 0), |
30 | | -# (0, 12, 0), |
31 | | -# (-1, 1, 0), |
32 | | -# (-12, 0, 0), |
33 | | -# ] |
34 | | -# hole = [(-1, 0, 0), (0, 1, 0), (1, 0, 0), (0, -1, 0)] |
35 | | -# graph = interior_straight_skeleton_with_holes(points, [hole]) |
36 | | -# assert graph.number_of_edges() == 32 |
| 23 | +def test_straight_skeleton_with_holes(): |
| 24 | + points = [ |
| 25 | + (-1, -1, 0), |
| 26 | + (0, -12, 0), |
| 27 | + (1, -1, 0), |
| 28 | + (12, 0, 0), |
| 29 | + (1, 1, 0), |
| 30 | + (0, 12, 0), |
| 31 | + (-1, 1, 0), |
| 32 | + (-12, 0, 0), |
| 33 | + ] |
| 34 | + hole = [(-1, 0, 0), (0, 1, 0), (1, 0, 0), (0, -1, 0)] |
| 35 | + graph = interior_straight_skeleton_with_holes(points, [hole]) |
| 36 | + assert graph.number_of_edges() == 32 |
37 | 37 |
|
38 | 38 |
|
39 | | -# def test_offset(): |
40 | | -# points = [ |
41 | | -# (-1, -1, 0), |
42 | | -# (0, -12, 0), |
43 | | -# (1, -1, 0), |
44 | | -# (12, 0, 0), |
45 | | -# (1, 1, 0), |
46 | | -# (0, 12, 0), |
47 | | -# (-1, 1, 0), |
48 | | -# (-12, 0, 0), |
49 | | -# ] |
50 | | -# offset = 0.5 |
51 | | -# polygons = offset_polygon(points, offset) |
52 | | -# assert len(polygons) == 1, len(polygons) |
53 | | -# polygons = offset_polygon(points, -offset) |
54 | | -# assert len(polygons) == 1, len(polygons) |
55 | | -# weights = [0.1, 0.5, 0.3, 0.3, 0.9, 1.0, 0.2, 1.0] |
56 | | -# polygons = weighted_offset_polygon(points, offset, weights) |
57 | | -# assert len(polygons) == 1, len(polygons) |
58 | | -# polygons = weighted_offset_polygon(points, -offset, weights) |
59 | | -# assert len(polygons) == 1, len(polygons) |
| 39 | +def test_offset(): |
| 40 | + points = [ |
| 41 | + (-1, -1, 0), |
| 42 | + (0, -12, 0), |
| 43 | + (1, -1, 0), |
| 44 | + (12, 0, 0), |
| 45 | + (1, 1, 0), |
| 46 | + (0, 12, 0), |
| 47 | + (-1, 1, 0), |
| 48 | + (-12, 0, 0), |
| 49 | + ] |
| 50 | + offset = 0.5 |
| 51 | + polygons = offset_polygon(points, offset) |
| 52 | + assert len(polygons) == 1, len(polygons) |
| 53 | + polygons = offset_polygon(points, -offset) |
| 54 | + assert len(polygons) == 1, len(polygons) |
| 55 | + weights = [0.1, 0.5, 0.3, 0.3, 0.9, 1.0, 0.2, 1.0] |
| 56 | + polygons = weighted_offset_polygon(points, offset, weights) |
| 57 | + assert len(polygons) == 1, len(polygons) |
| 58 | + polygons = weighted_offset_polygon(points, -offset, weights) |
| 59 | + assert len(polygons) == 1, len(polygons) |
60 | 60 |
|
61 | 61 |
|
62 | | -# def test_offset_with_holes(): |
63 | | -# points = [ |
64 | | -# (65.322, -16.156, 0.0), |
65 | | -# (65.322, -11.157, 0.0), |
66 | | -# (63.022, -11.157, 0.0), |
67 | | -# (63.022, -11.167, 0.0), |
68 | | -# (60.042, -11.167, 0.0), |
69 | | -# (60.042, -16.156, 0.0), |
70 | | -# (61.702, -16.156, 0.0), |
71 | | -# (61.702, -16.416, 0.0), |
72 | | -# (61.712, -16.416, 0.0), |
73 | | -# (61.712, -16.156, 0.0), |
74 | | -# ] |
75 | | -# holes = [ |
76 | | -# [ |
77 | | -# (63.912, -14.956, 0.0), |
78 | | -# (63.652, -14.956, 0.0), |
79 | | -# (63.652, -14.946, 0.0), |
80 | | -# (61.442, -14.946, 0.0), |
81 | | -# (61.442, -12.367, 0.0), |
82 | | -# (61.702, -12.367, 0.0), |
83 | | -# (61.702, -12.377, 0.0), |
84 | | -# (63.652, -12.377, 0.0), |
85 | | -# (63.652, -12.367, 0.0), |
86 | | -# (63.912, -12.367, 0.0), |
87 | | -# (63.912, -12.834, 0.0), |
88 | | -# ], |
89 | | -# [(61.452, -14.946, 0.0), (61.532, -14.949, 0.0), (61.702, -14.956, 0.0), (61.532, -14.956, 0.0), (61.452, -14.956, 0.0)], |
90 | | -# ] |
91 | | -# result = offset_polygon_with_holes(points, holes, -0.2) |
92 | | -# assert len(result) == 1, len(result) |
93 | | -# polygon, holes = result[0] |
94 | | -# assert len(holes) == 1, len(holes) |
95 | | -# area_net = polygon.area - sum(h.area for h in holes) |
96 | | -# assert abs(area_net - 26.25329) < 1e-3, area_net |
| 62 | +def test_offset_with_holes(): |
| 63 | + points = [ |
| 64 | + (65.322, -16.156, 0.0), |
| 65 | + (65.322, -11.157, 0.0), |
| 66 | + (63.022, -11.157, 0.0), |
| 67 | + (63.022, -11.167, 0.0), |
| 68 | + (60.042, -11.167, 0.0), |
| 69 | + (60.042, -16.156, 0.0), |
| 70 | + (61.702, -16.156, 0.0), |
| 71 | + (61.702, -16.416, 0.0), |
| 72 | + (61.712, -16.416, 0.0), |
| 73 | + (61.712, -16.156, 0.0), |
| 74 | + ] |
| 75 | + holes = [ |
| 76 | + [ |
| 77 | + (63.912, -14.956, 0.0), |
| 78 | + (63.652, -14.956, 0.0), |
| 79 | + (63.652, -14.946, 0.0), |
| 80 | + (61.442, -14.946, 0.0), |
| 81 | + (61.442, -12.367, 0.0), |
| 82 | + (61.702, -12.367, 0.0), |
| 83 | + (61.702, -12.377, 0.0), |
| 84 | + (63.652, -12.377, 0.0), |
| 85 | + (63.652, -12.367, 0.0), |
| 86 | + (63.912, -12.367, 0.0), |
| 87 | + (63.912, -12.834, 0.0), |
| 88 | + ], |
| 89 | + [(61.452, -14.946, 0.0), (61.532, -14.949, 0.0), (61.702, -14.956, 0.0), (61.532, -14.956, 0.0), (61.452, -14.956, 0.0)], |
| 90 | + ] |
| 91 | + result = offset_polygon_with_holes(points, holes, -0.2) |
| 92 | + assert len(result) == 1, len(result) |
| 93 | + polygon, holes = result[0] |
| 94 | + assert len(holes) == 1, len(holes) |
| 95 | + area_net = polygon.area - sum(h.area for h in holes) |
| 96 | + assert abs(area_net - 26.25329) < 1e-3, area_net |
0 commit comments