Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

line segment #19

wants to merge 2 commits into from

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

@koenigsley koenigsley 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