MCPcopy Index your code
hub / github.com/TheAlgorithms/Python / Point

Class Point

divide_and_conquer/convex_hull.py:21–85  ·  view source on GitHub ↗

Defines a 2-d point for use by all convex-hull algorithms. Parameters ---------- x: an int or a float, the x-coordinate of the 2-d point y: an int or a float, the y-coordinate of the 2-d point Examples -------- >>> Point(1, 2) (1.0, 2.0) >>> Point("1", "2")

Source from the content-addressed store, hash-verified

19
20
21class Point:
22 """
23 Defines a 2-d point for use by all convex-hull algorithms.
24
25 Parameters
26 ----------
27 x: an int or a float, the x-coordinate of the 2-d point
28 y: an int or a float, the y-coordinate of the 2-d point
29
30 Examples
31 --------
32 >>> Point(1, 2)
33 (1.0, 2.0)
34 >>> Point("1", "2")
35 (1.0, 2.0)
36 >>> Point(1, 2) > Point(0, 1)
37 True
38 >>> Point(1, 1) == Point(1, 1)
39 True
40 >>> Point(-0.5, 1) == Point(0.5, 1)
41 False
42 >>> Point("pi", "e")
43 Traceback (most recent call last):
44 ...
45 ValueError: could not convert string to float: 'pi'
46 """
47
48 def __init__(self, x, y):
49 self.x, self.y = float(x), float(y)
50
51 def __eq__(self, other):
52 return self.x == other.x and self.y == other.y
53
54 def __ne__(self, other):
55 return not self == other
56
57 def __gt__(self, other):
58 if self.x > other.x:
59 return True
60 elif self.x == other.x:
61 return self.y > other.y
62 return False
63
64 def __lt__(self, other):
65 return not self > other
66
67 def __ge__(self, other):
68 if self.x > other.x:
69 return True
70 elif self.x == other.x:
71 return self.y >= other.y
72 return False
73
74 def __le__(self, other):
75 if self.x < other.x:
76 return True
77 elif self.x == other.x:
78 return self.y <= other.y

Callers 1

_construct_pointsFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected