initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / OpenFOAM / meshes / primitiveShapes / line / line.H
blobe9f7c0296f81327d41a868ebe73eed644150b83b
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::line
28 Description
29     A line primitive.
31 SourceFiles
32     lineI.H
34 \*---------------------------------------------------------------------------*/
36 #ifndef line_H
37 #define line_H
39 #include "vector.H"
40 #include "PointHit.H"
41 #include "point2D.H"
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 namespace Foam
48 // Forward declaration of classes
50 class Istream;
51 class Ostream;
54 // Forward declaration of friend functions and operators
56 template<class Point, class PointRef> class line;
58 template<class Point, class PointRef>
59 inline Istream& operator>>(Istream&, line<Point, PointRef>&);
61 template<class Point, class PointRef>
62 inline Ostream& operator<<(Ostream&, const line<Point, PointRef>&);
65 /*---------------------------------------------------------------------------*\
66                            Class line Declaration
67 \*---------------------------------------------------------------------------*/
69 template<class Point, class PointRef>
70 class line
72     // Private data
74         PointRef a_, b_;
77 public:
79     // Constructors
81         //- Construct from two points
82         inline line(const Point& start, const Point& end);
84         //- Construct from Istream
85         inline line(Istream&);
88     // Member functions
90         // Access
92             //- Return first vertex
93             inline PointRef start() const;
95             //- Return second vertex
96             inline PointRef end() const;
99         // Properties
101             //- Return centre (centroid)
102             inline Point centre() const;
104             //- Return scalar magnitude
105             inline scalar mag() const;
107             //- Return start-end vector
108             inline Point vec() const;
110             //- Return nearest distance to line from a given point
111             //  If the nearest point is on the line, return a hit
112             PointHit<Point> nearestDist(const Point& p) const;
114             //- Return nearest distance from line to line. Returns distance
115             //  and sets both points (one on *this, one on the provided
116             //  linePointRef.
117             scalar nearestDist
118             (
119                 const line<Point, const Point&>& edge,
120                 Point& thisPoint,
121                 Point& edgePoint
122             ) const;
125     // Ostream operator
127         friend Istream& operator>> <Point, PointRef>
128         (
129             Istream&,
130             line&
131         );
133         friend Ostream& operator<< <Point, PointRef>
134         (
135             Ostream&,
136             const line&
137         );
141 //- 2D specialisation
142 template<>
143 scalar line<point2D, const point2D&>::nearestDist
145     const line<point2D, const point2D&>& edge,
146     point2D& thisPoint,
147     point2D& edgePoint
148 ) const;
151 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
153 } // End namespace Foam
155 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
157 #include "lineI.H"
159 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
161 #endif
163 // ************************************************************************* //