Belle II Software development
LineSegment2D.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9/* Own header. */
10#include <klm/eklm/geometry/LineSegment2D.h>
11
12using namespace Belle2;
13
15 const HepGeom::Point3D<double>& point2) :
16 Line2D(point1.x(), point1.y(),
17 point2.x() - point1.x(), point2.y() - point1.y())
18{
19}
20
24
26// cppcheck-suppress duplInheritedMember ; the line segment versions intentionally hide the Line2D ones
27findIntersection(const Line2D& line,
28 HepGeom::Point3D<double>* intersection) const
29{
30 int n;
31 double t[2];
32 bool condition;
33 n = Line2D::findIntersection(line, intersection, t);
34 if (n == 0)
35 return 0;
36 condition = tWithinRange(t[0]);
37 return selectIntersections(intersection, &condition, 1);
38}
39
40
42findIntersection(const LineSegment2D& lineSegment,
43 HepGeom::Point3D<double>* intersection) const
44{
45 int n;
46 double t[2];
47 bool condition;
48 n = Line2D::findIntersection(lineSegment, intersection, t);
49 if (n == 0)
50 return 0;
51 condition = tWithinRange(t[0]) && lineSegment.tWithinRange(t[1]);
52 return selectIntersections(intersection, &condition, 1);
53}
54
56// cppcheck-suppress duplInheritedMember ; the line segment versions intentionally hide the Line2D ones
57findIntersection(const Circle2D& circle,
58 HepGeom::Point3D<double> intersections[2]) const
59{
60 int i, n;
61 double t[2], angles[2];
62 bool condition[2] = {false, false};
63 n = Line2D::findIntersection(circle, intersections, t, angles);
64 for (i = 0; i < n; i++)
65 condition[i] = tWithinRange(t[i]);
66 return selectIntersections(intersections, condition, n);
67}
68
70// cppcheck-suppress duplInheritedMember ; the line segment versions intentionally hide the Line2D ones
71findIntersection(const Arc2D& arc,
72 HepGeom::Point3D<double> intersections[2]) const
73{
74 int i, n;
75 double t[2], angles[2];
76 bool condition[2] = {false, false};
77 n = Line2D::findIntersection(arc, intersections, t, angles);
78 for (i = 0; i < n; i++)
79 condition[i] = tWithinRange(t[i]) && arc.angleWithinRange(angles[i]);
80 return selectIntersections(intersections, condition, n);
81}
82
84{
85 return (t >= 0 && t <= 1);
86}
87
int findIntersection(const Line2D &line, HepGeom::Point3D< double > *intersection) const
Find intersection with a line.
Definition Line2D.cc:28
static int selectIntersections(HepGeom::Point3D< double > *intersections, const bool *condition, int n)
Select intersections.
Definition Line2D.cc:132
Line2D(double x, double y, double vecx, double vecy)
Constructor.
Definition Line2D.cc:17
int findIntersection(const Line2D &line, HepGeom::Point3D< double > *intersection) const
Find intersection with a line.
LineSegment2D(const HepGeom::Point3D< double > &point1, const HepGeom::Point3D< double > &point2)
Constructor.
static bool tWithinRange(double t)
Check if t is within the line segment (0 <= t <= 1).
Abstract base class for different kinds of events.