Skip to content

Commit c4b239f

Browse files
author
Release Manager
committed
gh-39975: Fix two floating point bugs in the hyperbolic geometry code <!-- ^ Please provide a concise and informative title. --> <!-- ^ Don't put issue numbers in the title, do this in the PR description below. --> <!-- ^ For example, instead of "Fixes #12345" use "Introduce new method to calculate 1 + 2". --> <!-- v Describe your changes below in detail. --> <!-- v Why is this change required? What problem does it solve? --> <!-- v If this PR resolves an open issue, please link to it here. For example, "Fixes #12345". --> There are two places in the hyperbolic geometry code where comparing floating point values for equality causes issues. This PR should fix #32362.  See also this discussion on sage-devel: [hyperbolic_polygon bug](https://groups.google.com/g/sage-devel/c/Czt-2y6W4iw).   ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. - [x] I have created tests covering the changes. - [ ] I have updated the documentation and checked the documentation preview. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on. For example, --> <!-- - #12345: short description why this is a dependency --> <!-- - #34567: ... --> URL: #39975 Reported by: Håkan Granath Reviewer(s): Travis Scrimshaw
2 parents 7b79f0e + ca709e0 commit c4b239f

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

src/sage/geometry/hyperbolic_space/hyperbolic_coercion.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from sage.rings.infinity import infinity
2727
from sage.functions.other import real, imag
2828
from sage.misc.functional import sqrt
29+
from sage.geometry.hyperbolic_space.hyperbolic_constants import EPSILON
2930
from sage.misc.lazy_import import lazy_import
3031
lazy_import('sage.misc.call', 'attrcall')
3132

@@ -296,8 +297,19 @@ def image_coordinates(self, x):
296297
+Infinity
297298
sage: phi.image_coordinates(-I)
298299
0
300+
301+
TESTS::
302+
303+
Check that the second bug discussed in :issue:`32362` is fixed::
304+
305+
sage: PD = HyperbolicPlane().PD()
306+
sage: UHP = HyperbolicPlane().UHP()
307+
sage: r = exp((pi*I/2).n())
308+
sage: p = PD.get_point(r)
309+
sage: UHP(p)
310+
Boundary point in UHP +Infinity
299311
"""
300-
if x == I:
312+
if abs(x - I) < EPSILON:
301313
return infinity
302314
return (x + I)/(Integer(1) + I*x)
303315

src/sage/geometry/hyperbolic_space/hyperbolic_geodesic.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1212,6 +1212,17 @@ def ideal_endpoints(self):
12121212
sage: UHP.get_geodesic(1 + I, 2 + 4*I).ideal_endpoints()
12131213
[Boundary point in UHP -sqrt(65) + 9,
12141214
Boundary point in UHP sqrt(65) + 9]
1215+
1216+
TESTS::
1217+
1218+
Check that :issue:`32362` is fixed::
1219+
1220+
sage: PD = HyperbolicPlane().PD()
1221+
sage: z0 = CC(-0.0571909584179366 + 0.666666666666667*I)
1222+
sage: z1 = CC(-1)
1223+
sage: pts = PD.get_geodesic(z0, z1).ideal_endpoints()
1224+
sage: pts[1]
1225+
Boundary point in PD I
12151226
"""
12161227
start = self._start.coordinates()
12171228
end = self._end.coordinates()
@@ -1226,7 +1237,7 @@ def ideal_endpoints(self):
12261237
if CC(end).is_infinity():
12271238
return [M.get_point(x1), M.get_point(end)]
12281239
# We could also have a vertical line with two interior points
1229-
if x1 == x2:
1240+
if abs(x1 - x2) < EPSILON:
12301241
return [M.get_point(x1), M.get_point(infinity)]
12311242
# Otherwise, we have a semicircular arc in the UHP
12321243
c = ((x1+x2)*(x2-x1) + (y1+y2)*(y2-y1)) / (2*(x2-x1))

0 commit comments

Comments
 (0)