Belle II Software development
Area2D.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#include "trg/trg/Area2D.h"
10
11namespace Belle2 {
18 const TRGPoint2D& rightUpper)
19 {
20 _c[0] = leftBottom;
21 _c[1] = rightUpper;
22 }
23
25 {
26 }
27
28 void
30 const TRGPoint2D& x1,
31 unsigned& nFound,
32 TRGPoint2D crossPoint[2]) const
33 {
34
35 //...Parameters...
36 const float xDiff = x1.x() - x0.x();
37 const float yDiff = x1.y() - x0.y();
38 const float a = yDiff / xDiff;
39 const float b = x0.x() - a * x0.x();
40
41 //...Find cross-points...
42 nFound = 0;
43 for (unsigned i = 0; i < 2; i++) {
44
45 TRGPoint2D p(_c[i].x(), a * _c[i].x() + b);
46 if (inArea(p))
47 crossPoint[nFound++] = p;
48 if (nFound == 2) return;
49
50 TRGPoint2D q((_c[i].y() - b) / a, _c[i].y());
51 if (inArea(q))
52 crossPoint[nFound++] = q;
53 if (nFound == 2) return;
54 }
55 }
56
58} // namespace Belle2
59
TRGPoint2D _c[2]
2D points
Definition: Area2D.h:43
A class to represent a point in 2D.
Definition: Point2D.h:27
double y(void) const
y of the point
Definition: Point2D.h:99
virtual ~TRGArea2D()
Destructor.
Definition: Area2D.cc:24
TRGArea2D(const TRGPoint2D &leftBottom, const TRGPoint2D &rightUpper)
Contructor.
Definition: Area2D.cc:17
double x(void) const
x of the point
Definition: Point2D.h:92
bool inArea(const TRGPoint2D &x) const
returns true if give point is in the area.
Definition: Area2D.h:50
void cross(const TRGPoint2D &x0, const TRGPoint2D &x1, unsigned &nFound, TRGPoint2D crossPoint[2]) const
returns cross-points.
Definition: Area2D.cc:29
Abstract base class for different kinds of events.