Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 6 additions & 29 deletions point_pattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
Below are 5 functions (we will talk about what
a function is later) that I have removed bits of
logic from. The missing logic is noted with a comment.

The files tests.py runs units tests on these functions.
For this week, you should fill in the logic in these
functions so that the tests pass.
Expand All @@ -13,71 +12,57 @@
def manhattan_distance(a, b):
"""
Compute the Manhattan distance between two points

Parameters
----------
a : tuple
A point in the form (x,y)

b : tuple
A point in the form (x,y)

Returns
-------
distance : float
The Manhattan distance between the two points
"""
distance = None # Add the algorithm to compute manhattan distance here
distance = abs(a[0]-b[0])+abs(a[1]-b[1]) # Add the algorithm to compute manhattan distance here
return distance


def euclidean_distance(a, b):
"""
Compute the Euclidean distance between two points

Parameters
----------
a : tuple
A point in the form (x,y)

b : tuple
A point in the form (x,y)

Returns
-------

distance : float
The Euclidean distance between the two points
"""
distance = None # Add the euclidean distance algorithm here
distance = math.sqrt((a[0]-b[0])**2+(a[1]-b[1])**2) # Add the euclidean distance algorithm here
return distance


def shift_point(point, x_shift, y_shift):
"""
Shift a point by some amount in the x and y directions

Parameters
----------
point : tuple
in the form (x,y)

x_shift : int or float
distance to shift in the x direction

y_shift : int or float
distance to shift in the y direction

Returns
-------
new_x : int or float
shited x coordinate

new_y : int or float
shifted y coordinate

Note that the new_x new_y elements are returned as a tuple

Example
-------
>>> point = (0,0)
Expand All @@ -87,8 +72,8 @@ def shift_point(point, x_shift, y_shift):
x = getx(point)
y = gety(point)

x_new = None # Add the logic to shift x here
y_new = None # Add the logic to shift y here
x_new = x+x_shift # Add the logic to shift x here
y_new = y+y_shift # Add the logic to shift y here

return x_new, y_new

Expand All @@ -100,44 +85,38 @@ def check_coincident(a, b):
----------
a : tuple
A point in the form (x,y)

b : tuple
A point in the form (x,y)

Returns
-------
equal : bool
Whether the points are equal
"""
return None # Add the logic to check if coincident here
return a[0]==b[0] and a[1]==b[1] # Add the logic to check if coincident here


def check_in(point, point_list):
"""
Check whether point is in the point list

Parameters
----------
point : tuple
In the form (x,y)

point_list : list
in the form [point, point_1, point_2, ..., point_n]
"""
return None # Add the logic to check if a point is in the point list here
return point in point_list # Add the logic to check if a point is in the point list here


def getx(point):
"""
A simple method to return the x coordinate of
an tuple in the form(x,y). We will look at
sequences in a coming lesson.

Parameters
----------
point : tuple
in the form (x,y)

Returns
-------
: int or float
Expand All @@ -151,12 +130,10 @@ def gety(point):
A simple method to return the x coordinate of
an tuple in the form(x,y). We will look at
sequences in a coming lesson.

Parameters
----------
point : tuple
in the form (x,y)

Returns
-------
: int or float
Expand Down