Changed the interface of the interpolating function of a segment (2D and 3D) from the ambiguous P(float) to Lerp(float). Note that with the previous interface it could happen that seg.P(1) != seg.P0() just becouse seg.P(1) was the result of a lerp.

This commit is contained in:
Paolo Cignoni 2013-11-06 16:06:57 +00:00
parent c8ef412821
commit 3bdf666e86
2 changed files with 57 additions and 57 deletions

View File

@ -42,7 +42,7 @@ namespace vcg {
/** /**
Templated class for 3D segment. Templated class for 3D segment.
This is the class for a segment in 3D space. A Segment is stored just as its two extrema (Point3). This is the class for a segment in 3D space. A Segment is stored just as its two extrema (Point3).
@param SegmentScalarType (template parameter) Specifies the type of scalar used to represent coords. @param SegmentScalarType (template parameter) Specifies the type of scalar used to represent coords.
*/ */
template <class SegmentScalarType > template <class SegmentScalarType >
class Segment2 class Segment2
@ -65,42 +65,42 @@ private:
public: public:
/// Members to access either extrema /// Members to access either extrema
inline const PointType &P0() const { return _p0; } inline const PointType &P0() const { return _p0; }
inline const PointType &P1() const { return _p1; } inline const PointType &P1() const { return _p1; }
inline PointType &P0() { return _p0; } inline PointType &P0() { return _p0; }
inline PointType &P1() { return _p1; } inline PointType &P1() { return _p1; }
/// The empty constructor /// The empty constructor
Segment2() {}; Segment2() {};
/// The (a,b) constructor /// The (a,b) constructor
Segment2(const PointType &a, const PointType &b) { _p0=a; _p1=b; }; Segment2(const PointType &a, const PointType &b) { _p0=a; _p1=b; };
/// Operator to compare segments /// Operator to compare segments
inline bool operator == ( SegmentType const & p ) const inline bool operator == ( SegmentType const & p ) const
{ return _p0==p._p0 && _p1==p._p1; } { return _p0==p._p0 && _p1==p._p1; }
/// Operator to dispare segments /// Operator to dispare segments
inline bool operator != ( SegmentType const & p ) const inline bool operator != ( SegmentType const & p ) const
{ return _p0!=p._p0 || _p1!=p._p1; } { return _p0!=p._p0 || _p1!=p._p1; }
/// initializes the segment with its extrema /// initializes the segment with its extrema
void Set( const PointType &a, const PointType &b) void Set( const PointType &a, const PointType &b)
{ _p0=a; _p1=b;} { _p0=a; _p1=b;}
/// calculates the point of parameter t on the segment. /// calculates the point of parameter t on the segment.
/// if t is in [0..1] returned point is inside the segment /// if t is in [0..1] returned point is inside the segment
inline PointType P( const ScalarType t ) const inline PointType Lerp( const ScalarType t ) const
{ return _p0 + (_p1 - _p0) * t; } { return _p0 + (_p1 - _p0) * t; }
/// return the middle point /// return the middle point
inline PointType MidPoint( ) const inline PointType MidPoint( ) const
{ return ( _p0 + _p1) / ScalarType(2.0) ; } { return ( _p0 + _p1) / ScalarType(2.0) ; }
/// return the bounding box /// return the bounding box
inline Box2<ScalarType> BBox( ) const inline Box2<ScalarType> BBox( ) const
{ {
Box2<ScalarType> t; Box2<ScalarType> t;
t.Add(_p0); t.Add(_p0);
t.Add(_p1); t.Add(_p1);
return t; return t;
} }
/// returns segment length /// returns segment length
ScalarType Length() ScalarType Length()
{ return (_p0 - _p1).Norm(); } { return (_p0 - _p1).Norm(); }
/// returns segment length /// returns segment length
ScalarType Length() const ScalarType Length() const

View File

@ -61,7 +61,7 @@ namespace vcg {
/** /**
Templated class for 3D segment. Templated class for 3D segment.
This is the class for a segment in 3D space. A Segment is stored just as its two extrema (Point3). This is the class for a segment in 3D space. A Segment is stored just as its two extrema (Point3).
@param SegmentScalarType (template parameter) Specifies the type of scalar used to represent coords. @param SegmentScalarType (template parameter) Specifies the type of scalar used to represent coords.
*/ */
template <class SegmentScalarType > template <class SegmentScalarType >
class Segment3 class Segment3
@ -84,7 +84,7 @@ private:
public: public:
/// Members to access either extrema /// Members to access either extrema
inline const PointType &P0() const { return _p0; } inline const PointType &P0() const { return _p0; }
inline const PointType &P1() const { return _p1; } inline const PointType &P1() const { return _p1; }
inline PointType &P0() { return _p0; } inline PointType &P0() { return _p0; }
@ -108,7 +108,7 @@ public:
{ _p0=a; _p1=b;} { _p0=a; _p1=b;}
/// calculates the point of parameter t on the segment. /// calculates the point of parameter t on the segment.
/// if t is in [0..1] returned point is inside the segment /// if t is in [0..1] returned point is inside the segment
inline PointType P( const ScalarType t ) const inline PointType Lerp( const ScalarType t ) const
{ return _p0 + (_p1 - _p0) * t; } { return _p0 + (_p1 - _p0) * t; }
/// return the middle point /// return the middle point
inline PointType MidPoint( ) const inline PointType MidPoint( ) const