diff --git a/src/OpenFOAM/meshes/meshShapes/edge/edgeI.H b/src/OpenFOAM/meshes/meshShapes/edge/edgeI.H index a9f3c39554..22efb3d438 100644 --- a/src/OpenFOAM/meshes/meshShapes/edge/edgeI.H +++ b/src/OpenFOAM/meshes/meshShapes/edge/edgeI.H @@ -421,10 +421,10 @@ inline Foam::vector Foam::edge::unitVec(const UList& 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; } diff --git a/src/OpenFOAM/meshes/primitiveShapes/line/line.H b/src/OpenFOAM/meshes/primitiveShapes/line/line.H index a3ccc2319f..f075228324 100644 --- a/src/OpenFOAM/meshes/primitiveShapes/line/line.H +++ b/src/OpenFOAM/meshes/primitiveShapes/line/line.H @@ -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; diff --git a/src/OpenFOAM/meshes/primitiveShapes/line/lineI.H b/src/OpenFOAM/meshes/primitiveShapes/line/lineI.H index b2ee4d40ea..01b018e50f 100644 --- a/src/OpenFOAM/meshes/primitiveShapes/line/lineI.H +++ b/src/OpenFOAM/meshes/primitiveShapes/line/lineI.H @@ -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::second() const } +template +inline PointRef Foam::line::last() const +{ + return b_; +} + + template inline PointRef Foam::line::start() const { @@ -107,10 +115,10 @@ inline Point Foam::line::vec() const template inline Point Foam::line::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; }