Blame c++/vector/curve.cpp

145120
145120
#include "curve.h"
145120
145120
145120
int Hermite::bends(Real *l, const Real &p0, const Real &p1, const Real &t0, const Real &t1) {
145120
	Real roots[2];
145120
	int count = solve_equation(
145120
		roots,
145120
		   p0 +          t0       ,
145120
		-6*p0 + 6*p1 - 4*t0 + 2*t1,
145120
		 6*p0 - 6*p1 + 3*t0 + 3*t1 );
145120
	int valid_count = 0;	
145120
	for(Real *i = roots, *end = i + count; i != end; ++i)
145120
		if (less(0, *i) && less(*i, 1)) {
145120
			if (l) l[valid_count] = *i;
145120
			++valid_count;
145120
		}
145120
	return valid_count;
145120
}
145120
145120
Range Hermite::bounds_accurate(const Real &p0, const Real &p1, const Real &t0, const Real &t1) {
145120
	Range range(p0);
145120
	range.expand(p1);
145120
	Real roots[2];
145120
	int count = bends(roots, p0, p1, t0, t1);
145120
	for(Real *i = roots, *end = i + count; i != end; ++i)
145120
		range.expand( p(*i, p0, p1, t0, t1) );
145120
	return range;
145120
}
145120
145120
int Hermite::intersections(Real *l, const Real &p, const Real &p0, const Real &p1, const Real &t0, const Real &t1) {
145120
	Real roots[3];
145120
	int count = solve_equation(
145120
		roots,
145120
		   p0 - p               ,
145120
		                 t0     ,
145120
		-3*p0 + 3*p1 - 2*t0 - t1,
145120
		 2*p0 - 2*p1 +   t0 + t1 );
145120
	int valid_count = 0;
145120
	for(Real *i = roots, *end = i + count; i != end; ++i)
145120
		if (less(0, *i) && less(*i, 1)) {
145120
			if (l) l[valid_count] = *i;
145120
			++valid_count;
145120
		}
145120
	return valid_count;
145120
}
145120
145120
145120
int Bezier::bends(Real *l, const Real &p0, const Real &p1, const Real &pp0, const Real &pp1) {
145120
	Real roots[2];
145120
	int count = solve_equation(
145120
		roots,
145120
		 -p0 +   pp0             ,
145120
		2*p0 - 6*pp0 + 2*pp1     ,
145120
		 -p0 + 3*pp0 - 3*pp1 + p1 );
145120
	int valid_count = 0;	
145120
	for(Real *i = roots, *end = i + count; i != end; ++i)
145120
		if (less(0, *i) && less(*i, 1)) {
145120
			if (l) l[valid_count] = *i;
145120
			++valid_count;
145120
		}
145120
	return valid_count;
145120
}
145120
145120
Range Bezier::bounds_accurate(const Real &p0, const Real &p1, const Real &pp0, const Real &pp1) {
145120
	Range range(p0);
145120
	range.expand(p1);
145120
	Real roots[2];
145120
	int count = bends(roots, p0, p1, pp0, pp1);
145120
	for(Real *i = roots, *end = i + count; i != end; ++i)
145120
		range.expand( p(*i, p0, p1, pp0, pp1) );
145120
	return range;
145120
}
145120
145120
int Bezier::intersections(Real *l, const Real &p, const Real &p0, const Real &p1, const Real &pp0, const Real &pp1) {
145120
	Real roots[3];
145120
	int count = solve_equation(
145120
		roots,
145120
		   p0 - p                 ,
145120
		-3*p0 + 3*pp0             ,
145120
		 3*p0 - 6*pp0 + 3*pp1     ,
145120
		  -p0 + 3*pp0 - 3*pp1 + p1 );
145120
	int valid_count = 0;
145120
	for(Real *i = roots, *end = i + count; i != end; ++i)
145120
		if (less(0, *i) && less(*i, 1)) {
145120
			if (l) l[valid_count] = *i;
145120
			++valid_count;
145120
		}
145120
	return valid_count;
145120
}