From cc8fdf11a6e6a0e47f2f560ab2d9271464b95ccc Mon Sep 17 00:00:00 2001 From: w8r Date: Fri, 21 Jun 2024 14:30:17 +0200 Subject: [PATCH 1/2] Fixed a problem with big numbers in packEnclose --- src/pack/enclose.js | 11 ++++++----- test/pack/enclose-test.js | 13 +++++++++++-- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/pack/enclose.js b/src/pack/enclose.js index f6eb67f1..2596edfa 100644 --- a/src/pack/enclose.js +++ b/src/pack/enclose.js @@ -94,9 +94,10 @@ function encloseBasis2(a, b) { } function encloseBasis3(a, b, c) { - var x1 = a.x, y1 = a.y, r1 = a.r, - x2 = b.x, y2 = b.y, r2 = b.r, - x3 = c.x, y3 = c.y, r3 = c.r, + var cx = (a.x + b.x + c.x) / 3, cy = (a.y + b.y + c.y) / 3; + var x1 = a.x - cx, y1 = a.y - cy, r1 = a.r, + x2 = b.x - cx, y2 = b.y - cy, r2 = b.r, + x3 = c.x - cx, y3 = c.y - cy, r3 = c.r, a2 = x1 - x2, a3 = x1 - x3, b2 = y1 - y2, @@ -116,8 +117,8 @@ function encloseBasis3(a, b, c) { C = xa * xa + ya * ya - r1 * r1, r = -(Math.abs(A) > 1e-6 ? (B + Math.sqrt(B * B - 4 * A * C)) / (2 * A) : C / B); return { - x: x1 + xa + xb * r, - y: y1 + ya + yb * r, + x: cx + x1 + xa + xb * r, + y: cy + y1 + ya + yb * r, r: r }; } diff --git a/test/pack/enclose-test.js b/test/pack/enclose-test.js index b69714b1..a3601173 100644 --- a/test/pack/enclose-test.js +++ b/test/pack/enclose-test.js @@ -10,9 +10,18 @@ it("packEnclose(circles) handles a tricky case", () => { {x: 15.5, y: 73.5, r: 8.585} ]), { - r: 20.790781637717107, - x: 12.80193548387092, + r: 20.790781637717117, + x: 12.801935483870967, y: 61.59615384615385 } ); }); + +it('packEnclose(circles) handles big numbers', () => { + const circles = [ + { "x": 531214.7271532917, "y": 360738.8204573899, "r": 10 }, + { "x": 531242.0429781883, "y": 360764.87727581244, "r": 10 }, + { "x": 531239.7927335791, "y": 360716.54336245544, "r": 10 } + ]; + assert.doesNotThrow(() => packEnclose(circles)); +}); From dde59e2581e21a8589a62102927f36be7c5d64b9 Mon Sep 17 00:00:00 2001 From: Alexander Milevski Date: Fri, 21 Jun 2024 16:01:41 +0200 Subject: [PATCH 2/2] Wording in the test description --- test/pack/enclose-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/pack/enclose-test.js b/test/pack/enclose-test.js index a3601173..5fe0885e 100644 --- a/test/pack/enclose-test.js +++ b/test/pack/enclose-test.js @@ -17,7 +17,7 @@ it("packEnclose(circles) handles a tricky case", () => { ); }); -it('packEnclose(circles) handles big numbers', () => { +it('packEnclose(circles) handles large values', () => { const circles = [ { "x": 531214.7271532917, "y": 360738.8204573899, "r": 10 }, { "x": 531242.0429781883, "y": 360764.87727581244, "r": 10 },