示例#1
0
void EffectDistortion::CubicTable()
{
   double amount = mParams.mParam1 * std::sqrt(3.0) / 100.0;
   double gain = 1.0;
   if (amount != 0.0)
      gain = 1.0 / Cubic(std::min(amount, 1.0));

   double stepsize = amount / STEPS;
   double x = -amount;
   
   if (amount == 0) {
      for (int i = 0; i < TABLESIZE; i++) {
         mTable[i] = (i / (double)STEPS) - 1.0;
      }
   }
   else {
      for (int i = 0; i < TABLESIZE; i++) {
         mTable[i] = gain * Cubic(x);
         for (int j = 0; j < mParams.mRepeats; j++) {
            mTable[i] = gain * Cubic(mTable[i] * amount);
         }
         x += stepsize;
      }
   }
}
示例#2
0
	Int32 Quartic( Real x4, Real x3, Real x2, Real x, Real k, Real roots[4] )
	{
		if( IsZero( x4 ) )
			return Cubic( x3, x2, x, k, roots );
		
		Int32 n;
		Real a, b, c, d, s, a2, p, q, r, z, u, v;

		// Normalize
		a = x3 / x4;
		b = x2 / x4;
		c = x  / x4;
		d = k  / x4;

		// Reduction to a depressed quartic
		a2 = a * a;
		p = -3.0f / 8.0f * a2 + b;
		q = 1.0f / 8.0f * a2 * a - 1.0f / 2.0f * a * b + c;
		r = -3.0f / 256.0f * a2 * a2 + 1.0f / 16.0f * a2 * b - 1.0f / 4.0f * a * c + d;

		if( IsZero( r ) )
		{
			n = Cubic( 1.0f, 0.0f, p, q, roots );
			roots[n++] = 0.0f;
		}
		else
		{
			Cubic( 1.0f, -1.0f / 2.0f * p, -r, 1.0f / 2.0f * r * p - 1.0f / 8.0f * q * q, roots );

			z = roots[0];
			u = z * z - r;
			v = 2.0f * z - p;

			if( u < -CLOSE ) return 0;
			else u = u > CLOSE ? SQRT( u ) : 0.0f;

			if( v < -CLOSE ) return 0;
			else v = v > CLOSE ? SQRT( v ) : 0.0f;

			n  = Quadratic( 1.0f, q < 0.0f ? -v : v, z - u, roots );
			n += Quadratic( 1.0f, q < 0.0f ? v : -v, z + u, roots + n );
		}

		s = 1.0f / 4.0f * a;
		for( Int32 i = 0; i < n; i++ )
			roots[i] -= s;

		return n;
	}
bool FTVectoriser::Process()
{
  short first = 0;
  short last;
  const short cont = ftOutline.n_contours;
  
  for( short c = 0; c < cont; ++c)
  {
    contour = new FTContour;
    contourFlag = ftOutline.flags;
    last = ftOutline.contours[c];

    for( int p = first; p <= last; ++p)
    {
      switch( ftOutline.tags[p])
      {
        case FT_Curve_Tag_Conic:
          p += Conic( p, first, last);
          break;
        case FT_Curve_Tag_Cubic:
          p += Cubic( p, first, last);
          break;
        case FT_Curve_Tag_On:
        default:
           contour->AddPoint( ftOutline.points[p].x, ftOutline.points[p].y);
      }
    }
    
    contourList.push_back( contour);
    first = (short)(last + 1);
  }
  
  return true;
}
示例#4
0
UtilityMath::S_Vector2<T> UtilityMath::S_Vector2<T>::s_Bezier(const UtilityMath::S_Vector2<T>& rStartPoint,
                                                              const UtilityMath::S_Vector2<T>& rEndPoint,
                                                              const UtilityMath::S_Vector2<T>& rControlPoint1,
                                                              const UtilityMath::S_Vector2<T>& rControlPoint2,
                                                              T coefficient)
{
    // 各点の係数を求める
    T oneMinusCoefficient = static_cast<T>(1) - coefficient;
    
    T p0 = Cubic(oneMinusCoefficient);
    T p1 = Cubic(coefficient);
    T c0 = static_cast<T>(3) * coefficient * Square(oneMinusCoefficient);
    T c1 = static_cast<T>(3) * Square(coefficient) * oneMinusCoefficient;

    // ベジェ補間する
    S_Vector2 bezierPoint;

    bezierPoint.x_ = rStartPoint.x_ * p0 + rEndPoint.x_ * p1 + rControlPoint1.x_ * c0 + rControlPoint2.x_ * c1;
    bezierPoint.y_ = rStartPoint.y_ * p0 + rEndPoint.y_ * p1 + rControlPoint1.y_ * c0 + rControlPoint2.y_ * c1;

    return bezierPoint;
}
示例#5
0
文件: rvgImage.cpp 项目: ileben/RAVG
void ObjectFlatten::cubicTo (const Vec2 &p1, const Vec2 &p2, const Vec2 &p3, int space)
{
  if (!penDown) return;

  Vec2 t0 = transform( getPen() );
  Vec2 t1 = transform( p1 );
  Vec2 t2 = transform( p2 );
  Vec2 t3 = transform( p3 );

  getObject()->cubics.push_back( Cubic( t0.x,t0.y, t1.x,t1.y, t2.x,t2.y, t3.x,t3.y ));
  getObject()->contourPoints.push_back( t2 );
  getObject()->contours.back().length++;
}
示例#6
0
文件: bhtree.hpp 项目: LiamHe/N-Body
		Cubic get_sub(Octant o){
			Pos3 p;
			switch(o){
			case top_front_right: 	p = Pos3( len/2,  len/2,  len/2); break;
			case bottom_front_right:p = Pos3( len/2,  len/2, -len/2); break;
			case top_back_right:	p = Pos3( len/2, -len/2,  len/2); break;
			case bottom_back_right:	p = Pos3( len/2, -len/2, -len/2); break;
			case top_front_left:	p = Pos3(-len/2,  len/2,  len/2); break;
			case bottom_front_left:	p = Pos3(-len/2,  len/2, -len/2); break;
			case top_back_left:		p = Pos3(-len/2, -len/2,  len/2); break;
			case bottom_back_left:	p = Pos3(-len/2, -len/2, -len/2); break;
			}
			return Cubic(origin + p, len / 2);
		}
示例#7
0
void Painter::DoArc0(double theta, double th_sweep, const Xform2D& m)
{
	int nsegs = int(ceil(fabs(th_sweep / (M_PI * 0.5 + 0.001))));
	for(int i = 0; i < nsegs; i++) {
		double th0 = theta + i * th_sweep / nsegs;
		double th1 = theta + (i + 1) * th_sweep / nsegs;
		double thHalf = 0.5 * (th1 - th0);
		double t = (8.0 / 3.0) * sin(thHalf * 0.5) * sin(thHalf * 0.5) / sin(thHalf);
		double x3 = cos(th1);
		double y3 = sin(th1);
		Cubic(m.Transform(cos(th0) - t * sin(th0), sin(th0) + t * cos(th0)),
		      m.Transform(x3 + t * sin(th1), y3 - t * cos(th1)),
		      m.Transform(x3, y3));
	}
}
示例#8
0
 LogCubicInterpolation(const I1& xBegin, const I1& xEnd,
                       const I2& yBegin,
                       CubicInterpolation::DerivativeApprox da,
                       bool monotonic,
                       CubicInterpolation::BoundaryCondition leftC,
                       Real leftConditionValue,
                       CubicInterpolation::BoundaryCondition rightC,
                       Real rightConditionValue) {
     impl_ = boost::shared_ptr<Interpolation::Impl>(new
         detail::LogInterpolationImpl<I1, I2, Cubic>(
             xBegin, xEnd, yBegin,
             Cubic(da, monotonic,
                   leftC, leftConditionValue,
                   rightC, rightConditionValue)));
     impl_->update();
 }
示例#9
0
vector<Cubic> Spline::CalcNaturalCubic3D(vector<vec3> points, float(*GetVal)(vec3 p)){
	vector<Cubic> cubics;
	int num = points.size() - 1;

	float* gamma = new float[num + 1];
	float* delta = new float[num + 1];
	float* D = new float[num + 1];

	gamma[0] = 1.0f / 2.0f;
	for (int i = 1; i < num; ++i){
		gamma[i] = 1.0f / (4.0f - gamma[i - 1]);
	}
	gamma[num] = 1.0f / (2.0f - gamma[num - 1]);

	float p0 = GetVal(points[0]);
	float p1 = GetVal(points[1]);

	delta[0] = 3.0f * (p1 - p0) * gamma[0];
	for (int i = 1; i < num; ++i){
		float p0 = GetVal(points[i - 1]);
		float p1 = GetVal(points[i + 1]);
		delta[i] = (3.0f * (p1 - p0) - delta[i - 1]) * gamma[i];
	}
	p0 = GetVal(points[num - 1]);
	p1 = GetVal(points[num]);
	delta[num] = (3.0f * (p1 - p0) - delta[num - 1]) * gamma[num];

	D[num] = delta[num];
	for (int i = num - 1; i >= 0; --i){
		D[i] = delta[i] - gamma[i] * D[i + 1];
	}
	cubics.clear();
	for (int i = 0; i < num; ++i){
		p0 = GetVal(points[i]);
		p1 = GetVal(points[i + 1]);
		Cubic c = Cubic(p0, D[i],
			(3 * (p1 - p0) - 2 * D[i] - D[i + 1]),
			(2 * (p0 - p1) + D[i] + D[i + 1])
			);
		cubics.push_back(c);
	}
	delete[] gamma;
	delete[] delta;
	delete[] D;
	return cubics;
}
示例#10
0
 MixedLinearCubicInterpolation(const I1& xBegin, const I1& xEnd,
                               const I2& yBegin, Size n,
                               MixedInterpolation::Behavior behavior,
                               CubicInterpolation::DerivativeApprox da,
                               bool monotonic,
                               CubicInterpolation::BoundaryCondition leftC,
                               Real leftConditionValue,
                               CubicInterpolation::BoundaryCondition rightC,
                               Real rightConditionValue) {
     impl_ = ext::shared_ptr<Interpolation::Impl>(new
         detail::MixedInterpolationImpl<I1, I2, Linear, Cubic>(
             xBegin, xEnd, yBegin, n, behavior,
             Linear(),
             Cubic(da, monotonic,
                   leftC, leftConditionValue,
                   rightC, rightConditionValue)));
     impl_->update();
 }
示例#11
0
bool PolynomialRootsR<Real>::Cubic (const PRational& c0,
                                    const PRational& c1, const PRational& c2, const PRational& c3)
{
	if (c3 == msZero)
	{
		return Quadratic(c0, c1, c2);
	}

	// The equation is c3*x^3 c2*x^2 + c1*x + c0 = 0, where c3 is not zero.
	// Create a monic polynomial, x^3 + a2*x^2 + a1*x + a0 = 0.
	PRational ratInvC3 = msOne/c3;
	PRational ratA2 = c2*ratInvC3;
	PRational ratA1 = c1*ratInvC3;
	PRational ratA0 = c0*ratInvC3;

	// Solve the equation.
	return Cubic(ratA0, ratA1, ratA2);
}
示例#12
0
bool PolynomialRootsR<Real>::Cubic (Real c0, Real c1, Real c2, Real c3)
{
	if (c3 == (Real)0)
	{
		return Quadratic(c0, c1, c2);
	}

	// The equation is c3*x^3 c2*x^2 + c1*x + c0 = 0, where c3 is not zero.
	PRational ratC0(c0), ratC1(c1), ratC2(c2), ratC3(c3);

	// Create a monic polynomial, x^3 + a2*x^2 + a1*x + a0 = 0.
	PRational ratInvC3 = msOne/ratC3;
	PRational ratA2 = ratC2*ratInvC3;
	PRational ratA1 = ratC1*ratInvC3;
	PRational ratA0 = ratC0*ratInvC3;

	// Solve the equation.
	return Cubic(ratA0, ratA1, ratA2);
}
示例#13
0
 boost::shared_ptr<SmileSection>
 StrippedOptionletAdapter::smileSectionImpl(Time t) const {
     std::vector< Rate > optionletStrikes =
         optionletStripper_->optionletStrikes(
             0); // strikes are the same for all times ?!
     std::vector< Real > stddevs;
     for (Size i = 0; i < optionletStrikes.size(); i++) {
         stddevs.push_back(volatilityImpl(t, optionletStrikes[i]) *
                           std::sqrt(t));
     }
     // Extrapolation may be a problem with splines, but since minStrike()
     // and maxStrike() are set, we assume that no one will use stddevs for
     // strikes outside these strikes
     CubicInterpolation::BoundaryCondition bc =
         optionletStrikes.size() >= 4 ? CubicInterpolation::Lagrange
                                      : CubicInterpolation::SecondDerivative;
     return boost::make_shared< InterpolatedSmileSection< Cubic > >(
         t, optionletStrikes, stddevs, Null< Real >(),
         Cubic(CubicInterpolation::Spline, false, bc, 0.0, bc, 0.0),
         Actual365Fixed(), volatilityType(), displacement());
 }
示例#14
0
bool PolynomialRootsR<Real>::Quartic (const PRational& c0,
                                      const PRational& c1, const PRational& c2, const PRational& c3,
                                      const PRational& c4)
{
	if (c4 == msZero)
	{
		return Cubic(c0, c1, c2, c3);
	}

	// The equation is c4*x^4 + c3*x^3 c2*x^2 + c1*x + c0 = 0, where c3 is
	// not zero.  Create a monic polynomial,
	// x^4 + a3*x^3 + a2*x^2 + a1*x + a0 = 0.
	PRational ratInvC4 = msOne/c4;
	PRational ratA3 = c3*ratInvC4;
	PRational ratA2 = c2*ratInvC4;
	PRational ratA1 = c1*ratInvC4;
	PRational ratA0 = c0*ratInvC4;

	// Solve the equation.
	return Quartic(ratA0, ratA1, ratA2, ratA3);
}
示例#15
0
float TimelineKey::GetTByCurveType(float currentTime, float nextTimelineTime) const
{
    if (curveType_ == INSTANT)
        return 0.0f;

    float t = (currentTime - time_) / (nextTimelineTime - time_);
    switch (curveType_)
    {
    case LINEAR:
        return t;

    case QUADRATIC:
        return Quadratic(0.0f, c1_, 1.0f, t);

    case CUBIC:
        return Cubic(0.0f, c1_, c2_, 1.0f, t);

    default:
        return 0.0f;
    }
}
示例#16
0
bool PolynomialRootsR<Real>::Quartic (Real c0, Real c1, Real c2, Real c3,
                                      Real c4)
{
	if (c4 == (Real)0)
	{
		return Cubic(c0, c1, c2, c3);
	}

	// The equation is c4*x^4 + c3*x^3 c2*x^2 + c1*x + c0 = 0, where c3 is
	// not zero.
	PRational ratC0(c0), ratC1(c1), ratC2(c2), ratC3(c3), ratC4(c4);

	// Create a monic polynomial, x^4 + a3*x^3 + a2*x^2 + a1*x + a0 = 0.
	PRational ratInvC4 = msOne/ratC4;
	PRational ratA3 = ratC3*ratInvC4;
	PRational ratA2 = ratC2*ratInvC4;
	PRational ratA1 = ratC1*ratInvC4;
	PRational ratA0 = ratC0*ratInvC4;

	// Solve the equation.
	return Quartic(ratA0, ratA1, ratA2, ratA3);
}
示例#17
0
Painter& Painter::Cubic(double x2, double y2, double x, double y)
{
	return Cubic(x2, y2, x, y, false);
}
示例#18
0
Painter& Painter::Path(CParser& p)
{
	Pointf current(0, 0);
	while(!p.IsEof()) {
		int c = p.GetChar();
		p.Spaces();
		bool rel = IsLower(c);
		Pointf t, t1, t2;
		switch(ToUpper(c)) {
		case 'M':
			current = ReadPoint(p, current, rel);
			Move(current);
		case 'L':
			while(p.IsDouble2()) {
				current = ReadPoint(p, current, rel);
				Line(current);
			}
			break;
		case 'Z':
			Close();
			break;
		case 'H':
			while(p.IsDouble2()) {
				current.x = p.ReadDouble() + rel * current.x;
				Line(current);
			}
			break;
		case 'V':
			while(p.IsDouble2()) {
				current.y = p.ReadDouble() + rel * current.y;
				Line(current);
			}
			break;
		case 'C':
			while(p.IsDouble2()) {
				t1 = ReadPoint(p, current, rel);
				t2 = ReadPoint(p, current, rel);
				current = ReadPoint(p, current, rel);
				Cubic(t1, t2, current);
			}
			break;
		case 'S':
			while(p.IsDouble2()) {
				t2 = ReadPoint(p, current, rel);
				current = ReadPoint(p, current, rel);
				Cubic(t2, current);
			}
			break;
		case 'Q':
			while(p.IsDouble2()) {
				t1 = ReadPoint(p, current, rel);
				current = ReadPoint(p, current, rel);
				Quadratic(t1, current);
			}
			break;
		case 'T':
			while(p.IsDouble2()) {
				current = ReadPoint(p, current, rel);
				Quadratic(current);
			}
			break;
		case 'A':
			while(p.IsDouble2()) {
				t1 = ReadPoint(p, Pointf(0, 0), false);
				double xangle = ReadDouble(p);
				bool large = ReadBool(p);
				bool sweep = ReadBool(p);
				current = ReadPoint(p, current, rel);
				SvgArc(t1, xangle * M_PI / 180.0, large, sweep, current);
			}
			break;
		default:
			return *this;
		}
	}
	return *this;
}
示例#19
0
Painter& Painter::RelCubic(double x2, double y2, double x, double y)
{
	return Cubic(x2, y2, x, y, true);
}
示例#20
0
Painter& Painter::RelCubic(double x2, double y2, double x, double y)
{
	Cubic(x2, y2, x, y, true);
	return *this;
}
示例#21
0
Painter& Painter::Cubic(double x2, double y2, double x, double y)
{
	Cubic(x2, y2, x, y, false);
	return *this;
}
示例#22
0
void BoundsPainter::CubicOp(const Pointf& p1, const Pointf& p2, const Pointf& p, bool)
{
	sw.Cubic(p1, p2, p);
	Cubic(p1, p2, p);
}