-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
line segment #19
base: master
Are you sure you want to change the base?
line segment #19
Conversation
def length | ||
# Your code goes here... | ||
# REQUIREMENT: use lazy evaluation | ||
begins_at.distance ends_at |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
Please, add tests for |
Implemented line_segment class with its basic method, made tests for methods
Solution for issue #9