/usr/include/tuxcap/NaturalCubicSpline.h is in libtuxcap-dev 1.4.0.dfsg2-2.1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | ///////////////////////////////////////////////////////////////
//
// Written By: James Poag
//
// http://sexyfaq.jamespoag.com
//
///////////////////////////////////////////////////////////////
//
// Cubic Class, RegenerateSpline, and RegenrateClosedSpline
// written by Tim Lambert.
//
// http://www.cse.unsw.edu.au/~lambert/
//
// Thanks to Brian "Ace" Rothstein For pointing me to Tim.
//
// Special Thanks to Paul Hamilton.
// http://www.mooktowngames.com
// http://mooktown.blogspot.com
//
///////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
// Usage
//////////////////////////////////////////////////////////////
//
// Use AddPoint() to create a Spline. 3 or more points are
// required to create a cubic spline.
//
// Think of the spline as a long straight line. Addressing
// a Point on the line with a single distance variable. The
// Spline will return 2D coordinates for the position passed
// into 'GetPointAt'. 'GetTangentAt' reports the direction
// of travel. Use 'atan2' to turn the tangent into a rotation.
//
// The rest of the functions are used in creating and refining
// the Spline in an editor
//
//////////////////////////////////////////////////////////////
#include <vector>
#include "Point.h"
namespace Sexy
{
class Graphics;
class XMLWriter;
class XMLElement;
class XMLParser;
};
class Cubic
{
float a,b,c,d; /* a + b*u + c*u^2 +d*u^3 */
public:
Cubic(float a, float b, float c, float d){
this->a = a;
this->b = b;
this->c = c;
this->d = d;
}
~Cubic(){};
/** evaluate cubic */
public:
float eval(float u) {
return (((d*u) + c)*u + b)*u + a;
}
float tangent(float u){
return ((3*d*u) + 2*c)*u + b;
}
};
class NaturalCubicSpline
{
protected:
std::vector<Cubic> mYCubics;
std::vector<Cubic> mXCubics;
std::vector<float> mXCoords;
std::vector<float> mYCoords;
std::vector<Sexy::Point> mPoints;
std::vector<Sexy::FPoint> mSpline;
std::vector<float> mSplineSegmentLengths;
virtual void RegenerateSpline(std::vector<float>& theInput, std::vector<Cubic>& theOutput);
virtual void RegenerateClosedSpline(std::vector<float>& theInput, std::vector<Cubic>& theOutput);
virtual float GetMinUFromLineAB(Sexy::FPoint A, Sexy::FPoint B, Sexy::Point C);
virtual float GetMinDistanceFromLineAB(Sexy::FPoint A, Sexy::FPoint B, Sexy::Point C);
float mArcLength;
unsigned int mGranularity;
bool mClosed;
public:
NaturalCubicSpline(void);
virtual ~NaturalCubicSpline(void);
// Drawing Functions
virtual void Draw(Sexy::Graphics* g); //Example on how to draw
virtual void DrawControlPoint(Sexy::Graphics* g, int theControlPointId, int theWidth);
virtual void DrawSplineSegment(Sexy::Graphics* g, int theSplineSegmentId);
// The main functions
virtual void AddPoint(Sexy::Point thePoint);
virtual void RegenerateSplines(); // You Shouldn't have to call this.
virtual Sexy::Point GetPointAt(float theDistanceOnTheSpline);
virtual Sexy::FPoint GetTangentAt(float theLength);
// ADT functions
virtual int GetNumControlPoints(){return (int)mPoints.size();};
virtual int GetNumSplineSegments(){return (int)mXCubics.size();};
virtual float GetArcLength(){return mArcLength;};
virtual void SetClosed(bool bClosed){mClosed = bClosed; RegenerateSplines();};
virtual bool isClosed(){return mClosed;};
virtual int GetGranularity(){return mGranularity;};
virtual void SetGranularity(int theGranularity){mGranularity = theGranularity; RegenerateSplines();};
// For Curve Refinement
virtual void BisectSegment(int theSplineSegmentId);
virtual void DeleteControlPoint(int theControlPointId);
virtual void ClearAllPoints();
// Picking Helper Functions
virtual float GetClosestPointOnSegmentToPoint(Sexy::Point thePoint);
virtual int GetControlPointIdNear(Sexy::Point thePoint);
virtual int GetSegmentIdNear(Sexy::Point thePoint);
virtual Sexy::Point GetControlPoint(int theControlPointId);
virtual void SetControlPoint(int theControlPointId, Sexy::Point thePoint);
//Serialization
virtual void Serialize(Sexy::XMLWriter* theWriter);
virtual void Serialize(Sexy::XMLParser* theParser, Sexy::XMLElement* theNode);
virtual void SaveToFile(std::string theFileName);
virtual void OpenFile(std::string theFileName);
};
|