Skip to content

Commit

Permalink
more operations
Browse files Browse the repository at this point in the history
  • Loading branch information
mamantoha committed Apr 30, 2024
1 parent 2531804 commit b77f872
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions spec/haversine/distance_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ describe Haversine::Distance do

it { (dist1 + dist2).distance.should eq(3) }
it { (dist1 - dist2).distance.should eq(1) }
it { [dist1, dist2].sum.distance.should eq(3) }
end
end
4 changes: 4 additions & 0 deletions src/haversine/distance.cr
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ module Haversine
distance <=> other.distance
end

def self.zero : Haversine::Distance
new(0)
end

# Adds the value of `self` to *other*.
def +(other : Haversine::Distance) : Haversine::Distance
Haversine::Distance.new(distance + other.distance)
Expand Down

0 comments on commit b77f872

Please sign in to comment.