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 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