Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix scaling-dependence of termination criterion #47

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion alphashape/optimizealpha.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def optimizealpha(points: Union[List[Tuple[float]], np.ndarray],

# Begin the bisection loop
counter = 0
while (upper - lower) > np.finfo(float).eps * 2:
while not np.isclose(lower, upper, atol=0.0, rtol=np.finfo(float).eps * 2):
# Bisect the current bounds
test_alpha = (upper + lower) * .5

Expand Down
23 changes: 23 additions & 0 deletions tests/test_optimizealpha.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@


import unittest
import numpy as np

from alphashape import optimizealpha

Expand Down Expand Up @@ -39,3 +40,25 @@ def test_reach_max_iterations(self):
(0.5, 0.25), (0.5, 0.75), (0.25, 0.5), (0.75, 0.5)],
max_iterations=2, lower=0.0, upper=1000.0)
self.assertEqual(alpha, 0.0)

def test_large_alpha(self):
"""
Given a polygon for which a large alpha is optimal, the optimizealpha
function should find a large alpha
"""
scale = 1e30
alpha = optimizealpha(np.array(
[(0., 0.), (0., 1.), (1., 1.), (1., 0.),
(0.5, 0.25), (0.5, 0.75), (0.25, 0.5), (0.75, 0.5)]) / scale)
assert alpha > 3. * scale and alpha < 3.5 * scale

def test_tiny_alpha(self):
"""
Given a polygon for which a tiny alpha is optimal, the optimizealpha
function should find a tiny alpha
"""
scale = 1e-30
alpha = optimizealpha(np.array(
[(0., 0.), (0., 1.), (1., 1.), (1., 0.),
(0.5, 0.25), (0.5, 0.75), (0.25, 0.5), (0.75, 0.5)]) / scale)
assert alpha > 3. * scale and alpha < 3.5 * scale