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

Method intersect

numericals.py:327–348  ·  view source on GitHub ↗
(self, obj: Union[Line, HalfLine, Circle, HoleCircle])

Source from the content-addressed store, hash-verified

325 self.head = head
326
327 def intersect(self, obj: Union[Line, HalfLine, Circle, HoleCircle]) -> Point:
328 if isinstance(obj, (HalfLine, Line)):
329 return line_line_intersection(self.line, obj)
330
331 exclude = [self.tail]
332 if isinstance(obj, HoleCircle):
333 exclude += [obj.hole]
334
335 a, b = line_circle_intersection(self.line, obj)
336 if any([a.close(x) for x in exclude]):
337 return b
338 if any([b.close(x) for x in exclude]):
339 return a
340
341 v = self.head - self.tail
342 va = a - self.tail
343 vb = b - self.tail
344 if v.dot(va) > 0:
345 return a
346 if v.dot(vb) > 0:
347 return b
348 raise InvalidLineIntersectError()
349
350 def sample_within(self, points: list[Point], n: int = 5) -> list[Point]:
351 center = sum(points, Point(0.0, 0.0)) * (1.0 / len(points))

Callers

nothing calls this directly

Calls 5

line_line_intersectionFunction · 0.85
line_circle_intersectionFunction · 0.85
closeMethod · 0.80
dotMethod · 0.45

Tested by

no test coverage detected