Commit e32c2649 authored by Mark Olesen's avatar Mark Olesen
Browse files

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()
parent d29d8d6b
......@@ -421,10 +421,10 @@ inline Foam::vector Foam::edge::unitVec(const UList<point>& pts) const
}
#endif
Foam::vector v = pts[second()] - pts[first()];
v /= ::Foam::mag(v) + VSMALL;
const vector v = (pts[second()] - pts[first()]);
const scalar s(Foam::mag(v));
return v;
return s < ROOTVSMALL ? Zero : v/s;
}
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -98,24 +98,27 @@ public:
inline line(Istream&);
// Member functions
// Member Functions
// Access
// Access
//- Return first point
inline PointRef first() const;
//- Return second point
//- Return second (last) point
inline PointRef second() const;
//- Return last (second) point
inline PointRef last() const;
//- Return first point
inline PointRef start() const;
//- Return second point
//- Return second (last) point
inline PointRef end() const;
// Properties
// Properties
//- Return centre (centroid)
inline Point centre() const;
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -23,6 +23,7 @@ License
\*---------------------------------------------------------------------------*/
#include "zero.H"
#include "IOstreams.H"
// * * * * * * * * * * * * * * * * 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>
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>
inline Point Foam::line<Point, PointRef>::unitVec() const
{
Point v = b_ - a_;
v /= ::Foam::mag(v) + VSMALL;
const Point v = (b_ - a_);
const scalar s(::Foam::mag(v));
return v;
return s < ROOTVSMALL ? Zero : v/s;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment