| 893 | } |
| 894 | |
| 895 | static |
| 896 | Point |
| 897 | findPointInside(const BezierCPs& cps, |
| 898 | double time) |
| 899 | { |
| 900 | /* |
| 901 | Given a simple polygon, find some point inside it. Here is a method based on the proof that |
| 902 | there exists an internal diagonal, in [O'Rourke, 13-14]. The idea is that the midpoint of |
| 903 | a diagonal is interior to the polygon. |
| 904 | */ |
| 905 | assert( !cps.empty() ); |
| 906 | int i = 0; |
| 907 | for (BezierCPs::const_iterator it = cps.begin(); it != cps.end(); ++it, ++i) { |
| 908 | Point dir = dirVect(cps, time, i); |
| 909 | if ( (dir.x == 0.) && (dir.y == 0.) ) { |
| 910 | continue; |
| 911 | } |
| 912 | Point p; |
| 913 | (*it)->getPositionAtTime(false, time, ViewIdx(0), &p.x, &p.y); |
| 914 | Point q; |
| 915 | q.x = p.x; |
| 916 | q.y = p.y + dir.y; |
| 917 | boost::shared_ptr<BezierCP> newPoint; |
| 918 | int beforeIndex = -1; |
| 919 | findIntersection(cps, time, p, q, &newPoint, &beforeIndex); |
| 920 | if ( newPoint && (beforeIndex != -1) ) { |
| 921 | Point np; |
| 922 | newPoint->getPositionAtTime(false, time, ViewIdx(0), &np.x, &np.y); |
| 923 | if ( (np.x != p.x) || (np.y != p.y) ) { |
| 924 | Point m; |
| 925 | m.x = 0.5 * (p.x + np.x); |
| 926 | m.y = 0.5 * (p.y + np.y); |
| 927 | |
| 928 | return m; |
| 929 | } |
| 930 | } |
| 931 | } |
| 932 | Point ret; |
| 933 | cps.front()->getPositionAtTime(false, time, ViewIdx(0), &ret.x, &ret.y); |
| 934 | |
| 935 | return ret; |
| 936 | } |
| 937 | |
| 938 | static double |
| 939 | estimate(int elen, |
no test coverage detected