Commit c2f59af0 authored by Mark Olesen's avatar Mark Olesen Committed by Andrew Heather
Browse files

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
parent a2fb1d0b
......@@ -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>> <Point, PointRef>
(
......
......@@ -444,7 +444,7 @@ void Foam::plane::writeDict(Ostream& os) const
}
// * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
Foam::Ostream& Foam::operator<<(Ostream& os, const plane& pln)
{
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017-2018 OpenCFD Ltd.
\\ / A nd | Copyright (C) 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);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......
......@@ -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());
}
// ************************************************************************* //
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