Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/h3/traversal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,12 @@ def k_ring_distances(origin, k)
# @return [Array<Integer>] 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

Expand Down
11 changes: 10 additions & 1 deletion spec/traversal_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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