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