https://gitlab.opengeosys.org/ogs/ogs.git
Raw File
Tip revision: a0de7c86bca851b217650a4119c13eed0723b758 authored by Dmitry Yu. Naumov on 15 September 2023, 11:25:11 UTC
Merge branch 'SmallFixes' into 'master'
Tip revision: a0de7c8
LineRule.cpp
/**
 * \file
 * \copyright
 * Copyright (c) 2012-2023, OpenGeoSys Community (http://www.opengeosys.org)
 *            Distributed under a Modified BSD License.
 *              See accompanying file LICENSE.txt or
 *              http://www.opengeosys.org/project/license
 */

#include "LineRule.h"

#include "MathLib/MathTools.h"
#include "MeshLib/Node.h"

namespace MeshLib
{
double LineRule::computeVolume(Node const* const* element_nodes)
{
    return std::sqrt(MathLib::sqrDist(*element_nodes[0], *element_nodes[1]));
}

bool LineRule::isPntInElement(Node const* const* nodes,
                              MathLib::Point3d const& pnt, double eps)
{
    auto const& a = *nodes[0];
    auto const& b = *nodes[1];

    if (MathLib::sqrDist(a, pnt) < eps * eps)
    {
        return true;
    }
    if (MathLib::sqrDist(b, pnt) < eps * eps)
    {
        return true;
    }

    double lambda;
    double distance_of_proj_pnt_to_a;
    auto const distance_from_line = MathLib::calcProjPntToLineAndDists(
        pnt, a, b, lambda, distance_of_proj_pnt_to_a);

    if (lambda >= 0 && lambda <= 1)
    {
        // pnt has been projected to the interior of the line
        return distance_from_line < eps;
    }
    else
    {
        // pnt has been projected outside the line segment
        // corner cases have already been treated in the beginning
        return false;
    }
}

unsigned LineRule::identifyFace(Node const* const* element_nodes,
                                Node const* nodes[1])
{
    if (nodes[0] == element_nodes[0])
    {
        return 0;
    }
    if (nodes[0] == element_nodes[1])
    {
        return 1;
    }
    return std::numeric_limits<unsigned>::max();
}

ElementErrorCode LineRule::validate(const Element* e)
{
    ElementErrorCode error_code;
    error_code[ElementErrorFlag::ZeroVolume] = hasZeroVolume(*e);
    return error_code;
}
}  // end namespace MeshLib
back to top