Skip to content

Commit

Permalink
Address emails from hound
Browse files Browse the repository at this point in the history
  • Loading branch information
kaczowkad committed Aug 11, 2016
1 parent 90caa8c commit b33c399
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
9 changes: 5 additions & 4 deletions lib/geometry/segment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ class SegmentsOverlap < Exception; end

class Segment < Struct.new(:point1, :point2)
def self.new_by_arrays(point1_coordinates, point2_coordinates)
self.new(Point.new_by_array(point1_coordinates),
Point.new_by_array(point2_coordinates))
new(Point.new_by_array(point1_coordinates),
Point.new_by_array(point2_coordinates))
end

def leftmost_endpoint
Expand Down Expand Up @@ -55,14 +55,15 @@ def intersection_point_with(segment)

numerator = (segment.point1.y - point1.y) * (segment.point1.x - segment.point2.x) -
(segment.point1.y - segment.point2.y) * (segment.point1.x - point1.x);
denominator = (point2.y - point1.y) * (segment.point1.x - segment.point2.x) -
denominator = (point2.y - point1.y) *
(segment.point1.x - segment.point2.x) -
(segment.point1.y - segment.point2.y) * (point2.x - point1.x);

if numerator.is_a?(Integer) && denominator.is_a?(Integer)
numerator = numerator.to_f
end

t = numerator / denominator;
t = numerator / denominator

x = point1.x + t * (point2.x - point1.x)
y = point1.y + t * (point2.y - point1.y)
Expand Down
22 changes: 13 additions & 9 deletions test/segment/intersection_point_with_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'minitest/autorun'
require 'geometry'
require 'bigdecimal'
require "bigdecimal"

class IntersectionPointWithTest < Minitest::Test
include Geometry
Expand All @@ -20,14 +20,18 @@ def test_segments_intersect_at_the_endpoint
end

def test_big_decimal_segments_intersect_at_the_endpoint
segment1 = Segment.new_by_arrays([BigDecimal.new('-109.775390625'), BigDecimal.new('42.734102391081')],
[BigDecimal.new('-91.23046875'), BigDecimal.new('42.734102391081')])

segment2 = Segment.new_by_arrays([BigDecimal.new('-91.23046875'), BigDecimal.new('42.734102391081')],
[BigDecimal.new('-91.23046875'), BigDecimal.new('34.147272023649')])


assert_equal Point.new(BigDecimal.new('-91.23046875'), BigDecimal.new('42.734102391081')),
segment1 = Segment.new_by_arrays([BigDecimal.new("-109.775390625"),
BigDecimal.new("42.734102391081")],
[BigDecimal.new("-91.23046875"),
BigDecimal.new("42.734102391081")])

segment2 = Segment.new_by_arrays([BigDecimal.new("-91.23046875"),
BigDecimal.new("42.734102391081")],
[BigDecimal.new("-91.23046875"),
BigDecimal.new("34.147272023649")])

assert_equal Point.new(BigDecimal.new("-91.23046875"),
BigDecimal.new("42.734102391081")),
segment1.intersection_point_with(segment2)
end

Expand Down

0 comments on commit b33c399

Please sign in to comment.