Why two ratios are equal, returns a Dependency objects.
(
d1: gm.Direction,
d2: gm.Direction,
d3: gm.Direction,
d4: gm.Direction,
level: int,
)
| 456 | |
| 457 | |
| 458 | def why_eqratio( |
| 459 | d1: gm.Direction, |
| 460 | d2: gm.Direction, |
| 461 | d3: gm.Direction, |
| 462 | d4: gm.Direction, |
| 463 | level: int, |
| 464 | ) -> list[Dependency]: |
| 465 | """Why two ratios are equal, returns a Dependency objects.""" |
| 466 | all12 = list(gm.all_ratios(d1, d2, level)) |
| 467 | all34 = list(gm.all_ratios(d3, d4, level)) |
| 468 | |
| 469 | min_why = None |
| 470 | for ang12, d1s, d2s in all12: |
| 471 | for ang34, d3s, d4s in all34: |
| 472 | why0 = gm.why_equal(ang12, ang34, level) |
| 473 | if why0 is None: |
| 474 | continue |
| 475 | d1_, d2_ = ang12._l |
| 476 | d3_, d4_ = ang34._l |
| 477 | why1 = gm.bfs_backtrack(d1, [d1_], d1s) |
| 478 | why2 = gm.bfs_backtrack(d2, [d2_], d2s) |
| 479 | why3 = gm.bfs_backtrack(d3, [d3_], d3s) |
| 480 | why4 = gm.bfs_backtrack(d4, [d4_], d4s) |
| 481 | why = why0 + why1 + why2 + why3 + why4 |
| 482 | if min_why is None or len(why) < len(min_why[0]): |
| 483 | min_why = why, ang12, ang34, why0, why1, why2, why3, why4 |
| 484 | |
| 485 | if min_why is None: |
| 486 | return None |
| 487 | |
| 488 | _, ang12, ang34, why0, why1, why2, why3, why4 = min_why |
| 489 | d1_, d2_ = ang12._l |
| 490 | d3_, d4_ = ang34._l |
| 491 | |
| 492 | if d1 == d1_ and d2 == d2_ and d3 == d3_ and d4 == d4_: |
| 493 | return why0 |
| 494 | |
| 495 | (a_, b_), (c_, d_) = d1_._obj.points, d2_._obj.points |
| 496 | (e_, f_), (g_, h_) = d3_._obj.points, d4_._obj.points |
| 497 | deps = [] |
| 498 | if why0: |
| 499 | dep = Dependency('eqratio', [a_, b_, c_, d_, e_, f_, g_, h_], '', level) |
| 500 | dep.why = why0 |
| 501 | deps.append(dep) |
| 502 | |
| 503 | (a, b), (c, d) = d1._obj.points, d2._obj.points |
| 504 | (e, f), (g, h) = d3._obj.points, d4._obj.points |
| 505 | for why, (x, y), (x_, y_) in zip( |
| 506 | [why1, why2, why3, why4], |
| 507 | [(a, b), (c, d), (e, f), (g, h)], |
| 508 | [(a_, b_), (c_, d_), (e_, f_), (g_, h_)], |
| 509 | ): |
| 510 | if why: |
| 511 | dep = Dependency('cong', [x, y, x_, y_], '', level) |
| 512 | dep.why = why |
| 513 | deps.append(dep) |
| 514 | |
| 515 | return deps |
no test coverage detected