Garfield++ v2r0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
Heed::polyline Class Reference

Polyline. More...

#include <polyline.h>

+ Inheritance diagram for Heed::polyline:

Public Member Functions

int Gqpt () const
 
point Gpt (int n) const
 
int Gqsl () const
 
straight Gsl (int n) const
 
int check_point_in (const point &fpt, vfloat prec) const
 
int cross (const straight &fsl, point *pc, int &qpc, polyline *pl, int &qpl, vfloat prec) const
 
vfloat dist_two_inter (polyline &pl, vfloat prec) const
 Distance between two intervals.
 
vfloat distance (const point &fpt) const
 
vfloat distance (const point &fpt, point &cpt) const
 Distance between two points.
 
 polyline ()
 
 polyline (polyline &pl)
 
 polyline (const polyline &pl)
 
 polyline (const point *fpt, int fqpt)
 
 polyline (const point &fpt1, const point &fpt2)
 
polylineoperator= (const polyline &fpl)
 
 ~polyline ()
 
- Public Member Functions inherited from Heed::absref
virtual ~absref ()
 Destructor.
 
virtual void down (const abssyscoor *fasc)
 Convert numbering representation of object to basical system of fasc.
 
virtual void up (const abssyscoor *fasc)
 Convert numbering representation of objects to new system.
 
virtual void turn (const vec &dir, vfloat angle)
 Turn around axis doing via center of coordinate system along dir.
 
virtual void shift (const vec &dir)
 

Protected Member Functions

virtual void get_components (ActivePtr< absref_transmit > &aref_tran)
 
void polyline_init (const point *fpt, int fqpt)
 
void polyline_del ()
 

Protected Attributes

int qpt
 
pointpt
 
int qsl
 
straightsl
 
absref ** aref
 

Friends

int plane::cross (const polyline &pll, point *crpt, int &qcrpt, polyline *crpll, int &qcrpll, vfloat prec) const
 
std::ostream & operator<< (std::ostream &file, const polyline &p)
 

Detailed Description

Polyline.

Definition at line 23 of file polyline.h.

Constructor & Destructor Documentation

◆ polyline() [1/5]

Heed::polyline::polyline ( )
inline

Definition at line 92 of file polyline.h.

92 {
93 point ptl;
94 polyline_init(&ptl, 0);
95 }
void polyline_init(const point *fpt, int fqpt)
Definition: polyline.cpp:50

Referenced by cross().

◆ polyline() [2/5]

Heed::polyline::polyline ( polyline pl)

Definition at line 22 of file polyline.cpp.

22 : absref(pl) {
23 mfunname("polyline::polyline( polyline &pl)");
24 polyline_init(pl.pt, pl.qpt);
25}
#define mfunname(string)
Definition: FunNameStack.h:45

◆ polyline() [3/5]

Heed::polyline::polyline ( const polyline pl)

Definition at line 26 of file polyline.cpp.

26 : absref(pl) {
27 mfunname("polyline::polyline(const polyline &pl)");
28 polyline_init(pl.pt, pl.qpt);
29}

◆ polyline() [4/5]

Heed::polyline::polyline ( const point fpt,
int  fqpt 
)

Definition at line 30 of file polyline.cpp.

30 {
31 mfunname("polyline::polyline(const point* fpt, int fqpt)");
32 polyline_init(fpt, fqpt);
33}

◆ polyline() [5/5]

Heed::polyline::polyline ( const point fpt1,
const point fpt2 
)

Definition at line 34 of file polyline.cpp.

34 {
35 // interval
36 mfunname("polyline::polyline(const point& fpt1, const point& fpt2)");
37 point fpt[2];
38 fpt[0] = fpt1;
39 fpt[1] = fpt2;
40 polyline_init(fpt, 2);
41}

◆ ~polyline()

Heed::polyline::~polyline ( )
inline

Definition at line 105 of file polyline.h.

105{ polyline_del(); }
void polyline_del()
Definition: polyline.h:76

Member Function Documentation

◆ check_point_in()

int Heed::polyline::check_point_in ( const point fpt,
vfloat  prec 
) const

Return whether a point is inside. 0 point is not in 1 point coincides with an edge 2 point is inside an interval

Definition at line 76 of file polyline.cpp.

76 {
77 pvecerror("int polyline::check_point_in(point& fpt, vfloat prec)");
78 for (int n = 0; n < qpt; ++n) {
79 if (apeq(pt[n], fpt, prec)) return 1;
80 }
81 for (int n = 0; n < qsl; ++n) {
82 if (sl[n].check_point_in(fpt, prec) == 1) {
83 vec v1 = fpt - pt[n];
84 vec v2 = fpt - pt[n + 1];
85 if (check_par(v1, v2, prec) == -1) {
86 // anti-parallel vectors, point inside borders
87 return 2;
88 }
89 }
90 }
91 return 0;
92}
point * pt
Definition: polyline.h:26
straight * sl
Definition: polyline.h:28
int check_point_in(const point &fpt, vfloat prec) const
Definition: polyline.cpp:76
bool apeq(const circumf &f1, const circumf &f2, vfloat prec)
Definition: circumf.cpp:44
#define pvecerror(string)
Definition: vec.h:29

Referenced by check_point_in(), Heed::polygon::check_point_in(), and dist_two_inter().

◆ cross()

int Heed::polyline::cross ( const straight fsl,
point pc,
int &  qpc,
polyline pl,
int &  qpl,
vfloat  prec 
) const

If straight line goes exactly by segment of polyline, the fuction gives two end points of adjacent segments and the segment itself. If one of the points is common, it is given several times. For example, if line crosses break point the point is given two times.

Definition at line 94 of file polyline.cpp.

95 {
96 pvecerror("void polyline::cross(const straight& fsl, ...)");
97 qpc = 0;
98 qpl = 0;
99 for (int n = 0; n < qsl; ++n) {
100 pc[qpc] = sl[n].cross(fsl, prec);
101 if (vecerror == 1 || vecerror == 2) {
102 // lines do not cross
103 vecerror = 0;
104 } else if (vecerror == 3) {
105 // the same straight line
106 pl[qpl++] = polyline(&(pt[n]), 2);
107 } else {
108 vec v1 = pc[qpc] - pt[n];
109 if (v1.length() < prec) {
110 qpc++;
111 } else {
112 vec v2 = pc[qpc] - pt[n + 1];
113 if (v2.length() < prec) {
114 qpc++;
115 } else if (check_par(v1, v2, prec) == -1) {
116 // anti-parallel vectors, point inside borders
117 qpc++;
118 }
119 }
120 }
121 }
122 if (qpc > 0 || qpl > 0) return 1;
123 return 0;
124}
point cross(const straight &sl, vfloat prec) const
Definition: straight.cpp:54
int vecerror
Definition: vec.cpp:29

◆ dist_two_inter()

vfloat Heed::polyline::dist_two_inter ( polyline pl,
vfloat  prec 
) const

Distance between two intervals.

Definition at line 126 of file polyline.cpp.

126 {
127 pvecerror("vfloat polyline::dist_two_inter(polyline& pl)");
128 const polyline& pl1 = *this;
129 check_econd11(pl1.Gqpt(), != 2, mcerr);
130 check_econd11(pl2.Gqpt(), != 2, mcerr);
131 point cpt[2];
132 int type_of_cross;
133 vfloat sldist = pl1.Gsl(0).distance(pl2.Gsl(0), type_of_cross, cpt);
134 if (type_of_cross == 2 || type_of_cross == 3) return sldist;
135 if (pl1.check_point_in(cpt[0], prec) > 0 &&
136 pl2.check_point_in(cpt[1], prec) > 0)
137 return sldist;
138 vfloat mx = max_vfloat;
139 vfloat r;
140 if ((r = pl1.distance(pl2.Gpt(0))) < mx) mx = r;
141 if ((r = pl1.distance(pl2.Gpt(1))) < mx) mx = r;
142 if ((r = pl2.distance(pl1.Gpt(0))) < mx) mx = r;
143 if ((r = pl2.distance(pl1.Gpt(1))) < mx) mx = r;
144 return mx;
145}
#define check_econd11(a, signb, stream)
Definition: FunNameStack.h:155
double vfloat
Definition: vfloat.h:16
#define mcerr
Definition: prstream.h:128

◆ distance() [1/2]

vfloat Heed::polyline::distance ( const point fpt) const

Definition at line 147 of file polyline.cpp.

147 {
148 pvecerror("vfloat polyline::distance(const point& fpt) const");
149 check_econd11(qsl, <= 0, mcerr);
150 vfloat sldist;
151 point cpt;
152 vfloat mx = max_vfloat;
153 int n;
154 for (n = 0; n < qsl; n++) {
155 sldist = sl[n].distance(fpt, cpt);
156 vec v1 = cpt - pt[n];
157 vec v2 = cpt - pt[n + 1];
158 if (check_par(v1, v2, 0.01) ==
159 -1) { // anti-parallel vectors, point inside borders
160 if (sldist < mx) mx = sldist;
161 } else {
162 if ((sldist = (fpt - pt[n]).length()) < mx) mx = sldist;
163 if ((sldist = (fpt - pt[n + 1]).length()) < mx) mx = sldist;
164 }
165 }
166 return mx;
167}
vfloat distance(const straight &sl, int &type_of_cross, point pt[2]) const
Definition: straight.cpp:137

Referenced by dist_two_inter().

◆ distance() [2/2]

vfloat Heed::polyline::distance ( const point fpt,
point cpt 
) const

Distance between two points.

Definition at line 169 of file polyline.cpp.

169 {
170 pvecerror("vfloat polyline::distance(const point& fpt) const");
171 check_econd11(qsl, <= 0, mcerr);
172 vfloat sldist;
173 point cpt;
174 vfloat mx = max_vfloat;
175 int n;
176 for (n = 0; n < qsl; n++) {
177 sldist = sl[n].distance(fpt, cpt);
178 vec v1 = cpt - pt[n];
179 vec v2 = cpt - pt[n + 1];
180 if (check_par(v1, v2, 0.01) ==
181 -1) { // anti-parallel vectors, point inside borders
182 if (sldist < mx) {
183 mx = sldist;
184 fcpt = cpt;
185 }
186 } else {
187 if ((sldist = (fpt - pt[n]).length()) < mx) {
188 mx = sldist;
189 fcpt = pt[n];
190 }
191 if ((sldist = (fpt - pt[n + 1]).length()) < mx) {
192 mx = sldist;
193 fcpt = pt[n + 1];
194 }
195 }
196 }
197 return mx;
198}

◆ get_components()

void Heed::polyline::get_components ( ActivePtr< absref_transmit > &  aref_tran)
protectedvirtual

Reimplemented from Heed::absref.

Reimplemented in Heed::polyline_pl, Heed::rectangle, and Heed::spquadr.

Definition at line 18 of file polyline.cpp.

18 {
19 aref_tran.pass(new absref_transmit(qpt + qsl, aref));
20}
absref ** aref
Definition: polyline.h:51

◆ Gpt()

point Heed::polyline::Gpt ( int  n) const
inline

Definition at line 32 of file polyline.h.

32 {
33 if (n >= qpt) {
34 mcerr << "error in polyline:Gpt(int n): n>qpt: n=" << n << " qpt=" << qpt
35 << '\n';
37 }
38 return pt[n];
39 }
#define spexit(stream)
Definition: FunNameStack.h:256

Referenced by Heed::cross4pllines(), dist_two_inter(), and Heed::polygon::polygon().

◆ Gqpt()

int Heed::polyline::Gqpt ( ) const
inline

Definition at line 31 of file polyline.h.

31{ return qpt; }

Referenced by dist_two_inter(), and Heed::polygon::polygon().

◆ Gqsl()

int Heed::polyline::Gqsl ( ) const
inline

Definition at line 40 of file polyline.h.

40{ return qsl; }

Referenced by Heed::splane::cross(), and Heed::polyline_pl::polyline_pl().

◆ Gsl()

straight Heed::polyline::Gsl ( int  n) const
inline

Definition at line 41 of file polyline.h.

41 {
42 if (n >= qsl) {
43 mcerr << "error in polyline:Gpt(int n): n>qsl: n=" << n << " qsl=" << qsl
44 << '\n';
46 }
47 return sl[n];
48 }

Referenced by dist_two_inter(), and Heed::polyline_pl::polyline_pl().

◆ operator=()

polyline & Heed::polyline::operator= ( const polyline fpl)

Definition at line 43 of file polyline.cpp.

43 {
44 mfunname("polyline& polyline::operator=(const polyline& fpl)");
46 polyline_init(fpl.pt, fpl.qpt);
47 return *this;
48}

Referenced by Heed::polyline_pl::polyline_pl().

◆ polyline_del()

void Heed::polyline::polyline_del ( )
inlineprotected

Definition at line 76 of file polyline.h.

76 {
77 if (pt) {
78 delete[] pt;
79 pt = NULL;
80 }
81 if (sl) {
82 delete[] sl;
83 sl = NULL;
84 }
85 if (aref) {
86 delete[] aref;
87 aref = NULL;
88 }
89 }

Referenced by Heed::polygon::operator=(), operator=(), Heed::polyline_pl::operator=(), and ~polyline().

◆ polyline_init()

void Heed::polyline::polyline_init ( const point fpt,
int  fqpt 
)
protected

Definition at line 50 of file polyline.cpp.

50 {
51 pvecerror("void polyline::polyline_init(const point* fpt, int fqpt)");
52 check_econd11(fqpt, < 0, mcerr)
53 if (fqpt < 1) {
54 qpt = 0;
55 qsl = 0;
56 pt = NULL;
57 sl = NULL;
58 aref = NULL;
59 return;
60 }
61 pt = new point[fqpt];
62 for (qpt = 0; qpt < fqpt; ++qpt) pt[qpt] = fpt[qpt];
63 if (fqpt >= 2) {
64 sl = new straight[qpt - 1];
65 for (qsl = 0; qsl < qpt - 1; ++qsl) {
66 sl[qsl] = straight(pt[qsl], pt[qsl + 1]);
67 }
68 } else {
69 sl = NULL;
70 }
71 aref = new absref* [qpt + qsl];
72 for (int n = 0; n < qpt; ++n) aref[n] = &pt[n];
73 for (int n = 0; n < qsl; ++n) aref[n + qpt] = &sl[n];
74}

Referenced by Heed::polygon::operator=(), operator=(), Heed::polyline_pl::operator=(), and polyline().

Friends And Related Function Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream &  file,
const polyline p 
)
friend

Definition at line 221 of file polyline.cpp.

221 {
222 int n;
223 Ifile << "polyline:\n";
224 indn.n += 2;
225 Ifile << "qpt=" << p.qpt << '\n';
226 for (n = 0; n < p.qpt; n++) file << p.pt[n];
227 Ifile << "qsl=" << p.qsl << '\n';
228 for (n = 0; n < p.qsl; n++) file << p.sl[n];
229 indn.n -= 2;
230 return file;
231}
indentation indn
Definition: prstream.cpp:15
#define Ifile
Definition: prstream.h:196

◆ plane::cross

int plane::cross ( const polyline pll,
point crpt,
int &  qcrpt,
polyline crpll,
int &  qcrpll,
vfloat  prec 
) const
friend

Member Data Documentation

◆ aref

◆ pt

◆ qpt

◆ qsl

◆ sl

straight* Heed::polyline::sl
protected

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