OGS
LineRule.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
4#include "LineRule.h"
5
6#include "MathLib/MathTools.h"
7#include "MeshLib/Node.h"
8
9namespace MeshLib
10{
11double LineRule::computeVolume(Node const* const* element_nodes)
12{
13 return std::sqrt(MathLib::sqrDist(*element_nodes[0], *element_nodes[1]));
14}
15
16bool LineRule::isPntInElement(Node const* const* nodes,
17 MathLib::Point3d const& pnt, double eps)
18{
19 auto const& a = *nodes[0];
20 auto const& b = *nodes[1];
21
22 if (MathLib::sqrDist(a, pnt) < eps * eps)
23 {
24 return true;
25 }
26 if (MathLib::sqrDist(b, pnt) < eps * eps)
27 {
28 return true;
29 }
30
31 double lambda;
32 double distance_of_proj_pnt_to_a;
33 auto const distance_from_line = MathLib::calcProjPntToLineAndDists(
34 pnt, a, b, lambda, distance_of_proj_pnt_to_a);
35
36 if (lambda >= 0 && lambda <= 1)
37 {
38 // pnt has been projected to the interior of the line
39 return distance_from_line < eps;
40 }
41
42 // pnt has been projected outside the line segment
43 // corner cases have already been treated in the beginning
44 return false;
45}
46
47unsigned LineRule::identifyFace(Node const* const* element_nodes,
48 Node const* nodes[1])
49{
50 if (nodes[0] == element_nodes[0])
51 {
52 return 0;
53 }
54 if (nodes[0] == element_nodes[1])
55 {
56 return 1;
57 }
58 return std::numeric_limits<unsigned>::max();
59}
60
62{
63 ElementErrorCode error_code;
65 return error_code;
66}
67} // end namespace MeshLib
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:47
static ElementErrorCode validate(const Element *e)
Definition LineRule.cpp:61
static double computeVolume(Node const *const *element_nodes)
Calculates the length of a line.
Definition LineRule.cpp:11
static bool isPntInElement(Node const *const *nodes, MathLib::Point3d const &pnt, double eps)
Definition LineRule.cpp:16
double calcProjPntToLineAndDists(Point3d const &pp, Point3d const &pa, Point3d const &pb, double &lambda, double &d0)
Definition MathTools.cpp:13
double sqrDist(MathLib::Point3d const &p0, MathLib::Point3d const &p1)
Definition Point3d.cpp:19
bool hasZeroVolume(MeshLib::Element const &element)
Returns true if the element has zero length/area/volume.
Definition Element.cpp:126