initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / OpenFOAM / meshes / primitiveShapes / objectHit / PointHit.H
blob375978a0b22e293cac8c772ecfc4a08880a8a8d1
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software; you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 Class
26     Foam::PointHit
28 Description
29     This class describes the interaction of a face and a point. It
30     carries the info of a successful hit and (if successful), returns
31     the interaction point.
33 \*---------------------------------------------------------------------------*/
35 #ifndef PointHit_H
36 #define PointHit_H
38 #include "bool.H"
39 #include "token.H"
41 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 namespace Foam
46 // Forward declaration of classes
48 class Ostream;
51 // Forward declaration of friend functions and operators
53 template<class Point> class PointHit;
55 template<class Point>
56 inline Ostream& operator<<(Ostream&, const PointHit<Point>&);
59 /*---------------------------------------------------------------------------*\
60                            Class PointHit Declaration
61 \*---------------------------------------------------------------------------*/
63 template<class Point>
64 class PointHit
66     // Private data
68         //- Hit success
69         bool hit_;
71         //- Point of hit; for miss holds best estimate outside the object
72         Point hitPoint_;
74         //- Distance to hit point
75         scalar distance_;
77         //- Eligible miss
78         bool eligibleMiss_;
81 public:
83     // Constructors
85         //- Construct from components
86         PointHit
87         (
88             const bool hit,
89             const Point& p,
90             const scalar dist,
91             const bool eligibleMiss
92         )
93         :
94             hit_(hit),
95             hitPoint_(p),
96             distance_(dist),
97             eligibleMiss_(eligibleMiss)
98         {}
100         //- Construct from point. Hit and distance set later
101         PointHit(const Point& p)
102         :
103             hit_(false),
104             hitPoint_(p),
105             distance_(GREAT),
106             eligibleMiss_(false)
107         {}
110     // Member Functions
112         //- Is there a hit
113         bool hit() const
114         {
115             return hit_;
116         }
118         //- Return hit point
119         const Point& hitPoint() const
120         {
121             if (!hit_)
122             {
123                 FatalErrorIn("const Point& PointHit::hitPoint() const")
124                     << "requested a hit point for a miss"
125                     << abort(FatalError);
126             }
128             return hitPoint_;
129         }
131         //- Return distance to hit
132         scalar distance() const
133         {
134             return distance_;
135         }
137         //- Return miss point
138         const Point& missPoint() const
139         {
140             if (hit_)
141             {
142                 FatalErrorIn("const Point& PointHit::missPoint() const")
143                     << "requested a miss point for a hit"
144                     << abort(FatalError);
145             }
147             return hitPoint_;
148         }
150         //- Return point with no checking
151         const Point& rawPoint() const
152         {
153             return hitPoint_;
154         }
156         //- Is this an eligible miss
157         bool eligibleMiss() const
158         {
159             return eligibleMiss_;
160         }
162         void setHit()
163         {
164             hit_ = true;
165             eligibleMiss_ = false;
166         }
168         void setMiss(const bool eligible)
169         {
170             hit_ = false;
171             eligibleMiss_ = eligible;
172         }
174         void setPoint(const Point& p)
175         {
176             hitPoint_ = p;
177         }
179         void setDistance(const scalar d)
180         {
181             distance_ = d;
182         }
185     // Ostream operator
187         friend Ostream& operator<< <Point>
188         (
189             Ostream& os,
190             const PointHit<Point>& b
191         );
195 template<class Point>
196 inline Ostream& operator<<(Ostream& os, const PointHit<Point>& b)
198     os  << b.hit() << token::SPACE
199         << b.rawPoint() << token::SPACE
200         << b.distance() << token::SPACE
201         << b.eligibleMiss();
203     return os;
207 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
209 } // End namespace Foam
211 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
213 #endif
215 // ************************************************************************* //