* @function LevelRenderer.Tool.Areal.prototype.windingCubic
(x0, y0, x1, y1, x2, y2, x3, y3, x, y)
| 683 | * @function LevelRenderer.Tool.Areal.prototype.windingCubic |
| 684 | */ |
| 685 | windingCubic(x0, y0, x1, y1, x2, y2, x3, y3, x, y) { |
| 686 | var curve = this.curve; |
| 687 | var roots = this.roots; |
| 688 | var extrema = this.extrema; |
| 689 | |
| 690 | // Quick reject |
| 691 | if ( |
| 692 | (y > y0 && y > y1 && y > y2 && y > y3) |
| 693 | || (y < y0 && y < y1 && y < y2 && y < y3) |
| 694 | ) { |
| 695 | return 0; |
| 696 | } |
| 697 | var nRoots = curve.cubicRootAt(y0, y1, y2, y3, y, roots); |
| 698 | if (nRoots === 0) { |
| 699 | return 0; |
| 700 | } else { |
| 701 | var w = 0; |
| 702 | var nExtrema = -1; |
| 703 | var y0_, y1_; |
| 704 | for (var i = 0; i < nRoots; i++) { |
| 705 | var t = roots[i]; |
| 706 | var x_ = curve.cubicAt(x0, x1, x2, x3, t); |
| 707 | if (x_ < x) { // Quick reject |
| 708 | continue; |
| 709 | } |
| 710 | if (nExtrema < 0) { |
| 711 | nExtrema = curve.cubicExtrema(y0, y1, y2, y3, extrema); |
| 712 | if (extrema[1] < extrema[0] && nExtrema > 1) { |
| 713 | this.swapExtrema(); |
| 714 | } |
| 715 | y0_ = curve.cubicAt(y0, y1, y2, y3, extrema[0]); |
| 716 | if (nExtrema > 1) { |
| 717 | y1_ = curve.cubicAt(y0, y1, y2, y3, extrema[1]); |
| 718 | } |
| 719 | } |
| 720 | if (nExtrema == 2) { |
| 721 | // 分成三段单调函数 |
| 722 | if (t < extrema[0]) { |
| 723 | w += y0_ < y0 ? 1 : -1; |
| 724 | } else if (t < extrema[1]) { |
| 725 | w += y1_ < y0_ ? 1 : -1; |
| 726 | } else { |
| 727 | w += y3 < y1_ ? 1 : -1; |
| 728 | } |
| 729 | } else { |
| 730 | // 分成两段单调函数 |
| 731 | if (t < extrema[0]) { |
| 732 | w += y0_ < y0 ? 1 : -1; |
| 733 | } else { |
| 734 | w += y3 < y0_ ? 1 : -1; |
| 735 | } |
| 736 | } |
| 737 | } |
| 738 | return w; |
| 739 | } |
| 740 | } |
| 741 | |
| 742 | /** |
no test coverage detected