+
+inline bool CompRealByPtr(const Real * a, const Real * b)
+{
+ return (*a) < (*b);
+}
+
+/**
+ * Get Bounds Rectangle of Bezier
+ */
+Rect Bezier::SolveBounds() const
+{
+ Rect result;
+ pair<Real, Real> tsols = BezierTurningPoints(x0, x1, x2, x3);
+
+ Real tp0; Real tp1; Real o;
+ Evaluate(tp0, o, tsols.first);
+ Evaluate(tp1, o, tsols.second);
+
+ Debug("x: tp0 is %f tp1 is %f", Float(tp0), Float(tp1));
+
+ vector<const Real*> v(4);
+ v[0] = &x0;
+ v[1] = &x3;
+ v[2] = &tp0;
+ v[3] = &tp1;
+
+ // Not using a lambda to keep this compiling on cabellera
+ sort(v.begin(), v.end(), CompRealByPtr);
+
+ result.x = *(v[0]);
+ result.w = *(v[3]) - result.x;
+
+ // Do the same thing for y component (wow this is a mess)
+ tsols = BezierTurningPoints(y0, y1, y2, y3);
+ Evaluate(o, tp0, tsols.first);
+ Evaluate(o, tp1, tsols.second);
+
+
+ Debug("y: tp0 is %f tp1 is %f", Float(tp0), Float(tp1));
+
+ v[0] = &y0;
+ v[1] = &y3;
+ v[2] = &tp0;
+ v[3] = &tp1;
+ sort(v.begin(), v.end(), CompRealByPtr);
+
+ result.y = *(v[0]);
+ result.h = *(v[3]) - result.y;
+
+ Debug("Solved Bezier %s bounds as %s", Str().c_str(), result.Str().c_str());
+ return result;
+}
+
+} // end namespace