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
This commit is contained in:
Mark Olesen
2019-03-13 08:00:39 +01:00
parent 54989c4a18
commit 2ae60cc7bb
4 changed files with 37 additions and 19 deletions

View File

@ -97,7 +97,7 @@ public:
); );
//- Construct from Istream //- Construct from Istream
inline line(Istream&); inline explicit line(Istream& is);
// Member Functions // Member Functions
@ -149,7 +149,7 @@ public:
) const; ) const;
// Ostream operator // IOstream operators
friend Istream& operator>> <Point, PointRef> friend Istream& operator>> <Point, PointRef>
( (

View File

@ -444,7 +444,7 @@ void Foam::plane::writeDict(Ostream& os) const
} }
// * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
Foam::Ostream& Foam::operator<<(Ostream& os, const plane& pln) Foam::Ostream& Foam::operator<<(Ostream& os, const plane& pln)
{ {

View File

@ -2,7 +2,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) 2004-2010, 2017-2018 OpenCFD Ltd. \\ / A nd | Copyright (C) 2004-2010, 2017-2019 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
| Copyright (C) 2011-2016 OpenFOAM Foundation | Copyright (C) 2011-2016 OpenFOAM Foundation
@ -82,11 +82,6 @@ SourceFiles
namespace Foam namespace Foam
{ {
// Forward Declarations
class plane;
Ostream& operator<<(Ostream& os, const plane& pln);
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class plane Declaration Class plane Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
@ -177,7 +172,7 @@ public:
// Constructors // Constructors
//- Construct null. Does not set normal and point. //- Construct zero-initialised.
inline plane(); inline plane();
//- Construct from normal vector through the origin. //- Construct from normal vector through the origin.
@ -221,9 +216,12 @@ public:
//- The plane unit normal //- The plane unit normal
inline const vector& normal() const; inline const vector& normal() const;
//- The plane base point (same as refPoint) //- The plane base point
inline const point& origin() const; inline const point& origin() const;
//- The plane base point, for modification
inline point& origin();
//- The plane base point (same as origin) //- The plane base point (same as origin)
inline const point& refPoint() const; inline const point& refPoint() const;
@ -293,21 +291,26 @@ public:
//- Write to dictionary //- Write to dictionary
void writeDict(Ostream& os) const; void writeDict(Ostream& os) const;
};
// IOstream Operators // IOstream Operators
//- Write plane properties //- Write plane normal, origin
friend Ostream& operator<<(Ostream& os, const plane& pln); Ostream& operator<<(Ostream& os, const plane& pln);
};
// Global Operators // Global Operators
//- Test for equality of origin and normal
inline bool operator==(const plane& a, const plane& b); 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); inline bool operator!=(const plane& a, const plane& b);
//- Compare origin
inline bool operator<(const plane& a, const plane& b);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -2,7 +2,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) 2018 OpenCFD Ltd. \\ / A nd | Copyright (C) 2018-2019 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -26,6 +26,9 @@ License
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
inline Foam::plane::plane() 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 inline const Foam::point& Foam::plane::refPoint() const
{ {
return origin_; 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());
}
// ************************************************************************* // // ************************************************************************* //