51 return ((Bx-Ax)*(Cy-Ay) - (By-Ay)*(Cx-Ax))*0.5;
63 return ((B.
x()-Ax)*(C.
y()-Ay) - (B.
y()-Ay)*(C.
x()-Ax))*0.5;
75 return ((C.
x()-A.
x())*(D.
y()-B.
y()) - (C.
y()-A.
y())*(D.
x()-B.
x()))*0.5;
86 G4double area = p[n-1].x()*p[0].y() - p[0].x()*p[n-1].y();
89 area += p[i-1].x()*p[i].y() - p[i].x()*p[i-1].y();
104 if ((Bx-Ax)*(Cy-Ay) - (By-Ay)*(Cx-Ax) > 0.)
106 if ((Ax-Cx)*(Py-Cy) - (Ay-Cy)*(Px-Cx) < 0.)
return false;
107 if ((Bx-Ax)*(Py-Ay) - (By-Ay)*(Px-Ax) < 0.)
return false;
108 if ((Cx-Bx)*(Py-By) - (Cy-By)*(Px-Bx) < 0.)
return false;
112 if ((Ax-Cx)*(Py-Cy) - (Ay-Cy)*(Px-Cx) > 0.)
return false;
113 if ((Bx-Ax)*(Py-Ay) - (By-Ay)*(Px-Ax) > 0.)
return false;
114 if ((Cx-Bx)*(Py-By) - (Cy-By)*(Px-Bx) > 0.)
return false;
132 if ((Bx-Ax)*(Cy-Ay) - (By-Ay)*(Cx-Ax) > 0.)
134 if ((Ax-Cx)*(Py-Cy) - (Ay-Cy)*(Px-Cx) < 0.)
return false;
135 if ((Bx-Ax)*(Py-Ay) - (By-Ay)*(Px-Ax) < 0.)
return false;
136 if ((Cx-Bx)*(Py-By) - (Cy-By)*(Px-Bx) < 0.)
return false;
140 if ((Ax-Cx)*(Py-Cy) - (Ay-Cy)*(Px-Cx) > 0.)
return false;
141 if ((Bx-Ax)*(Py-Ay) - (By-Ay)*(Px-Ax) > 0.)
return false;
142 if ((Cx-Bx)*(Py-By) - (Cy-By)*(Px-Bx) > 0.)
return false;
156 for (
G4int i = 0, k = Nv - 1; i < Nv; k = i++)
158 if ((v[i].
y() > p.
y()) != (v[k].
y() > p.
y()))
160 G4double ctg = (v[k].x()-v[i].x())/(v[k].
y()-v[i].y());
161 in ^= (p.
x() < (p.
y()-v[i].y())*ctg + v[i].
x());
176 G4bool gotNegative =
false;
177 G4bool gotPositive =
false;
179 if (n <= 0)
return false;
180 for (
G4int icur=0; icur<
n; ++icur)
182 G4int iprev = (icur == 0) ? n-1 : icur-1;
183 G4int inext = (icur == n-1) ? 0 : icur+1;
187 if (std::abs(cross) < kCarTolerance)
return false;
188 if (cross < 0) gotNegative =
true;
189 if (cross > 0) gotPositive =
true;
190 if (gotNegative && gotPositive)
return false;
203 std::vector<G4int> triangles;
206 G4int n = triangles.size();
207 for (
G4int i=0; i<
n; ++i) result.push_back(polygon[triangles[i]]);
216 std::vector<G4int>&
result)
223 if (n < 3)
return false;
230 for (
G4int i=0; i<
n; ++i) V[i] = i;
232 for (
G4int i=0; i<
n; ++i) V[i] = (n-1)-i;
238 for(
G4int b=nv-1; nv>2; )
244 if (area < 0.)
std::reverse(result.begin(),result.end());
249 G4int a = (b < nv) ? b : 0;
250 b = (a+1 < nv) ? a+1 : 0;
251 G4int c = (b+1 < nv) ? b+1 : 0;
256 result.push_back(V[a]);
257 result.push_back(V[b]);
258 result.push_back(V[c]);
262 for(
G4int i=b; i<nv; ++i) V[i] = V[i+1];
268 if (area < 0.)
std::reverse(result.begin(),result.end());
285 G4double Ax = contour[V[
a]].x(), Ay = contour[V[
a]].y();
286 G4double Bx = contour[V[b]].x(), By = contour[V[b]].y();
287 G4double Cx = contour[V[c]].x(), Cy = contour[V[c]].y();
288 if ((Bx-Ax)*(Cy-Ay) - (By-Ay)*(Cx-Ax) < kCarTolerance)
return false;
297 if((i == a) || (i == b) || (i == c))
continue;
299 if (Px < xmin || Px > xmax)
continue;
301 if (Py < ymin || Py > ymax)
continue;
312 std::vector<G4int>& iout,
317 G4double delta = tolerance*tolerance;
321 G4int nv = polygon.size();
326 G4int icur = 0, iprev = 0, inext = 0, nout = 0;
327 for (
G4int i=0; i<nv; ++i)
331 for (
G4int k=1; k<nv+1; ++k)
334 if (iprev < 0) iprev += nv;
335 if (polygon[iprev].
x() != removeIt)
break;
338 for (
G4int k=1; k<nv+1; ++k)
341 if (inext >= nv) inext -= nv;
342 if (polygon[inext].
x() != removeIt)
break;
345 if (iprev == inext)
break;
357 if (leng1 <= delta || leng2 <= delta || leng3 <= delta)
359 polygon[icur].setX(removeIt); nout++;
364 G4double area = std::abs(e1.
x()*e2.
y()-e1.
y()*e2.
x())*0.5;
365 if (area/std::sqrt(lmax) <= std::abs(tolerance))
367 polygon[icur].setX(removeIt); nout++;
377 for (
G4int i=0; i<nv; ++i) iout.push_back(i);
381 for (
G4int i=0; i<nv; ++i)
383 if (polygon[i].
x() != removeIt)
384 polygon[icur++] = polygon[i];
388 if (icur < nv) polygon.resize(icur);
407 if (rmin < 0)
return false;
408 if (rmax <= rmin + kCarTolerance)
return false;
409 if (delPhi <= 0 + kCarTolerance)
return false;
413 pmin.
set(-rmax,-rmax);
414 pmax.
set( rmax, rmax);
418 std::sin(startPhi),std::cos(startPhi),
419 std::sin(startPhi+delPhi),std::cos(startPhi+delPhi),
439 pmin.
set(-rmax,-rmax);
440 pmax.
set( rmax, rmax);
442 if (std::abs(sinEnd-sinStart) < kCarTolerance &&
443 std::abs(cosEnd-cosStart) < kCarTolerance)
return;
451 G4int icase = (cosEnd < 0) ? 1 : 0;
452 if (sinEnd < 0) icase += 2;
453 if (cosStart < 0) icase += 4;
454 if (sinStart < 0) icase += 8;
460 if (sinEnd < sinStart)
break;
461 pmin.
set(rmin*cosEnd,rmin*sinStart);
462 pmax.
set(rmax*cosStart,rmax*sinEnd );
465 pmin.
set(rmax*cosEnd,
std::min(rmin*sinStart,rmin*sinEnd));
466 pmax.
set(rmax*cosStart,rmax );
469 pmin.
set(-rmax,-rmax);
470 pmax.
set(
std::max(rmax*cosStart,rmax*cosEnd),rmax);
473 pmin.
set(-rmax,rmax*sinEnd);
474 pmax.
set(rmax*cosStart,rmax);
478 pmin.
set(-rmax,-rmax);
479 pmax.
set(rmax,
std::max(rmax*sinStart,rmax*sinEnd));
482 if (sinEnd > sinStart)
break;
483 pmin.
set(rmax*cosEnd,rmin*sinEnd );
484 pmax.
set(rmin*cosStart,rmax*sinStart);
487 pmin.
set(-rmax,-rmax);
488 pmax.
set(rmax*cosEnd,rmax*sinStart);
491 pmin.
set(-rmax,rmax*sinEnd);
492 pmax.
set(
std::max(rmin*cosStart,rmin*cosEnd),rmax*sinStart);
496 pmin.
set(
std::min(rmin*cosStart,rmin*cosEnd),rmax*sinStart);
497 pmax.
set(rmax,rmax*sinEnd);
500 pmin.
set(rmax*cosEnd,rmax*sinStart);
504 if (sinEnd < sinStart)
break;
505 pmin.
set(rmin*cosStart,rmax*sinStart);
506 pmax.
set(rmax*cosEnd,rmin*sinEnd );
509 pmin.
set(-rmax,
std::min(rmax*sinStart,rmax*sinEnd));
514 pmin.
set(rmax*cosStart,-rmax);
515 pmax.
set(rmax,rmax*sinEnd);
518 pmin.
set(
std::min(rmax*cosStart,rmax*cosEnd),-rmax);
522 pmin.
set(rmax*cosStart,-rmax);
523 pmax.
set(rmax*cosEnd,
std::max(rmin*sinStart,rmin*sinEnd));
526 if (sinEnd > sinStart)
break;
527 pmin.
set(rmax*cosStart,rmax*sinEnd);
528 pmax.
set(rmin*cosEnd,rmin*sinStart);
544 G4double e = std::sqrt((1. - b/a)*(1. + b/a));
561 G4double e = std::sqrt((1. - b/a)*(1. + b/a)) / std::hypot(1.,b/h);
581 G4double b = std::sqrt((1. - e)*(1. + e));
583 if (b == 0.)
return 1.;
589 while (x - y > eps*y) {
594 S += M * (x -
y)*(x - y);
607 return ((B-A).cross(C-A))*0.5;
619 return ((C-A).cross(D-B))*0.5;
633 normal += p[i-1].
cross(p[i]);
650 if (u <= 0)
return AP.
mag();
653 if (u >= len2)
return (B-P).mag();
655 return ((u/len2)*AB - AP).mag();
671 if (u <= 0)
return A;
674 if (u >= len2)
return B;
731 region = (t0 < 0) ? ((t1 < 0) ? 4 : 3) : ((t1 < 0) ? 5 : 0);
733 region = (t0 < 0) ? 2 : ((t1 < 0) ? 6 : 1);
740 return A + (t0*invDet)*edge0 + (t1*invDet)*edge1;
745 if (numer <= 0)
return C;
747 return (numer >= denom) ? B : C + (numer/denom)*(edge0-edge1);
757 return (numer >= denom) ? B : C + (numer/denom)*(edge0-edge1);
760 return (tmp1 <= 0) ? C : (( e >= 0) ? A : A + (-e/c)*edge1);
763 return (e >= 0) ? A : ((-e >= c) ? C : A + (-e/c)*edge1);
766 if (d < 0)
return (-d >= a) ? B : A + (-d/
a)*edge0;
767 return (e >= 0) ? A : ((-e >= c) ? C : A + (-e/c)*edge1);
770 return (d >= 0) ? A : ((-d >=
a) ? B : A + (-d/a)*edge0);
780 return (numer >= denom) ? C : B + (numer/denom)*(edge1-edge0);
783 return (tmp1 <= 0) ? B : (( d >= 0) ? A : A + (-d/a)*edge0);
807 if (rmin < 0)
return false;
808 if (rmax <= rmin + kCarTolerance)
return false;
809 if (delTheta <= 0 + kCarTolerance)
return false;
810 if (delPhi <= 0 + kCarTolerance)
return false;
814 if (stheta < 0 && stheta >
CLHEP::pi)
return false;
815 if (stheta + dtheta > CLHEP::pi) dtheta = CLHEP::pi - stheta;
816 if (dtheta <= 0 + kCarTolerance)
return false;
820 pmin.
set(-rmax,-rmax,-rmax);
821 pmax.
set( rmax, rmax, rmax);
822 if (dtheta >= CLHEP::pi && delPhi >=
CLHEP::twopi)
return true;
825 G4double sinStart = std::sin(stheta);
826 G4double cosStart = std::cos(stheta);
837 std::sin(startPhi),std::cos(startPhi),
838 std::sin(startPhi+delPhi),std::cos(startPhi+delPhi),
843 pmin.
set(xymin.
x(),xymin.
y(),zmin);
844 pmax.
set(xymax.
x(),xymax.
y(),zmax);
void set(double x, double y, double z)
T max(const T t1, const T t2)
brief Return the largest of the two arguments
CLHEP::Hep3Vector G4ThreeVector
std::vector< ExP01TrackerHit * > a
static const G4double kInfinity
static double normal(HepRandomEngine *eptr)
double dot(const Hep3Vector &) const
const G4double kCarTolerance
std::vector< G4ThreeVector > G4ThreeVectorList
double A(double temperature)
Hep3Vector cross(const Hep3Vector &) const
G4double G4ParticleHPJENDLHEData::G4double result
static constexpr double twopi
void set(double x, double y)
static G4GeometryTolerance * GetInstance()
static const G4double eps
static constexpr double halfpi
double B(double temperature)
G4double GetSurfaceTolerance() const
static constexpr double pi
T min(const T t1, const T t2)
brief Return the smallest of the two arguments