Skip to content

Conversation

@DLebedyuk
Copy link

Implemented line_segment class with its basic method, made tests for methods
Solution for issue #9

def length
# Your code goes here...
# REQUIREMENT: use lazy evaluation
begins_at.distance ends_at
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The distance method uses the square root function under the hood. Also the length won`t be changed because the points are fixed. It is better to store the length as an instance variable and use lazy initialization.

def length
  @length ||= begins_at.distance ends_at
end

def to_straight_line
a = ends_at.y - begins_at.y
b = begins_at.x - ends_at.x
c = -begins_at.x * ends_at.y + begins_at.y * ends_at.x
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, add tests for to_straight_line method.

StraightLine.new(a, b, c)
end

def check_is_a_point(x)
Copy link
Contributor

@callmekeypuncher callmekeypuncher Nov 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This utility method should be private.

@Wolwer1nE
Copy link
Contributor

Please, add tests for to_straight_line and check if docs need to be updated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants