line.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
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.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::line
26 
27 Description
28  A line primitive.
29 
30 SourceFiles
31  lineI.H
32 
33 \*---------------------------------------------------------------------------*/
34 
35 #ifndef line_H
36 #define line_H
37 
38 #include "vector.H"
39 #include "PointHit.H"
40 #include "point2D.H"
41 #include "FixedList.H"
42 #include "UList.H"
43 
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 
46 namespace Foam
47 {
48 
49 // Forward declaration of classes
50 
51 class Istream;
52 class Ostream;
53 
54 
55 // Forward declaration of friend functions and operators
56 
57 template<class Point, class PointRef> class line;
58 
59 template<class Point, class PointRef>
61 
62 template<class Point, class PointRef>
63 inline Ostream& operator<<(Ostream&, const line<Point, PointRef>&);
64 
65 
66 /*---------------------------------------------------------------------------*\
67  Class line Declaration
68 \*---------------------------------------------------------------------------*/
69 
70 template<class Point, class PointRef>
71 class line
72 {
73  // Private data
74 
75  PointRef a_, b_;
76 
77 
78 public:
79 
80  // Constructors
81 
82  //- Construct from two points
83  inline line(const Point& start, const Point& end);
84 
85  //- Construct from two points in the list of points
86  // The indices could be from edge etc.
87  inline line
88  (
89  const UList<Point>&,
90  const FixedList<label, 2>& indices
91  );
92 
93  //- Construct from Istream
94  inline line(Istream&);
95 
96 
97  // Member functions
98 
99  // Access
100 
101  //- Return first vertex
102  inline PointRef start() const;
103 
104  //- Return second vertex
105  inline PointRef end() const;
106 
107 
108  // Properties
109 
110  //- Return centre (centroid)
111  inline Point centre() const;
112 
113  //- Return scalar magnitude
114  inline scalar mag() const;
115 
116  //- Return start-end vector
117  inline Point vec() const;
118 
119  //- Return nearest distance to line from a given point
120  // If the nearest point is on the line, return a hit
121  PointHit<Point> nearestDist(const Point& p) const;
122 
123  //- Return nearest distance from line to line. Returns distance
124  // and sets both points (one on *this, one on the provided
125  // linePointRef.
126  scalar nearestDist
127  (
129  Point& thisPoint,
130  Point& edgePoint
131  ) const;
132 
133  bool insideBoundBox(const Point&) const;
134 
135 
136  // Ostream operator
137 
138  friend Istream& operator>> <Point, PointRef>
139  (
140  Istream&,
141  line&
142  );
143 
144  friend Ostream& operator<< <Point, PointRef>
145  (
146  Ostream&,
147  const line&
148  );
149 };
150 
151 
152 //- 2D specialisation
153 template<>
155 (
157  point2D& thisPoint,
158  point2D& edgePoint
159 ) const;
160 
161 
162 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
163 
164 } // End namespace Foam
165 
166 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
167 
168 #include "lineI.H"
169 
170 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
171 
172 #endif
173 
174 // ************************************************************************* //
A line primitive.
Definition: line.H:56
scalar mag() const
Return scalar magnitude.
Definition: lineI.H:80
bool insideBoundBox(const Point &) const
Definition: lineI.H:261
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
line(const Point &start, const Point &end)
Construct from two points.
Definition: lineI.H:31
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
Definition: edge.H:58
Istream & operator>>(Istream &, directionInfo &)
PointRef start() const
Return first vertex.
Definition: lineI.H:60
This class describes the interaction of a face and a point. It carries the info of a successful hit a...
Definition: PointHit.H:51
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:61
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
Point centre() const
Return centre (centroid)
Definition: lineI.H:73
Point vec() const
Return start-end vector.
Definition: lineI.H:87
PointRef end() const
Return second vertex.
Definition: lineI.H:66
volScalarField & p
PointHit< Point > nearestDist(const Point &p) const
Return nearest distance to line from a given point.
Definition: lineI.H:95
Namespace for OpenFOAM.