BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
Line Class Reference
Inheritance diagram for Line:
Collaboration diagram for Line:

Public Member Functions

 Line (double x1, double y1, double x2, double y2)
 
Lineclone () const
 
bool contains (double x, double y) const
 
bool contains (const Bin1D &binx, const Bin1D &biny) const
 
virtual void transferToCPP ()
 

Protected Member Functions

virtual void print (std::ostream &ostr) const
 

Private Attributes

double m_x1
 
double m_y1
 
double m_x2
 
double m_y2
 
const char *const m_name
 

Detailed Description

A line segment.

Definition at line 23 of file Line.h.

Constructor & Destructor Documentation

◆ Line()

Line::Line ( double  x1,
double  y1,
double  x2,
double  y2 
)

Definition at line 29 of file Line.cpp.

30  : IShape2D("Line"), m_x1(x1), m_y1(y1), m_x2(x2), m_y2(y2)
31 {
32 }
IShape2D(const char *name)
Definition: IShape2D.h:29
double m_x2
Definition: Line.h:33
double m_x1
Definition: Line.h:33
double m_y1
Definition: Line.h:33
double m_y2
Definition: Line.h:33

Referenced by clone().

Member Function Documentation

◆ clone()

Line* Line::clone ( ) const
inlinevirtual

Implements IShape2D.

Definition at line 27 of file Line.h.

27 { return new Line(m_x1, m_y1, m_x2, m_y2); }
Line(double x1, double y1, double x2, double y2)
Definition: Line.cpp:29

References Line(), m_x1, m_x2, m_y1, and m_y2.

Here is the call graph for this function:

◆ contains() [1/2]

bool Line::contains ( double  x,
double  y 
) const
virtual

Returns true if point with given coordinates is inside or on border of the shape.

Implements IShape2D.

Definition at line 34 of file Line.cpp.

35 {
36  point_t p(x, y);
37  line_t line;
38  line.push_back(point_t(m_x1, m_y1));
39  line.push_back(point_t(m_x2, m_y2));
40 
41  double d = distance(p, line);
42 
43  return d < std::numeric_limits<double>::epsilon();
44 }
model::linestring< point_t > line_t
Definition: Line.cpp:27
model::d2::point_xy< double > point_t
Definition: Line.cpp:25

References m_x1, m_x2, m_y1, m_y2, and anonymous_namespace{InterferenceFunctionHardDisk.cpp}::p.

◆ contains() [2/2]

bool Line::contains ( const Bin1D binx,
const Bin1D biny 
) const
virtual

Returns true if area defined by two bins is inside or on border of polygon (more precisely, if mid point of two bins satisfy this condition).

Implements IShape2D.

Definition at line 48 of file Line.cpp.

49 {
50  std::vector<point_t> box_points;
51  box_points.push_back(point_t(binx.m_lower, biny.m_lower));
52  box_points.push_back(point_t(binx.m_lower, biny.m_upper));
53  box_points.push_back(point_t(binx.m_upper, biny.m_upper));
54  box_points.push_back(point_t(binx.m_upper, biny.m_lower));
55  box_points.push_back(point_t(binx.m_lower, biny.m_lower));
56 
57  std::vector<point_t> line_points;
58  line_points.push_back(point_t(m_x1, m_y1));
59  line_points.push_back(point_t(m_x2, m_y2));
60 
61  return intersects(line_t(box_points.begin(), box_points.end()),
62  line_t(line_points.begin(), line_points.end()));
63 }
double m_upper
upper bound of the bin
Definition: Bin.h:24
double m_lower
lower bound of the bin
Definition: Bin.h:23

References Bin1D::m_lower, Bin1D::m_upper, m_x1, m_x2, m_y1, and m_y2.

◆ print()

virtual void IShape2D::print ( std::ostream &  ostr) const
inlineprotectedvirtualinherited

Reimplemented in Polygon.

Definition at line 46 of file IShape2D.h.

46 { ostr << m_name; }
const char *const m_name
Definition: IShape2D.h:49

References IShape2D::m_name.

◆ transferToCPP()

virtual void ICloneable::transferToCPP ( )
inlinevirtualinherited

Used for Python overriding of clone (see swig/tweaks.py)

Definition at line 34 of file ICloneable.h.

Member Data Documentation

◆ m_x1

double Line::m_x1
private

Definition at line 33 of file Line.h.

Referenced by clone(), and contains().

◆ m_y1

double Line::m_y1
private

Definition at line 33 of file Line.h.

Referenced by clone(), and contains().

◆ m_x2

double Line::m_x2
private

Definition at line 33 of file Line.h.

Referenced by clone(), and contains().

◆ m_y2

double Line::m_y2
private

Definition at line 33 of file Line.h.

Referenced by clone(), and contains().

◆ m_name

const char* const IShape2D::m_name
privateinherited

Definition at line 49 of file IShape2D.h.

Referenced by IShape2D::print().


The documentation for this class was generated from the following files: