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

Class Line

numericals.py:147–311  ·  view source on GitHub ↗

Numerical line.

Source from the content-addressed store, hash-verified

145
146
147class Line:
148 """Numerical line."""
149
150 def __init__(
151 self,
152 p1: Point = None,
153 p2: Point = None,
154 coefficients: tuple[int, int, int] = None,
155 ):
156 if p1 is None and p2 is None and coefficients is None:
157 self.coefficients = None, None, None
158 return
159
160 a, b, c = coefficients or (
161 p1.y - p2.y,
162 p2.x - p1.x,
163 p1.x * p2.y - p2.x * p1.y,
164 )
165
166 # Make sure a is always positive (or always negative for that matter)
167 # With a == 0, Assuming a = +epsilon > 0
168 # Then b such that ax + by = 0 with y>0 should be negative.
169 if a < 0.0 or a == 0.0 and b > 0.0:
170 a, b, c = -a, -b, -c
171
172 self.coefficients = a, b, c
173
174 def parallel_line(self, p: Point) -> Line:
175 a, b, _ = self.coefficients
176 return Line(coefficients=(a, b, -a * p.x - b * p.y)) # pylint: disable=invalid-unary-operand-type
177
178 def perpendicular_line(self, p: Point) -> Line:
179 a, b, _ = self.coefficients
180 return Line(p, p + Point(a, b))
181
182 def greater_than(self, other: Line) -> bool:
183 a, b, _ = self.coefficients
184 x, y, _ = other.coefficients
185 # b/a > y/x
186 return b * x > a * y
187
188 def __gt__(self, other: Line) -> bool:
189 return self.greater_than(other)
190
191 def __lt__(self, other: Line) -> bool:
192 return other.greater_than(self)
193
194 def same(self, other: Line) -> bool:
195 a, b, c = self.coefficients
196 x, y, z = other.coefficients
197 return close_enough(a * y, b * x) and close_enough(b * z, c * y)
198
199 def equal(self, other: Line) -> bool:
200 a, b, _ = self.coefficients
201 x, y, _ = other.coefficients
202 # b/a == y/x
203 return b * x == a * y
204

Callers 15

parallel_lineMethod · 0.70
perpendicular_lineMethod · 0.70
__init__Method · 0.70
_perpendicular_bisectorFunction · 0.70
circle_segment_intersectFunction · 0.70
check_collFunction · 0.70
check_paraFunction · 0.70
check_perpFunction · 0.70
bring_togetherFunction · 0.70
check_eqangleFunction · 0.70
highlightFunction · 0.70
sketch_incenter2Function · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected