MCPcopy Create free account
hub / github.com/google-deepmind/alphageometry / Point

Class Point

numericals.py:46–144  ·  view source on GitHub ↗

Numerical point.

Source from the content-addressed store, hash-verified

44
45
46class Point:
47 """Numerical point."""
48
49 def __init__(self, x, y):
50 self.x = x
51 self.y = y
52
53 def __lt__(self, other: Point) -> bool:
54 return (self.x, self.y) < (other.x, other.y)
55
56 def __gt__(self, other: Point) -> bool:
57 return (self.x, self.y) > (other.x, other.y)
58
59 def __add__(self, p: Point) -> Point:
60 return Point(self.x + p.x, self.y + p.y)
61
62 def __sub__(self, p: Point) -> Point:
63 return Point(self.x - p.x, self.y - p.y)
64
65 def __mul__(self, f: float) -> Point:
66 return Point(self.x * f, self.y * f)
67
68 def __rmul__(self, f: float) -> Point:
69 return self * f
70
71 def __truediv__(self, f: float) -> Point:
72 return Point(self.x / f, self.y / f)
73
74 def __floordiv__(self, f: float) -> Point:
75 div = self / f # true div
76 return Point(int(div.x), int(div.y))
77
78 def __str__(self) -> str:
79 return 'P({},{})'.format(self.x, self.y)
80
81 def close(self, point: Point, tol: float = 1e-12) -> bool:
82 return abs(self.x - point.x) < tol and abs(self.y - point.y) < tol
83
84 def midpoint(self, p: Point) -> Point:
85 return Point(0.5 * (self.x + p.x), 0.5 * (self.y + p.y))
86
87 def distance(self, p: Union[Point, Line, Circle]) -> float:
88 if isinstance(p, Line):
89 return p.distance(self)
90 if isinstance(p, Circle):
91 return abs(p.radius - self.distance(p.center))
92 dx = self.x - p.x
93 dy = self.y - p.y
94 return np.sqrt(dx * dx + dy * dy)
95
96 def distance2(self, p: Point) -> float:
97 if isinstance(p, Line):
98 return p.distance(self)
99 dx = self.x - p.x
100 dy = self.y - p.y
101 return dx * dx + dy * dy
102
103 def rotatea(self, ang: float) -> Point:

Callers 15

__add__Method · 0.70
__sub__Method · 0.70
__mul__Method · 0.70
__truediv__Method · 0.70
__floordiv__Method · 0.70
midpointMethod · 0.70
rotateMethod · 0.70
flipMethod · 0.70
perpendicular_lineMethod · 0.70
point_atMethod · 0.70
sample_withinMethod · 0.70
sample_withinMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected