Changeset 40:ff9509bbfa3a in rrlib_geometry


Ignore:
Timestamp:
07.05.2012 16:48:50 (8 years ago)
Author:
Tobias Föhst <foehst@…>
Branch:
default
Parents:
39:a651fce8402e (diff), 31:2ab1b4fdb800 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Phase:
public
Message:

Merged with changes from rrlib.org

Location:
curves
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • curves/tBezierCurve.hpp

    r39 r40  
    6868template <typename TIterator> 
    6969tBezierCurve<Tdimension, TElement, Tdegree>::tBezierCurve(TIterator begin, TIterator end) 
    70   : tShape() 
    7170{ 
    7271  static_assert(Tdegree > 0, "The degree of Bezier curves must be greater than zero"); 
    73   assert(static_cast<size_t>(std::distance(begin, end)) == this->NumberOfControlPoints()); 
     72  assert(static_cast<size_t>(std::distance(begin, end)) == this->NumberOfControlPoints() && "A Bezier curve must have degree + 1 control points"); 
    7473  size_t index = 0; 
    7574  for (TIterator it = begin; it != end; ++it) 
     
    7776    this->control_points[index++] = *it; 
    7877  } 
     78} 
     79 
     80template <size_t Tdimension, typename TElement, unsigned int Tdegree> 
     81template <typename ... TPoints> 
     82tBezierCurve<Tdimension, TElement, Tdegree>::tBezierCurve(const typename tShape::tPoint &p1, const typename tShape::tPoint &p2, const TPoints &... rest) 
     83{ 
     84  static_assert(Tdegree > 0, "The degree of Bezier curves must be greater than zero"); 
     85  static_assert(sizeof...(rest) + 1 == Tdegree, "A Bezier curve must have degree + 1 control points"); 
     86  size_t index = 0; 
     87  util::ProcessVariadicValues<typename tShape::tPoint>([this, index](const typename tShape::tPoint & x) mutable { this->control_points[index++] = x; }, p1, p2, rest...); 
    7988} 
    8089 
     
    398407#ifdef _LIB_RRLIB_CANVAS_PRESENT_ 
    399408 
    400 template <typename TElement> 
    401 canvas::tCanvas2D &operator << (canvas::tCanvas2D &canvas, const tBezierCurve<2, TElement, 2> &bezier_curve) 
    402 { 
    403   canvas.StartPath(bezier_curve.ControlPoints()[0]); 
    404   canvas.AppendQuadraticBezierCurve(bezier_curve.ControlPoints()[1], bezier_curve.ControlPoints()[2]); 
    405  
    406   return canvas; 
    407 } 
    408  
    409 template <typename TElement> 
    410 canvas::tCanvas2D &operator << (canvas::tCanvas2D &canvas, const tBezierCurve<2, TElement, 3> &bezier_curve) 
    411 { 
    412   canvas.DrawCubicBezierCurve(bezier_curve.ControlPoints(), bezier_curve.ControlPoints() + 4); 
    413  
    414   return canvas; 
    415 } 
    416  
    417409template <typename TElement, unsigned int Tdegree> 
    418410canvas::tCanvas2D &operator << (canvas::tCanvas2D &canvas, const tBezierCurve<2, TElement, Tdegree> &bezier_curve) 
    419411{ 
    420   if (bezier_curve.GetTwist() < 1E-6) 
    421   { 
    422     canvas.DrawLineSegment(bezier_curve.ControlPoints()[0], bezier_curve.ControlPoints()[Tdegree]); 
    423     return canvas; 
    424   } 
    425  
    426   typename tBezierCurve<2, TElement, Tdegree>::tSubdivision subdivision(bezier_curve.GetSubdivision()); 
    427   canvas << subdivision.first << subdivision.second; 
     412  canvas.DrawBezierCurve(Tdegree, bezier_curve.ControlPoints(), bezier_curve.ControlPoints() + bezier_curve.NumberOfControlPoints()); 
    428413 
    429414  return canvas; 
  • curves/tSplineCurve.h

    r37 r40  
    9898  tSplineCurve(TIterator begin, TIterator end); 
    9999 
     100  template <typename ... TPoints> 
     101  tSplineCurve(const typename tShape::tPoint &p1, const typename tShape::tPoint &p2, const TPoints &... rest); 
     102 
    100103  inline const size_t NumberOfControlPoints() const 
    101104  { 
     
    117120  void AppendControlPoint(const typename tShape::tPoint &point); 
    118121 
    119   void InsertControlPoint(size_t at, const typename tShape::tPoint &point); 
     122  void InsertControlPoint(size_t position, const typename tShape::tPoint &point); 
    120123 
    121124  const typename tShape::tPoint operator()(tParameter t) const; 
  • curves/tSplineCurve.hpp

    r37 r40  
    7070tSplineCurve<Tdimension, TElement, Tdegree>::tSplineCurve(TIterator begin, TIterator end) 
    7171{ 
     72  static_assert(Tdegree > 0, "The degree of spline curves must be greater than zero"); 
    7273  std::copy(begin, end, std::back_inserter(this->control_points)); 
    73   assert(control_points.size() > Tdegree); 
     74  assert(control_points.size() > Tdegree && "A spline curve needs at least degree + 1 control points"); 
     75  this->bezier_curve_cache.resize(this->NumberOfSegments()); 
     76} 
     77 
     78template <size_t Tdimension, typename TElement, unsigned int Tdegree> 
     79template <typename ... TPoints> 
     80tSplineCurve<Tdimension, TElement, Tdegree>::tSplineCurve(const typename tShape::tPoint &p1, const typename tShape::tPoint &p2, const TPoints &... rest) 
     81{ 
     82  static_assert(Tdegree > 0, "The degree of spline curves must be greater than zero"); 
     83  static_assert(sizeof...(rest) + 2 > Tdegree, "A spline curve needs at least degree + 1 control points"); 
     84  util::ProcessVariadicValues<typename tShape::tPoint>([this](const typename tShape::tPoint & x) mutable { this->control_points.push_back(x); }, p1, p2, rest...); 
    7485  this->bezier_curve_cache.resize(this->NumberOfSegments()); 
    7586} 
     
    101112//---------------------------------------------------------------------- 
    102113template <size_t Tdimension, typename TElement, unsigned int Tdegree> 
    103 void tSplineCurve<Tdimension, TElement, Tdegree>::InsertControlPoint(size_t at, const typename tShape::tPoint &point) 
    104 { 
    105   this->control_points.insert(this->control_points.begin() + at, point); 
     114void tSplineCurve<Tdimension, TElement, Tdegree>::InsertControlPoint(size_t position, const typename tShape::tPoint &point) 
     115{ 
     116  assert(position < this->control_points.size()); 
     117  this->control_points.insert(this->control_points.begin() + position, point); 
    106118  this->SetChanged(); 
    107119  this->bezier_curve_cache.emplace_back(); 
     
    349361#ifdef _LIB_RRLIB_CANVAS_PRESENT_ 
    350362 
    351 template <typename TElement> 
    352 inline canvas::tCanvas2D &operator << (canvas::tCanvas2D &canvas, const tSplineCurve<2, TElement, 2> &spline_curve) 
    353 { 
    354   unsigned int number_of_segments = spline_curve.NumberOfSegments(); 
    355   auto bezier_curve = spline_curve.GetBezierCurveForSegment(0); 
    356   canvas.StartPath(bezier_curve->ControlPoints()[0]); 
    357   for (unsigned int i = 1; i < number_of_segments; ++i) 
    358   { 
    359     canvas.AppendQuadraticBezierCurve(bezier_curve->ControlPoints()[1], bezier_curve->ControlPoints()[2]); 
    360     bezier_curve = spline_curve.GetBezierCurveForSegment(i); 
    361   } 
    362   canvas.AppendQuadraticBezierCurve(bezier_curve->ControlPoints()[1], bezier_curve->ControlPoints()[2]); 
    363  
    364   return canvas; 
    365 } 
    366  
    367 template <typename TElement> 
    368 inline canvas::tCanvas2D &operator << (canvas::tCanvas2D &canvas, const tSplineCurve<2, TElement, 3> &spline_curve) 
    369 { 
    370   unsigned int number_of_segments = spline_curve.NumberOfSegments(); 
    371   auto bezier_curve = spline_curve.GetBezierCurveForSegment(0); 
    372   canvas.StartPath(bezier_curve->ControlPoints()[0]); 
    373   for (unsigned int i = 1; i < number_of_segments; ++i) 
    374   { 
    375     canvas.AppendCubicBezierCurve(bezier_curve->ControlPoints()[1], bezier_curve->ControlPoints()[2], bezier_curve->ControlPoints()[3]); 
    376     bezier_curve = spline_curve.GetBezierCurveForSegment(i); 
    377   } 
    378   canvas.AppendCubicBezierCurve(bezier_curve->ControlPoints()[1], bezier_curve->ControlPoints()[2], bezier_curve->ControlPoints()[3]); 
    379  
    380   return canvas; 
    381 } 
    382  
    383363template <typename TElement, unsigned int Tdegree> 
    384364inline canvas::tCanvas2D &operator << (canvas::tCanvas2D &canvas, const tSplineCurve<2, TElement, Tdegree> &spline_curve) 
Note: See TracChangeset for help on using the changeset viewer.