From a6163888f3c56123b1db313743c6147ba498732c Mon Sep 17 00:00:00 2001 From: Yuval Adam Date: Fri, 8 Aug 2014 14:42:07 +0300 Subject: Add third_party libs --- third_party/windows/fltk-1.1.10/src/fl_curve.cxx | 106 +++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 third_party/windows/fltk-1.1.10/src/fl_curve.cxx (limited to 'third_party/windows/fltk-1.1.10/src/fl_curve.cxx') diff --git a/third_party/windows/fltk-1.1.10/src/fl_curve.cxx b/third_party/windows/fltk-1.1.10/src/fl_curve.cxx new file mode 100644 index 0000000..5007e9a --- /dev/null +++ b/third_party/windows/fltk-1.1.10/src/fl_curve.cxx @@ -0,0 +1,106 @@ +// +// "$Id: fl_curve.cxx 5190 2006-06-09 16:16:34Z mike $" +// +// Bezier curve functions for the Fast Light Tool Kit (FLTK). +// +// Copyright 1998-2005 by Bill Spitzak and others. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Library General Public +// License as published by the Free Software Foundation; either +// version 2 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Library General Public License for more details. +// +// You should have received a copy of the GNU Library General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +// USA. +// +// Please report all bugs and problems on the following page: +// +// http://www.fltk.org/str.php +// + +// Utility for drawing Bezier curves, adding the points to +// the current fl_begin/fl_vertex/fl_end path. +// Incremental math implementation: +// I very much doubt this is optimal! From Foley/vanDam page 511. +// If anybody has a better algorithim, please send it! + +#include +#include + +void fl_curve(double X0, double Y0, + double X1, double Y1, + double X2, double Y2, + double X3, double Y3) { + + double x = fl_transform_x(X0,Y0); + double y = fl_transform_y(X0,Y0); + + // draw point 0: + fl_transformed_vertex(x,y); + + double x1 = fl_transform_x(X1,Y1); + double yy1 = fl_transform_y(X1,Y1); + double x2 = fl_transform_x(X2,Y2); + double y2 = fl_transform_y(X2,Y2); + double x3 = fl_transform_x(X3,Y3); + double y3 = fl_transform_y(X3,Y3); + + // find the area: + double a = fabs((x-x2)*(y3-yy1)-(y-y2)*(x3-x1)); + double b = fabs((x-x3)*(y2-yy1)-(y-y3)*(x2-x1)); + if (b > a) a = b; + + // use that to guess at the number of segments: + int n = int(sqrt(a)/4); + if (n > 1) { + if (n > 100) n = 100; // make huge curves not hang forever + + double e = 1.0/n; + + // calculate the coefficients of 3rd order equation: + double xa = (x3-3*x2+3*x1-x); + double xb = 3*(x2-2*x1+x); + double xc = 3*(x1-x); + // calculate the forward differences: + double dx1 = ((xa*e+xb)*e+xc)*e; + double dx3 = 6*xa*e*e*e; + double dx2 = dx3 + 2*xb*e*e; + + // calculate the coefficients of 3rd order equation: + double ya = (y3-3*y2+3*yy1-y); + double yb = 3*(y2-2*yy1+y); + double yc = 3*(yy1-y); + // calculate the forward differences: + double dy1 = ((ya*e+yb)*e+yc)*e; + double dy3 = 6*ya*e*e*e; + double dy2 = dy3 + 2*yb*e*e; + + // draw points 1 .. n-2: + for (int m=2; m