| 69 | |
| 70 | |
| 71 | NATRON_NAMESPACE_ENTER |
| 72 | |
| 73 | |
| 74 | static Point |
| 75 | getPointAt(const BezierCPs& cps, |
| 76 | double time, |
| 77 | double t) |
| 78 | { |
| 79 | int ncps = (int)cps.size(); |
| 80 | |
| 81 | assert(ncps); |
| 82 | if (!ncps) { |
| 83 | throw std::logic_error("getPointAt()"); |
| 84 | } |
| 85 | if (t < 0) { |
| 86 | t += ncps; |
| 87 | } |
| 88 | int t_i = (int)std::floor(t) % ncps; |
| 89 | int t_i_plus_1 = t_i % ncps; |
| 90 | assert(t_i >= 0 && t_i < ncps && t_i_plus_1 >= 0 && t_i_plus_1 < ncps); |
| 91 | if (t == t_i) { |
| 92 | BezierCPs::const_iterator it = cps.begin(); |
| 93 | std::advance(it, t_i); |
| 94 | Point ret; |
| 95 | (*it)->getPositionAtTime(false, time, ViewIdx(0), &ret.x, &ret.y); |
| 96 | |
| 97 | return ret; |
| 98 | } else if (t == t_i_plus_1) { |
| 99 | BezierCPs::const_iterator it = cps.begin(); |
| 100 | std::advance(it, t_i_plus_1); |
| 101 | Point ret; |
| 102 | (*it)->getPositionAtTime(false, time, ViewIdx(0), &ret.x, &ret.y); |
| 103 | |
| 104 | return ret; |
| 105 | } |
| 106 | |
| 107 | BezierCPs::const_iterator it = cps.begin(); |
| 108 | std::advance(it, t_i); |
| 109 | BezierCPs::const_iterator next = it; |
| 110 | ++next; |
| 111 | if ( next == cps.end() ) { |
| 112 | next = cps.begin(); |
| 113 | } |
| 114 | Point p0, p1, p2, p3; |
| 115 | (*it)->getPositionAtTime(false, time, ViewIdx(0), &p0.x, &p0.y); |
| 116 | (*it)->getRightBezierPointAtTime(false, time, ViewIdx(0), &p1.x, &p1.y); |
| 117 | (*next)->getLeftBezierPointAtTime(false, time, ViewIdx(0), &p2.x, &p2.y); |
| 118 | (*next)->getPositionAtTime(false, time, ViewIdx(0), &p3.x, &p3.y); |
| 119 | Point ret; |
| 120 | Bezier::bezierPoint(p0, p1, p2, p3, t - t_i, &ret); |
| 121 | |
| 122 | return ret; |
| 123 | } |
| 124 | |
| 125 | static Point |
| 126 | getLeftPointAt(const BezierCPs& cps, |
no test coverage detected