Wm4LinComp.h

Go to the documentation of this file.
00001 // Wild Magic Source Code
00002 // David Eberly
00003 // http://www.geometrictools.com
00004 // Copyright (c) 1998-2007
00005 //
00006 // This library is free software; you can redistribute it and/or modify it
00007 // under the terms of the GNU Lesser General Public License as published by
00008 // the Free Software Foundation; either version 2.1 of the License, or (at
00009 // your option) any later version.  The license is available for reading at
00010 // either of the locations:
00011 //     http://www.gnu.org/copyleft/lgpl.html
00012 //     http://www.geometrictools.com/License/WildMagicLicense.pdf
00013 // The license applies to versions 0 through 4 of Wild Magic.
00014 //
00015 // Version: 4.0.0 (2006/06/28)
00016 
00017 #ifndef WM4LINCOMP_H
00018 #define WM4LINCOMP_H
00019 
00020 #include "Wm4FoundationLIB.h"
00021 #include "Wm4Math.h"
00022 
00023 namespace Wm4
00024 {
00025 
00026 template <class Real>
00027 class LinComp
00028 {
00029 public:
00030     // abstract base class
00031     virtual ~LinComp ();
00032 
00033     // The linear component is represented as P+t*D where P is the component
00034     // origin and D is a unit-length direction vector.  The user must ensure
00035     // that the direction vector satisfies this condition.  The t-intervals
00036     // for lines, rays, segments, points, or the empty set are described
00037     // later.
00038 
00039     // component type
00040     enum
00041     {
00042         CT_EMPTY,
00043         CT_POINT,
00044         CT_SEGMENT,
00045         CT_RAY,
00046         CT_LINE
00047     };
00048 
00049     int GetType () const;
00050 
00051     // The interval of restriction for t, as defined above.  The function
00052     // SetInterval(min,max) sets the t-interval; it handles all possible
00053     // inputs according to the following scheme:
00054     //   CT_LINE:
00055     //     [-MAX_REAL,MAX_REAL]
00056     //   CT_RAY:
00057     //     [min,MAX_REAL], where min is finite
00058     //     [-MAX_REAL,max], where max is finite
00059     //   CT_SEGMENT:
00060     //     [min,max], where min and max are finite with min < max
00061     //   CT_POINT:
00062     //     [min,max], where min and max are finite with min = max
00063     //   CT_EMPTY:
00064     //     [min,max], where min > max or min = max = MAX_REAL or
00065     //                min = max = -MAX_REAL
00066     void SetInterval (Real fMin, Real fMax);
00067 
00068     // Determine the type of an interval without having to create an instance
00069     // of a LinComp object.
00070     static int GetTypeFromInterval (Real fMin, Real fMax);
00071 
00072     // The canonical intervals are [-MAX_REAL,MAX_REAL] for a line;
00073     // [0,MAX_REAL] for a ray; [-e,e] for a segment, where e > 0; [0,0] for
00074     // a point, and [MAX_REAL,-MAX_REAL] for the empty set.  If the interval
00075     // is [min,max], the adjustments are as follows.
00076     // 
00077     // CT_RAY:  If max is MAX_REAL and if min is not zero, then P is modified
00078     // to P' = P+min*D so that the ray is represented by P'+t*D for t >= 0.
00079     // If min is -MAX_REAL and max is finite, then the origin and direction
00080     // are modified to P' = P+max*D and D' = -D.
00081     //
00082     // CT_SEGMENT:  If min is not -max, then P is modified to
00083     // P' = P + ((min+max)/2)*D and the extent is e' = (max-min)/2.
00084     //
00085     // CT_POINT:  If min is not zero, the P is modified to P' = P+min*D.
00086     //
00087     // CT_EMPTY:  Set max to -MAX_REAL and min to MAX_REAL.
00088     //
00089     // The first function is virtual since the updates are dependent on the
00090     // dimension of the vector space.
00091     virtual void MakeCanonical () = 0;
00092     bool IsCanonical () const;
00093 
00094     // access the interval [min,max]
00095     Real GetMin () const;
00096     Real GetMax () const;
00097 
00098     // Determine if the specified parameter is in the interval.
00099     bool Contains (Real fParam) const;
00100 
00101 protected:
00102     LinComp ();  // default is CT_NONE
00103 
00104     // assignment
00105     LinComp& operator= (const LinComp& rkComponent);
00106 
00107     // component type
00108     int m_iType;
00109 
00110     // the interval of restriction for t
00111     Real m_fMin, m_fMax;
00112 };
00113 
00114 } //namespace Wm4
00115 
00116 #include "Wm4LinComp.inl"
00117 
00118 namespace Wm4
00119 {
00120 typedef LinComp<float> LinCompf;
00121 typedef LinComp<double> LinCompd;
00122 }
00123 
00124 #endif

Generated on Wed Nov 23 19:01:04 2011 for FreeCAD by  doxygen 1.6.1