Garfield++ v1r0
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

#include <polyline.h>

+ Inheritance diagram for Heed::polyline:

Public Member Functions

int Gqpt (void) const
 
point Gpt (int n) const
 
int Gqsl (void) 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
 
vfloat distance (const point &fpt) const
 
vfloat distance (const point &fpt, point &cpt) const
 
 polyline (void)
 
 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 (void)
 
- Public Member Functions inherited from absref
virtual ~absref ()
 
virtual void down (const abssyscoor *fasc)
 
virtual void up (const abssyscoor *fasc)
 
virtual void turn (const vec &dir, vfloat angle)
 
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 (void)
 

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

Definition at line 26 of file polyline.h.

Constructor & Destructor Documentation

◆ polyline() [1/5]

Heed::polyline::polyline ( void  )
inline

Definition at line 97 of file polyline.h.

97 {
98 point ptl;
99 polyline_init(&ptl, 0);
100 }
void polyline_init(const point *fpt, int fqpt)
Definition: polyline.cpp:50
Definition: vec.h:477

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:67
Definition: vec.h:134

◆ 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 ( void  )
inline

Definition at line 110 of file polyline.h.

110{ polyline_del(); }
void polyline_del(void)
Definition: polyline.h:81

Member Function Documentation

◆ check_point_in()

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

Definition at line 79 of file polyline.cpp.

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

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

Definition at line 97 of file polyline.cpp.

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

◆ dist_two_inter()

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

Definition at line 129 of file polyline.cpp.

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

◆ distance() [1/2]

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

Definition at line 150 of file polyline.cpp.

150 {
151 pvecerror("vfloat polyline::distance(const point& fpt) const");
152 check_econd11(qsl, <= 0, mcerr);
153 vfloat sldist;
154 point cpt;
155 vfloat mx = max_vfloat;
156 int n;
157 for (n = 0; n < qsl; n++) {
158 sldist = sl[n].distance(fpt, cpt);
159 vec v1 = cpt - pt[n];
160 vec v2 = cpt - pt[n + 1];
161 if (check_par(v1, v2, 0.01) ==
162 -1) { // anti-parallel vectors, point inside borders
163 if (sldist < mx) mx = sldist;
164 } else {
165 if ((sldist = length(fpt - pt[n])) < mx) mx = sldist;
166 if ((sldist = length(fpt - pt[n + 1])) < mx) mx = sldist;
167 }
168 }
169 return mx;
170}
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

Definition at line 172 of file polyline.cpp.

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

◆ get_components()

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

Reimplemented from 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:55

◆ Gpt()

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

Definition at line 35 of file polyline.h.

35 { // there is no funname line, check directly
36 //check_econd12(n , >= , qpt , mcerr);
37 if (n >= qpt) {
38 mcerr << "error in polyline:Gpt(int n): n>qpt: n=" << n << " qpt=" << qpt
39 << '\n';
41 }
42 return pt[n];
43 }
#define spexit(stream)
Definition: FunNameStack.h:536

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

◆ Gqpt()

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

Definition at line 34 of file polyline.h.

34{ return qpt; }

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

◆ Gqsl()

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

Definition at line 44 of file polyline.h.

44{ 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 45 of file polyline.h.

45 {
46 if (n >= qsl) {
47 mcerr << "error in polyline:Gpt(int n): n>qsl: n=" << n << " qsl=" << qsl
48 << '\n';
50 }
51 return sl[n];
52 }

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 ( void  )
inlineprotected

Definition at line 81 of file polyline.h.

81 {
82 if (pt != NULL) {
83 delete[] pt;
84 pt = NULL;
85 }
86 if (sl != NULL) {
87 delete[] sl;
88 sl = NULL;
89 }
90 if (aref != NULL) {
91 delete[] aref;
92 aref = NULL;
93 }
94 }

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 pt = new point[fqpt];
55 for (qpt = 0; qpt < fqpt; ++qpt)
56 pt[qpt] = fpt[qpt];
57 if (fqpt >= 2) {
58 sl = new straight[qpt - 1];
59 for (qsl = 0; qsl < qpt - 1; ++qsl) {
60 sl[qsl] = straight(pt[qsl], pt[qsl + 1]);
61 }
62 } else {
63 sl = NULL;
64 }
65 aref = new absref* [qpt + qsl];
66 for (int n = 0; n < qpt; ++n)
67 aref[n] = &pt[n];
68 for (int n = 0; n < qsl; ++n)
69 aref[n + qpt] = &sl[n];
70 } else {
71 qpt = 0;
72 qsl = 0;
73 pt = NULL;
74 sl = NULL;
75 aref = NULL;
76 }
77}

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 225 of file polyline.cpp.

225 {
226 int n;
227 Ifile << "polyline:\n";
228 indn.n += 2;
229 Ifile << "qpt=" << p.qpt << '\n';
230 for (n = 0; n < p.qpt; n++)
231 file << p.pt[n];
232 Ifile << "qsl=" << p.qsl << '\n';
233 for (n = 0; n < p.qsl; n++)
234 file << p.sl[n];
235 indn.n -= 2;
236 return file;
237}
indentation indn
Definition: prstream.cpp:13
#define Ifile
Definition: prstream.h:207

◆ 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: