Skip to content

Commit d014edd

Browse files
committed
chore: update is_regular polygon check method
1 parent 733f8e9 commit d014edd

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

otary/geometry/discrete/shape/polygon.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,9 @@ def is_regular(self, margin_dist_error_pct: float = 1e-2) -> bool:
337337
diag2 = Segment(points=self.asarray[diag2_idxs])
338338

339339
# rectangular criteria = the diagonals have same lengths
340-
normed_length = np.sqrt(diag1.length * diag2.length)
341-
if np.abs(diag1.length - diag2.length) > normed_length * margin_dist_error_pct:
340+
normed_length = (diag1.length + diag2.length) / 2
341+
err_tol = normed_length * margin_dist_error_pct
342+
if np.abs(diag1.length - diag2.length) > err_tol:
342343
return False
343344

344345
# there should exist only one intersection point
@@ -351,8 +352,8 @@ def is_regular(self, margin_dist_error_pct: float = 1e-2) -> bool:
351352
dist_mid_cross_diag1 = np.linalg.norm(cross_point - diag1.centroid)
352353
dist_mid_cross_diag2 = np.linalg.norm(cross_point - diag2.centroid)
353354
if (
354-
np.abs(dist_mid_cross_diag1) > normed_length * margin_dist_error_pct
355-
or np.abs(dist_mid_cross_diag2) > normed_length * margin_dist_error_pct
355+
dist_mid_cross_diag1 > err_tol
356+
or dist_mid_cross_diag2 > err_tol
356357
):
357358
return False
358359

0 commit comments

Comments
 (0)