Skip to content

Commit f398fb7

Browse files
committed
Improve test coverage
1 parent ddc01f8 commit f398fb7

File tree

6 files changed

+293
-325
lines changed

6 files changed

+293
-325
lines changed

environment/actions/triangular_actions.py

Lines changed: 54 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,6 @@ def flip_edge(mesh_analysis, n1: Node, n2: Node) -> True:
7979

8080
after_check = check_mesh(mesh_analysis, mesh_before)
8181
if not after_check:
82-
plot_mesh(mesh_before)
83-
plot_mesh(mesh_analysis.mesh)
8482
raise ValueError("Some checks are missing")
8583

8684
return valid_action, topo, geo
@@ -242,23 +240,21 @@ def collapse_edge(mesh_analysis, n1: Node, n2: Node) -> True:
242240
ds = ds11.get_beta(2)
243241
if i > 30:
244242
i = 0
245-
plot_mesh(mesh_analysis.mesh)
246243
raise ValueError("Potential infinite loop in action collapse")
247244
else:
248245
ds = d2s.get_beta(1)
249246
ds.set_node(n1)
250247
ds1 = ds.get_beta(1)
251248
if i > 30:
252249
i = 0
253-
plot_mesh(mesh_analysis.mesh)
254250
raise ValueError("Potential infinite loop in action collapse")
255251

256252
found, new_x, new_y = mesh_analysis.find_star_vertex(n1)
257253
if found:
258254
n1.set_xy(new_x, new_y)
259255
else:
260-
plot_mesh(mesh_before)
261-
plot_mesh(mesh_analysis.mesh)
256+
# plot_mesh(mesh_before)
257+
# plot_mesh(mesh_analysis.mesh)
262258
mesh_analysis.find_star_vertex(n1, plot=True)
263259
raise ValueError("No star vertex found")
264260

@@ -301,7 +297,7 @@ def collapse_edge(mesh_analysis, n1: Node, n2: Node) -> True:
301297

302298
after_check = check_mesh(mesh_analysis, mesh_before)
303299
if not after_check:
304-
mesh_analysis.is_star_vertex(n1, np.array([n1.x(), n1.y()]), True)
300+
# mesh_analysis.is_star_vertex(n1, np.array([n1.x(), n1.y()]), True)
305301
raise ValueError("Some checks are missing")
306302
return True, topo, geo
307303

@@ -352,54 +348,54 @@ def check_mesh(mesh_analysis, m=None) -> bool:
352348
return False
353349
return True
354350

355-
356-
def check_mesh_debug(mesh_analysis, mesh_before=None)->True:
357-
for dart_info in mesh_analysis.mesh.active_darts():
358-
#Check beta2 relation
359-
d = dart_info[0]
360-
d2 = dart_info[2]
361-
# if associated twin dart no longer exist
362-
if d2 >= 0 and mesh_analysis.mesh.dart_info[d2, 0] < 0:
363-
plot_mesh(mesh_analysis.mesh)
364-
if mesh_before is not None:
365-
plot_mesh(mesh_before)
366-
raise ValueError("error beta2")
367-
# if beta2 relation is not symetrical
368-
elif d2 >= 0 and mesh_analysis.mesh.dart_info[d2, 2] != d:
369-
plot_mesh(mesh_analysis.mesh)
370-
if mesh_before is not None:
371-
plot_mesh(mesh_before)
372-
raise ValueError("error beta2")
373-
# null dart
374-
elif d2>=0 and mesh_analysis.mesh.dart_info[d2, 3] == mesh_analysis.mesh.dart_info[d, 3]:
375-
plot_mesh(mesh_analysis.mesh)
376-
if mesh_before is not None:
377-
plot_mesh(mesh_before)
378-
raise ValueError("same node for twin darts")
379-
#if adjacent face is the same
380-
elif d2>=0 and mesh_analysis.mesh.dart_info[d2, 4] == mesh_analysis.mesh.dart_info[d, 4]:
381-
plot_mesh(mesh_analysis.mesh)
382-
if mesh_before is not None:
383-
plot_mesh(mesh_before)
384-
raise ValueError("same adjacent face")
385-
386-
387-
d1 = mesh_analysis.mesh.dart_info[d,1]
388-
d11 = mesh_analysis.mesh.dart_info[d1,1]
389-
390-
#Check beta1
391-
if mesh_analysis.mesh.dart_info[d11,1]!=d :
392-
plot_mesh(mesh_analysis.mesh)
393-
if mesh_before is not None:
394-
plot_mesh(mesh_before)
395-
raise ValueError("error beta1")
396-
397-
if d2 >= 0 :
398-
d = Dart(mesh_analysis.mesh, d)
399-
d2, d1, d11, d21, d211, n1, n2, n3, n4 = mesh_analysis.mesh.active_triangles(d)
400-
401-
if len(set([n1.id, n2.id, n3.id, n4.id])) < 4:
402-
plot_mesh(mesh_analysis.mesh)
403-
if mesh_before is not None:
404-
plot_mesh(mesh_before)
405-
raise ValueError("same traingle for two faces")
351+
#
352+
# def check_mesh_debug(mesh_analysis, mesh_before=None)->True:
353+
# for dart_info in mesh_analysis.mesh.active_darts():
354+
# #Check beta2 relation
355+
# d = dart_info[0]
356+
# d2 = dart_info[2]
357+
# # if associated twin dart no longer exist
358+
# if d2 >= 0 and mesh_analysis.mesh.dart_info[d2, 0] < 0:
359+
# plot_mesh(mesh_analysis.mesh)
360+
# if mesh_before is not None:
361+
# plot_mesh(mesh_before)
362+
# raise ValueError("error beta2")
363+
# # if beta2 relation is not symetrical
364+
# elif d2 >= 0 and mesh_analysis.mesh.dart_info[d2, 2] != d:
365+
# plot_mesh(mesh_analysis.mesh)
366+
# if mesh_before is not None:
367+
# plot_mesh(mesh_before)
368+
# raise ValueError("error beta2")
369+
# # null dart
370+
# elif d2>=0 and mesh_analysis.mesh.dart_info[d2, 3] == mesh_analysis.mesh.dart_info[d, 3]:
371+
# plot_mesh(mesh_analysis.mesh)
372+
# if mesh_before is not None:
373+
# plot_mesh(mesh_before)
374+
# raise ValueError("same node for twin darts")
375+
# #if adjacent face is the same
376+
# elif d2>=0 and mesh_analysis.mesh.dart_info[d2, 4] == mesh_analysis.mesh.dart_info[d, 4]:
377+
# plot_mesh(mesh_analysis.mesh)
378+
# if mesh_before is not None:
379+
# plot_mesh(mesh_before)
380+
# raise ValueError("same adjacent face")
381+
#
382+
#
383+
# d1 = mesh_analysis.mesh.dart_info[d,1]
384+
# d11 = mesh_analysis.mesh.dart_info[d1,1]
385+
#
386+
# #Check beta1
387+
# if mesh_analysis.mesh.dart_info[d11,1]!=d :
388+
# plot_mesh(mesh_analysis.mesh)
389+
# if mesh_before is not None:
390+
# plot_mesh(mesh_before)
391+
# raise ValueError("error beta1")
392+
#
393+
# if d2 >= 0 :
394+
# d = Dart(mesh_analysis.mesh, d)
395+
# d2, d1, d11, d21, d211, n1, n2, n3, n4 = mesh_analysis.mesh.active_triangles(d)
396+
#
397+
# if len(set([n1.id, n2.id, n3.id, n4.id])) < 4:
398+
# plot_mesh(mesh_analysis.mesh)
399+
# if mesh_before is not None:
400+
# plot_mesh(mesh_before)
401+
# raise ValueError("same traingle for two faces")

mesh_model/mesh_analysis/global_mesh_analysis.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ def get_angle(self, d1: Dart, d2: Dart) -> float:
5959
angle_rad = atan2(cross, dot)
6060
angle = degrees(angle_rad) % 360
6161
if np.isnan(angle):
62-
plot_mesh(self.n.mesh)
6362
raise ValueError("Angle error")
6463
return angle
6564

@@ -135,8 +134,6 @@ def degree(self) -> int:
135134
else:
136135
adjacency += 0.5
137136
if adjacency != int(adjacency):
138-
#adjacency = int(adjacency+0.5)
139-
plot_mesh(self.n.mesh)
140137
raise ValueError("Adjacency error")
141138
return adjacency
142139

mesh_model/mesh_analysis/quadmesh_analysis.py

Lines changed: 0 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -127,130 +127,6 @@ def get_dart_geometric_quality(self, d: Dart, m=None) -> int:
127127
else:
128128
raise ValueError("Quality configuration doesn't exist")
129129

130-
def find_star_vertex(self, n:Node, plot=False)-> (bool, float, float):
131-
# Retrieve all neighboring vertices in order
132-
d = n.get_dart()
133-
d2 = d.get_beta(2)
134-
n_start = d2.get_node() # First neighbour to retrieve
135-
136-
adj_nodes = [n_start]
137-
nodes_coord = [[n_start.x(), n_start.y()]]
138-
139-
d = d2.get_beta(1)
140-
d2 = d.get_beta(2)
141-
n_neighbour = d2.get_node()
142-
143-
# As long as we haven't returned to the first neighbor, we keep searching.
144-
# This works because the collapse action is restricted to inner darts that are not connected to a boundary node.
145-
# Therefore, we are guaranteed to find the first vertex by following the beta1 and beta2 relations.
146-
147-
while n_neighbour != n_start:
148-
adj_nodes.append(n_neighbour)
149-
nodes_coord.append([n_neighbour.x(), n_neighbour.y()])
150-
d = d2.get_beta(1)
151-
d2 = d.get_beta(2)
152-
n_neighbour = d2.get_node()
153-
154-
nodes_coord = np.array(nodes_coord)
155-
156-
# Create a Polygon with shapely package
157-
poly = Polygon(nodes_coord)
158-
159-
# If polygon is convexe
160-
if poly.is_valid and poly.is_simple and poly.convex_hull.equals(poly):
161-
centroid = poly.centroid
162-
return True, centroid.x, centroid.y
163-
164-
#Else if polygon is concav, we're looking if there is a "star area"
165-
p_before = None
166-
p_first = None
167-
star_poly = poly
168-
for p in poly.exterior.coords[:-1]:
169-
if p_before is not None:
170-
# one side of the polygon
171-
seg = LineString([p, p_before])
172-
173-
# we create a big quad box
174-
box = Polygon([(-1e5, 0), (1e5, 0), (1e5, 1e5), (-1e5, 1e5)])
175-
176-
# segment angle
177-
dx = seg.coords[1][0] - seg.coords[0][0]
178-
dy = seg.coords[1][1] - seg.coords[0][1]
179-
angle = math.degrees(math.atan2(dy, dx))
180-
181-
#moving box
182-
box_rot = affinity.rotate(box, angle, origin=(0, 0))
183-
origin_pt = Point(seg.coords[0])
184-
box_final = affinity.translate(box_rot, origin_pt.x, origin_pt.y)
185-
186-
star_poly = star_poly.intersection(box_final)
187-
if star_poly.is_empty:
188-
plt.figure(figsize=(6, 6))
189-
# Polygone
190-
x, y = poly.exterior.xy
191-
plt.fill(x, y, alpha=0.3, edgecolor='blue',
192-
label='Polygon formed par by neighbours vertices')
193-
194-
# Voisins
195-
plt.scatter(nodes_coord[:, 0], nodes_coord[:, 1], color='blue', zorder=5, label='Neighbours')
196-
197-
plt.legend()
198-
plt.gca().set_aspect('equal')
199-
plt.show()
200-
return False, 0, 0
201-
elif p_before is None:
202-
p_first = p
203-
p_before = p
204-
205-
#We do the same for the last segment
206-
seg = LineString([p_first, p_before])
207-
box = Polygon([(-1e5, 0), (1e5, 0), (1e5, 1e5), (-1e5, 1e5)])
208-
dx = seg.coords[1][0] - seg.coords[0][0]
209-
dy = seg.coords[1][1] - seg.coords[0][1]
210-
angle = math.degrees(math.atan2(dy, dx))
211-
box_rot = affinity.rotate(box, angle, origin=(0, 0))
212-
origin_pt = Point(seg.coords[0])
213-
box_final = affinity.translate(box_rot, origin_pt.x, origin_pt.y)
214-
215-
star_poly = star_poly.intersection(box_final)
216-
if star_poly.is_empty:
217-
plt.figure(figsize=(6, 6))
218-
# Polygone
219-
x, y = poly.exterior.xy
220-
plt.fill(x, y, alpha=0.3, edgecolor='blue',
221-
label='Polygon formed par by neighbours vertices')
222-
223-
# Voisins
224-
plt.scatter(nodes_coord[:, 0], nodes_coord[:, 1], color='blue', zorder=5, label='Neighbours')
225-
226-
plt.legend()
227-
plt.gca().set_aspect('equal')
228-
plt.show()
229-
return False, 0, 0
230-
231-
if plot:
232-
plt.figure(figsize=(6, 6))
233-
# Polygone
234-
x, y = poly.exterior.xy
235-
plt.fill(x, y, alpha=0.3, edgecolor='blue',
236-
label='Polygon formed par by neighbours vertices')
237-
238-
# Voisins
239-
plt.scatter(nodes_coord[:, 0], nodes_coord[:, 1], color='blue', zorder=5, label='Neighbours')
240-
241-
# Polygone
242-
x_s, y_s = star_poly.exterior.xy
243-
plt.fill(x_s, y_s, alpha=0.3, facecolor='lightcoral',
244-
label='Star area')
245-
246-
plt.legend()
247-
plt.gca().set_aspect('equal')
248-
plt.show()
249-
250-
centroid = star_poly.centroid
251-
return True, centroid.x ,centroid.y
252-
253-
254130
def get_adjacent_faces(self, n: Node, d_from: Dart, d_to: Dart) -> list:
255131
adj_faces = []
256132
d2 = d_from

0 commit comments

Comments
 (0)