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