(c: Curve, y: number, end: 'source' | 'target')
| 641 | * rises and falls, so it is searched on the half nearest `end`. |
| 642 | */ |
| 643 | export function tAtY(c: Curve, y: number, end: 'source' | 'target'): number | null { |
| 644 | const arch = c.y0 === c.y3; |
| 645 | let lo = arch && end === 'target' ? 0.5 : 0; |
| 646 | let hi = arch && end === 'source' ? 0.5 : 1; |
| 647 | const yLo = pointAt(c, lo).y; |
| 648 | const yHi = pointAt(c, hi).y; |
| 649 | if (y < Math.min(yLo, yHi) - 1e-6 || y > Math.max(yLo, yHi) + 1e-6) return null; |
| 650 | const rising = yHi > yLo; |
| 651 | for (let i = 0; i < 40; i++) { |
| 652 | const mid = (lo + hi) / 2; |
| 653 | if (pointAt(c, mid).y < y === rising) lo = mid; |
| 654 | else hi = mid; |
| 655 | } |
| 656 | return (lo + hi) / 2; |
| 657 | } |
| 658 | |
| 659 | /* ---------------------------------------------------------------- pills -- */ |
| 660 |
no test coverage detected