LCOV - code coverage report
Current view: top level - include/geometries - LineSegment.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #33416 (b10b36) with base 9fbd27 Lines: 2 5 40.0 %
Date: 2026-07-23 16:15:30 Functions: 2 6 33.3 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //* This file is part of the MOOSE framework
       2             : //* https://mooseframework.inl.gov
       3             : //*
       4             : //* All rights reserved, see COPYRIGHT for full restrictions
       5             : //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
       6             : //*
       7             : //* Licensed under LGPL 2.1, please see LICENSE for details
       8             : //* https://www.gnu.org/licenses/lgpl-2.1.html
       9             : 
      10             : #pragma once
      11             : 
      12             : // MOOSE includes
      13             : #include "Ball.h"
      14             : #include "DataIO.h"
      15             : #include "GeometryBase.h"
      16             : 
      17             : #include "json.h"
      18             : #include "libmesh/point.h"
      19             : 
      20             : // forward declarations
      21             : namespace libMesh
      22             : {
      23             : class Plane;
      24             : }
      25             : 
      26             : /**
      27             :  * The LineSegment class is used by the LineMaterialSamplerBase class
      28             :  * and for some ray tracing stuff.
      29             :  */
      30             : class LineSegment : public GeometryBase
      31             : {
      32             : public:
      33             :   LineSegment() = default;
      34             :   LineSegment(const Point & p0, const Point & p1);
      35             : 
      36        2197 :   ~LineSegment() override = default;
      37             : 
      38             :   /**
      39             :    * Returns the closest point on the LineSegment
      40             :    * to the passed in point.  Note that the closest point may be
      41             :    * one of the ends of the LineSegment.
      42             :    */
      43             :   Point closest_point(const Point & p) const;
      44             : 
      45             :   /**
      46             :    * Finds the closest point on the Line determined by the
      47             :    * Line Segments.  Returns a boolean indicating whether
      48             :    * that normal point is within the LineSegment or not
      49             :    */
      50             :   bool closest_normal_point(const Point & p, Point & closest_p) const;
      51             : 
      52             :   /**
      53             :    * Determines whether a point is in a line segment or not
      54             :    */
      55             :   bool contains_point(const Point & p) const;
      56             : 
      57             :   /**
      58             :    * Check if a line segment intersects a plane, and if so, return the intersection point.
      59             :    */
      60             :   bool intersect(const libMesh::Plane & pl, Point & intersect_p) const;
      61             : 
      62             :   /**
      63             :    * Check if a line segment intersects another line segment, and if so, return the intersection
      64             :    * point.
      65             :    */
      66             :   bool intersect(const LineSegment & l1, Point & intersect_p) const;
      67             : 
      68             :   /**
      69             :    * Check if a line segment intersects another line segment, without returning the intersection
      70             :    * point.
      71             :    */
      72             :   bool intersect(const LineSegment & line_segment) const override;
      73             : 
      74             :   /**
      75             :    * Compute a bounding ball for this line segment.
      76             :    *
      77             :    * The ball is defined by the midpoint of the segment and a radius equal to half the segment
      78             :    * length.
      79             :    */
      80             :   Ball computeBoundingBall() const override;
      81             : 
      82             :   /**
      83             :    * Beginning of the line segment.
      84             :    */
      85           0 :   const Point & start() const { return _p0; }
      86             : 
      87             :   /**
      88             :    * Ending of the line segment.
      89             :    */
      90         251 :   const Point & end() const { return _p1; }
      91             : 
      92             :   /**
      93             :    * Sets the beginning of the line segment.
      94             :    */
      95           0 :   void setStart(const Point & p0) { _p0 = p0; }
      96             : 
      97             :   /**
      98             :    * Sets the end of the line segment.
      99             :    */
     100           0 :   void setEnd(const Point & p1) { _p1 = p1; }
     101             : 
     102             :   /**
     103             :    * Sets the points on the line segment.
     104             :    * @param p0 The start point of the line segment
     105             :    * @param p1 The end point of the line segment
     106             :    */
     107             :   void set(const Point & p0, const Point & p1);
     108             : 
     109             :   /**
     110             :    * Length of segment
     111             :    */
     112             :   Real length() const { return (_p0 - _p1).norm(); }
     113             : 
     114             :   /**
     115             :    * normal vector of the line segment
     116             :    */
     117             :   Point normal() const;
     118             : 
     119             : private:
     120             :   bool closest_point(const Point & p, bool clamp_to_segment, Point & closest_p) const;
     121             : 
     122             :   Point _p0, _p1;
     123             : };
     124             : 
     125             : void dataStore(std::ostream & stream, LineSegment & l, void * context);
     126             : void dataLoad(std::istream & stream, LineSegment & l, void * context);
     127             : 
     128             : void to_json(nlohmann::json & json, const LineSegment & l);

Generated by: LCOV version 1.14