MCPcopy Index your code
hub / github.com/google-deepmind/alphageometry / why_eqangle

Function why_eqangle

problem.py:518–584  ·  view source on GitHub ↗

Why two angles are equal, returns a Dependency objects.

(
    d1: gm.Direction,
    d2: gm.Direction,
    d3: gm.Direction,
    d4: gm.Direction,
    level: int,
    verbose: bool = False,
)

Source from the content-addressed store, hash-verified

516
517
518def why_eqangle(
519 d1: gm.Direction,
520 d2: gm.Direction,
521 d3: gm.Direction,
522 d4: gm.Direction,
523 level: int,
524 verbose: bool = False,
525) -> list[Dependency]:
526 """Why two angles are equal, returns a Dependency objects."""
527 all12 = list(gm.all_angles(d1, d2, level))
528 all34 = list(gm.all_angles(d3, d4, level))
529
530 min_why = None
531 for ang12, d1s, d2s in all12:
532 for ang34, d3s, d4s in all34:
533 why0 = gm.why_equal(ang12, ang34, level)
534 if why0 is None:
535 continue
536 d1_, d2_ = ang12._d
537 d3_, d4_ = ang34._d
538 why1 = gm.bfs_backtrack(d1, [d1_], d1s)
539 why2 = gm.bfs_backtrack(d2, [d2_], d2s)
540 why3 = gm.bfs_backtrack(d3, [d3_], d3s)
541 why4 = gm.bfs_backtrack(d4, [d4_], d4s)
542 why = why0 + why1 + why2 + why3 + why4
543 if min_why is None or len(why) < len(min_why[0]):
544 min_why = why, ang12, ang34, why0, why1, why2, why3, why4
545
546 if min_why is None:
547 return None
548
549 _, ang12, ang34, why0, why1, why2, why3, why4 = min_why
550 why0 = gm.why_equal(ang12, ang34, level)
551 d1_, d2_ = ang12._d
552 d3_, d4_ = ang34._d
553
554 if d1 == d1_ and d2 == d2_ and d3 == d3_ and d4 == d4_:
555 return (d1_, d2_, d3_, d4_), why0
556
557 (a_, b_), (c_, d_) = d1_._obj.points, d2_._obj.points
558 (e_, f_), (g_, h_) = d3_._obj.points, d4_._obj.points
559 deps = []
560 if why0:
561 dep = Dependency('eqangle', [a_, b_, c_, d_, e_, f_, g_, h_], '', None)
562 dep.why = why0
563 deps.append(dep)
564
565 (a, b), (c, d) = d1._obj.points, d2._obj.points
566 (e, f), (g, h) = d3._obj.points, d4._obj.points
567 for why, d_xy, (x, y), d_xy_, (x_, y_) in zip(
568 [why1, why2, why3, why4],
569 [d1, d2, d3, d4],
570 [(a, b), (c, d), (e, f), (g, h)],
571 [d1_, d2_, d3_, d4_],
572 [(a_, b_), (c_, d_), (e_, f_), (g_, h_)],
573 ):
574 xy, xy_ = d_xy._obj, d_xy_._obj
575 if why:

Callers 1

why_meMethod · 0.85

Calls 2

DependencyClass · 0.85
why_equalMethod · 0.45

Tested by

no test coverage detected