ENH: consistency improvement for edge/line

- added line::last() for consistency with edge::last()

- adjusted unitVec() to return Zero for small vectors.
  Consistent with VectorSpace normalised() and vector::normalise()
This commit is contained in:
Mark Olesen
2018-08-10 11:07:52 +02:00
parent d29d8d6be3
commit e32c2649ed
3 changed files with 24 additions and 13 deletions

View File

@ -421,10 +421,10 @@ inline Foam::vector Foam::edge::unitVec(const UList<point>& pts) const
} }
#endif #endif
Foam::vector v = pts[second()] - pts[first()]; const vector v = (pts[second()] - pts[first()]);
v /= ::Foam::mag(v) + VSMALL; const scalar s(Foam::mag(v));
return v; return s < ROOTVSMALL ? Zero : v/s;
} }

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -98,20 +98,23 @@ public:
inline line(Istream&); inline line(Istream&);
// Member functions // Member Functions
// Access // Access
//- Return first point //- Return first point
inline PointRef first() const; inline PointRef first() const;
//- Return second point //- Return second (last) point
inline PointRef second() const; inline PointRef second() const;
//- Return last (second) point
inline PointRef last() const;
//- Return first point //- Return first point
inline PointRef start() const; inline PointRef start() const;
//- Return second point //- Return second (last) point
inline PointRef end() const; inline PointRef end() const;

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -23,6 +23,7 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "zero.H"
#include "IOstreams.H" #include "IOstreams.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
@ -70,6 +71,13 @@ inline PointRef Foam::line<Point, PointRef>::second() const
} }
template<class Point, class PointRef>
inline PointRef Foam::line<Point, PointRef>::last() const
{
return b_;
}
template<class Point, class PointRef> template<class Point, class PointRef>
inline PointRef Foam::line<Point, PointRef>::start() const inline PointRef Foam::line<Point, PointRef>::start() const
{ {
@ -107,10 +115,10 @@ inline Point Foam::line<Point, PointRef>::vec() const
template<class Point, class PointRef> template<class Point, class PointRef>
inline Point Foam::line<Point, PointRef>::unitVec() const inline Point Foam::line<Point, PointRef>::unitVec() const
{ {
Point v = b_ - a_; const Point v = (b_ - a_);
v /= ::Foam::mag(v) + VSMALL; const scalar s(::Foam::mag(v));
return v; return s < ROOTVSMALL ? Zero : v/s;
} }