OGS
LineRule2.cpp
Go to the documentation of this file.
1 
11 #include "LineRule2.h"
12 
13 #include "MathLib/MathTools.h"
14 #include "MeshLib/Node.h"
15 
16 namespace MeshLib
17 {
18 const unsigned LineRule2::edge_nodes[1][2] = {
19  {0, 1} // Edge 0
20 };
21 
22 double LineRule2::computeVolume(Node const* const* _nodes)
23 {
24  return std::sqrt(MathLib::sqrDist(*_nodes[0], *_nodes[1]));
25 }
26 
27 bool LineRule2::isPntInElement(Node const* const* nodes,
28  MathLib::Point3d const& pnt, double eps)
29 {
30  auto const& a = *nodes[0];
31  auto const& b = *nodes[1];
32 
33  if (MathLib::sqrDist(a, pnt) < eps * eps)
34  {
35  return true;
36  }
37  if (MathLib::sqrDist(b, pnt) < eps * eps)
38  {
39  return true;
40  }
41 
42  double lambda;
43  double distance_of_proj_pnt_to_a;
44  auto const distance_from_line = MathLib::calcProjPntToLineAndDists(
45  pnt, a, b, lambda, distance_of_proj_pnt_to_a);
46 
47  if (lambda >= 0 && lambda <= 1)
48  {
49  // pnt has been projected to the interior of the line
50  return distance_from_line < eps;
51  }
52  else
53  {
54  // pnt has been projected outside the line segment
55  // corner cases have already been treated in the beginning
56  return false;
57  }
58 }
59 
60 unsigned LineRule2::identifyFace(Node const* const* _nodes,
61  Node const* nodes[1])
62 {
63  if (nodes[0] == _nodes[0])
64  {
65  return 0;
66  }
67  if (nodes[0] == _nodes[1])
68  {
69  return 1;
70  }
71  return std::numeric_limits<unsigned>::max();
72 }
73 
75 {
76  ElementErrorCode error_code;
78  return error_code;
79 }
80 
81 } // end namespace MeshLib
Definition of the Node class.
Collects error flags for mesh elements.
static bool isPntInElement(Node const *const *nodes, MathLib::Point3d const &pnt, double eps)
Definition: LineRule2.cpp:27
static ElementErrorCode validate(const Element *e)
Definition: LineRule2.cpp:74
static const unsigned edge_nodes[1][2]
Constant: Local node index table for edge.
Definition: LineRule2.h:46
static double computeVolume(Node const *const *_nodes)
Calculates the length of a line.
Definition: LineRule2.cpp:22
static unsigned identifyFace(Node const *const *, Node const *nodes[1])
Returns the ID of a face given an array of nodes.
Definition: LineRule2.cpp:60
double calcProjPntToLineAndDists(Point3d const &pp, Point3d const &pa, Point3d const &pb, double &lambda, double &d0)
Definition: MathTools.cpp:19
double sqrDist(MathLib::Point3d const &p0, MathLib::Point3d const &p1)
Definition: Point3d.cpp:26
bool hasZeroVolume(MeshLib::Element const &element)
Returns true if the element has zero length/area/volume.
Definition: Element.cpp:119