From 2ae60cc7bb33d4f53ddb17646725f535948bd53a Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Wed, 13 Mar 2019 08:00:39 +0100 Subject: [PATCH] ENH: minor improvements for plane - comparison operator, for sorting based on the position of the origin. - allow modification of the origin. - zero-initialise for null constructor: base components are vectors and cheap to initialise. - 'unfriend' the output operator: it uses public access methods --- .../meshes/primitiveShapes/line/line.H | 4 +-- .../meshes/primitiveShapes/plane/plane.C | 2 +- .../meshes/primitiveShapes/plane/plane.H | 33 ++++++++++--------- .../meshes/primitiveShapes/plane/planeI.H | 17 +++++++++- 4 files changed, 37 insertions(+), 19 deletions(-) diff --git a/src/OpenFOAM/meshes/primitiveShapes/line/line.H b/src/OpenFOAM/meshes/primitiveShapes/line/line.H index 6874303885..0ad694e88d 100644 --- a/src/OpenFOAM/meshes/primitiveShapes/line/line.H +++ b/src/OpenFOAM/meshes/primitiveShapes/line/line.H @@ -97,7 +97,7 @@ public: ); //- Construct from Istream - inline line(Istream&); + inline explicit line(Istream& is); // Member Functions @@ -149,7 +149,7 @@ public: ) const; - // Ostream operator + // IOstream operators friend Istream& operator>> ( diff --git a/src/OpenFOAM/meshes/primitiveShapes/plane/plane.C b/src/OpenFOAM/meshes/primitiveShapes/plane/plane.C index 893283b87b..13ed7517f6 100644 --- a/src/OpenFOAM/meshes/primitiveShapes/plane/plane.C +++ b/src/OpenFOAM/meshes/primitiveShapes/plane/plane.C @@ -444,7 +444,7 @@ void Foam::plane::writeDict(Ostream& os) const } -// * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * // +// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * // Foam::Ostream& Foam::operator<<(Ostream& os, const plane& pln) { diff --git a/src/OpenFOAM/meshes/primitiveShapes/plane/plane.H b/src/OpenFOAM/meshes/primitiveShapes/plane/plane.H index c02c8b70ba..83a4e934fa 100644 --- a/src/OpenFOAM/meshes/primitiveShapes/plane/plane.H +++ b/src/OpenFOAM/meshes/primitiveShapes/plane/plane.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010, 2017-2018 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2004-2010, 2017-2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- | Copyright (C) 2011-2016 OpenFOAM Foundation @@ -82,11 +82,6 @@ SourceFiles namespace Foam { -// Forward Declarations -class plane; -Ostream& operator<<(Ostream& os, const plane& pln); - - /*---------------------------------------------------------------------------*\ Class plane Declaration \*---------------------------------------------------------------------------*/ @@ -177,7 +172,7 @@ public: // Constructors - //- Construct null. Does not set normal and point. + //- Construct zero-initialised. inline plane(); //- Construct from normal vector through the origin. @@ -221,9 +216,12 @@ public: //- The plane unit normal inline const vector& normal() const; - //- The plane base point (same as refPoint) + //- The plane base point inline const point& origin() const; + //- The plane base point, for modification + inline point& origin(); + //- The plane base point (same as origin) inline const point& refPoint() const; @@ -293,21 +291,26 @@ public: //- Write to dictionary void writeDict(Ostream& os) const; - - - // IOstream Operators - - //- Write plane properties - friend Ostream& operator<<(Ostream& os, const plane& pln); - }; +// IOstream Operators + +//- Write plane normal, origin +Ostream& operator<<(Ostream& os, const plane& pln); + + // Global Operators +//- Test for equality of origin and normal inline bool operator==(const plane& a, const plane& b); + +//- Test for inequality of origin or normal inline bool operator!=(const plane& a, const plane& b); +//- Compare origin +inline bool operator<(const plane& a, const plane& b); + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/meshes/primitiveShapes/plane/planeI.H b/src/OpenFOAM/meshes/primitiveShapes/plane/planeI.H index 83d14f529e..7e56258817 100644 --- a/src/OpenFOAM/meshes/primitiveShapes/plane/planeI.H +++ b/src/OpenFOAM/meshes/primitiveShapes/plane/planeI.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2018 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2018-2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -26,6 +26,9 @@ License // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // inline Foam::plane::plane() +: + normal_(Zero), + origin_(Zero) {} @@ -43,6 +46,12 @@ inline const Foam::point& Foam::plane::origin() const } +inline Foam::point& Foam::plane::origin() +{ + return origin_; +} + + inline const Foam::point& Foam::plane::refPoint() const { return origin_; @@ -103,4 +112,10 @@ inline bool Foam::operator!=(const plane& a, const plane& b) } +inline bool Foam::operator<(const plane& a, const plane& b) +{ + return (a.origin() < b.origin()); +} + + // ************************************************************************* //