From e73fc49fe5a445030621e16949ca84cf51b264c4 Mon Sep 17 00:00:00 2001 From: Brad Schrag Date: Fri, 5 Sep 2025 17:02:30 -0600 Subject: [PATCH 1/2] early return when max_hexagons is negative --- lib/h3/traversal.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/h3/traversal.rb b/lib/h3/traversal.rb index d0e6794..dc14578 100644 --- a/lib/h3/traversal.rb +++ b/lib/h3/traversal.rb @@ -299,9 +299,12 @@ def k_ring_distances(origin, k) # @return [Array] H3 indexes def line(origin, destination) max_hexagons = line_size(origin, destination) + raise(ArgumentError, "Could not compute line") if max_hexagons.negative? + hexagons = H3Indexes.of_size(max_hexagons) res = Bindings::Private.h3_line(origin, destination, hexagons) raise(ArgumentError, "Could not compute line") if res.negative? + hexagons.read end From 1fabde053c2ab299ee09e780471ca856258c974f Mon Sep 17 00:00:00 2001 From: Brad Schrag Date: Fri, 5 Sep 2025 17:17:38 -0600 Subject: [PATCH 2/2] add spec --- spec/traversal_spec.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/spec/traversal_spec.rb b/spec/traversal_spec.rb index 7deece1..c861f8c 100644 --- a/spec/traversal_spec.rb +++ b/spec/traversal_spec.rb @@ -64,7 +64,7 @@ it "raises an error" do expect { max_kring_size }.to raise_error(RangeError) end - end + end end describe ".k_ring_distances" do @@ -364,5 +364,14 @@ subject(:line) { H3.line(origin, destination) } it { is_expected.to eq(result) } + + context "when a line cannot be drawn" do + let(:origin) { "872889b8affffff".to_i(16) } + let(:destination) { "872aa6c80ffffff".to_i(16) } + + it "should raise an ArgumentError" do + expect { subject }.to raise_error(ArgumentError) + end + end end end