MCPcopy Create free account
hub / github.com/NatronGitHub/Natron / findPointInside

Function findPointInside

Engine/CoonsRegularization.cpp:896–937  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

regularizeMethod · 0.85

Calls 7

dirVectFunction · 0.85
findIntersectionFunction · 0.85
emptyMethod · 0.80
getPositionAtTimeMethod · 0.80
ViewIdxClass · 0.70
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected