summaryrefslogtreecommitdiff
path: root/gerber/rs274x.py
diff options
context:
space:
mode:
authorHamilton Kibbe <hamilton.kibbe@gmail.com>2017-06-12 07:59:39 -0400
committerGitHub <noreply@github.com>2017-06-12 07:59:39 -0400
commit872c2db250fe6b82ef893abe8606e08c5fdff2ca (patch)
treee562fb417b6f806e13c342f7700564fc5c82528c /gerber/rs274x.py
parentb85021d9b882136635ab4bd269fd983aa0533321 (diff)
parentdd1676ad8a9fff65231c22c01efc4bbccc21eb05 (diff)
downloadgerbonara-872c2db250fe6b82ef893abe8606e08c5fdff2ca.tar.gz
gerbonara-872c2db250fe6b82ef893abe8606e08c5fdff2ca.tar.bz2
gerbonara-872c2db250fe6b82ef893abe8606e08c5fdff2ca.zip
Merge pull request #69 from jmargeta/sweep_angle_tolerance
Add tolerance to center finding
Diffstat (limited to 'gerber/rs274x.py')
-rw-r--r--gerber/rs274x.py11
1 files changed, 7 insertions, 4 deletions
diff --git a/gerber/rs274x.py b/gerber/rs274x.py
index 5191fb7..fee60b3 100644
--- a/gerber/rs274x.py
+++ b/gerber/rs274x.py
@@ -765,14 +765,17 @@ class GerberParser(object):
# Calculate the radius error
sqdist_start = sq_distance(start, test_center)
sqdist_end = sq_distance(end, test_center)
+ sqdist_diff = abs(sqdist_start - sqdist_end)
# Take the option with the lowest radius error from the set of
# options with a valid sweep angle
- if ((abs(sqdist_start - sqdist_end) < sqdist_diff_min)
- and (sweep_angle >= 0)
- and (sweep_angle <= math.pi / 2.0)):
+ # In some rare cases, the sweep angle is numerically (10**-14) above pi/2
+ # So it is safer to compare the angles with some tolerance
+ is_lowest_radius_error = sqdist_diff < sqdist_diff_min
+ is_valid_sweep_angle = sweep_angle >= 0 and sweep_angle <= math.pi / 2.0 + 1e-6
+ if is_lowest_radius_error and is_valid_sweep_angle:
center = test_center
- sqdist_diff_min = abs(sqdist_start - sqdist_end)
+ sqdist_diff_min = sqdist_diff
return center
else:
return (start[0] + offsets[0], start[1] + offsets[1])