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 for(
G4int i=0,k=n-1; i<
n; k=i,++i)
88 area += p[k].x()*p[i].y() - p[i].x()*p[k].y();
103 if ((Bx-Ax)*(Cy-Ay) - (By-Ay)*(Cx-Ax) > 0.)
105 if ((Ax-Cx)*(Py-Cy) - (Ay-Cy)*(Px-Cx) < 0.)
return false;
106 if ((Bx-Ax)*(Py-Ay) - (By-Ay)*(Px-Ax) < 0.)
return false;
107 if ((Cx-Bx)*(Py-By) - (Cy-By)*(Px-Bx) < 0.)
return false;
111 if ((Ax-Cx)*(Py-Cy) - (Ay-Cy)*(Px-Cx) > 0.)
return false;
112 if ((Bx-Ax)*(Py-Ay) - (By-Ay)*(Px-Ax) > 0.)
return false;
113 if ((Cx-Bx)*(Py-By) - (Cy-By)*(Px-Bx) > 0.)
return false;
131 if ((Bx-Ax)*(Cy-Ay) - (By-Ay)*(Cx-Ax) > 0.)
133 if ((Ax-Cx)*(Py-Cy) - (Ay-Cy)*(Px-Cx) < 0.)
return false;
134 if ((Bx-Ax)*(Py-Ay) - (By-Ay)*(Px-Ax) < 0.)
return false;
135 if ((Cx-Bx)*(Py-By) - (Cy-By)*(Px-Bx) < 0.)
return false;
139 if ((Ax-Cx)*(Py-Cy) - (Ay-Cy)*(Px-Cx) > 0.)
return false;
140 if ((Bx-Ax)*(Py-Ay) - (By-Ay)*(Px-Ax) > 0.)
return false;
141 if ((Cx-Bx)*(Py-By) - (Cy-By)*(Px-Bx) > 0.)
return false;
155 G4bool gotNegative =
false;
156 G4bool gotPositive =
false;
158 if (n <= 0)
return false;
159 for (
G4int icur=0; icur<
n; ++icur)
161 G4int iprev = (icur == 0) ? n-1 : icur-1;
162 G4int inext = (icur == n-1) ? 0 : icur+1;
166 if (std::abs(cross) < kCarTolerance)
return false;
167 if (cross < 0) gotNegative =
true;
168 if (cross > 0) gotPositive =
true;
169 if (gotNegative && gotPositive)
return false;
182 std::vector<G4int> triangles;
185 G4int n = triangles.size();
186 for (
G4int i=0; i<
n; ++i) result.push_back(polygon[triangles[i]]);
195 std::vector<G4int>&
result)
202 if (n < 3)
return false;
209 for (
G4int i=0; i<
n; ++i) V[i] = i;
211 for (
G4int i=0; i<
n; ++i) V[i] = (n-1)-i;
217 for(
G4int b=nv-1; nv>2; )
223 if (area < 0.) std::reverse(result.begin(),result.end());
228 G4int a = (b < nv) ? b : 0;
229 b = (a+1 < nv) ? a+1 : 0;
230 G4int c = (b+1 < nv) ? b+1 : 0;
232 if (CheckSnip(polygon, a,b,c, nv,V))
235 result.push_back(V[a]);
236 result.push_back(V[b]);
237 result.push_back(V[c]);
241 for(
G4int i=b; i<nv; ++i) V[i] = V[i+1];
247 if (area < 0.) std::reverse(result.begin(),result.end());
264 G4double Ax = contour[V[a]].x(), Ay = contour[V[a]].y();
265 G4double Bx = contour[V[b]].x(), By = contour[V[b]].y();
266 G4double Cx = contour[V[c]].x(), Cy = contour[V[c]].y();
267 if ((Bx-Ax)*(Cy-Ay) - (By-Ay)*(Cx-Ax) < kCarTolerance)
return false;
276 if((i == a) || (i == b) || (i == c))
continue;
278 if (Px < xmin || Px > xmax)
continue;
280 if (Py < ymin || Py > ymax)
continue;
294 std::vector<G4int>& iout,
299 G4double delta = tolerance*tolerance;
303 G4int nv = polygon.size();
308 G4int icur = 0, iprev = 0, inext = 0, nout = 0;
309 for (
G4int i=0; i<nv; ++i)
313 for (
G4int k=1; k<nv+1; ++k)
316 if (iprev < 0) iprev += nv;
317 if (polygon[iprev].x() != removeIt)
break;
320 for (
G4int k=1; k<nv+1; ++k)
323 if (inext >= nv) inext -= nv;
324 if (polygon[inext].x() != removeIt)
break;
327 if (iprev == inext)
break;
339 if (leng1 <= delta || leng2 <= delta || leng3 <= delta)
341 polygon[icur].setX(removeIt); nout++;
346 G4double area = std::abs(e1.
x()*e2.
y()-e1.
y()*e2.
x())*0.5;
347 if (area/std::sqrt(lmax) <= std::abs(tolerance))
349 polygon[icur].setX(removeIt); nout++;
359 for (
G4int i=0; i<nv; ++i) iout.push_back(i);
363 for (
G4int i=0; i<nv; ++i)
365 if (polygon[i].x() != removeIt)
366 polygon[icur++] = polygon[i];
370 if (icur < nv) polygon.resize(icur);
382 static const G4double kCarTolerance =
389 if (rmin < 0)
return false;
390 if (rmax <= rmin + kCarTolerance)
return false;
391 if (delPhi <= 0 + kCarTolerance)
return false;
395 pmin.
set(-rmax,-rmax);
396 pmax.
set( rmax, rmax);
400 std::sin(startPhi),std::cos(startPhi),
401 std::sin(startPhi+delPhi),std::cos(startPhi+delPhi),
416 static const G4double kCarTolerance =
421 pmin.
set(-rmax,-rmax);
422 pmax.
set( rmax, rmax);
424 if (std::abs(sinEnd-sinStart) < kCarTolerance &&
425 std::abs(cosEnd-cosStart) < kCarTolerance)
return;
433 G4int icase = (cosEnd < 0) ? 1 : 0;
434 if (sinEnd < 0) icase += 2;
435 if (cosStart < 0) icase += 4;
436 if (sinStart < 0) icase += 8;
442 if (sinEnd < sinStart)
break;
443 pmin.
set(rmin*cosEnd,rmin*sinStart);
444 pmax.
set(rmax*cosStart,rmax*sinEnd );
447 pmin.
set(rmax*cosEnd,
std::min(rmin*sinStart,rmin*sinEnd));
448 pmax.
set(rmax*cosStart,rmax );
451 pmin.
set(-rmax,-rmax);
452 pmax.
set(
std::max(rmax*cosStart,rmax*cosEnd),rmax);
455 pmin.
set(-rmax,rmax*sinEnd);
456 pmax.
set(rmax*cosStart,rmax);
460 pmin.
set(-rmax,-rmax);
461 pmax.
set(rmax,
std::max(rmax*sinStart,rmax*sinEnd));
464 if (sinEnd > sinStart)
break;
465 pmin.
set(rmax*cosEnd,rmin*sinEnd );
466 pmax.
set(rmin*cosStart,rmax*sinStart);
469 pmin.
set(-rmax,-rmax);
470 pmax.
set(rmax*cosEnd,rmax*sinStart);
473 pmin.
set(-rmax,rmax*sinEnd);
474 pmax.
set(
std::max(rmin*cosStart,rmin*cosEnd),rmax*sinStart);
478 pmin.
set(
std::min(rmin*cosStart,rmin*cosEnd),rmax*sinStart);
479 pmax.
set(rmax,rmax*sinEnd);
482 pmin.
set(rmax*cosEnd,rmax*sinStart);
486 if (sinEnd < sinStart)
break;
487 pmin.
set(rmin*cosStart,rmax*sinStart);
488 pmax.
set(rmax*cosEnd,rmin*sinEnd );
491 pmin.
set(-rmax,
std::min(rmax*sinStart,rmax*sinEnd));
496 pmin.
set(rmax*cosStart,-rmax);
497 pmax.
set(rmax,rmax*sinEnd);
500 pmin.
set(
std::min(rmax*cosStart,rmax*cosEnd),-rmax);
504 pmin.
set(rmax*cosStart,-rmax);
505 pmax.
set(rmax*cosEnd,
std::max(rmin*sinStart,rmin*sinEnd));
508 if (sinEnd > sinStart)
break;
509 pmin.
set(rmax*cosStart,rmax*sinEnd);
510 pmax.
set(rmin*cosEnd,rmin*sinStart);
528 if (u <= 0)
return AP.
mag();
531 if (u >= len2)
return (B-P).mag();
533 return ((u/len2)*AB - AP).mag();
547 static const G4double kCarTolerance =
554 if (rmin < 0)
return false;
555 if (rmax <= rmin + kCarTolerance)
return false;
556 if (delTheta <= 0 + kCarTolerance)
return false;
557 if (delPhi <= 0 + kCarTolerance)
return false;
561 if (stheta < 0 && stheta >
CLHEP::pi)
return false;
562 if (stheta + dtheta > CLHEP::pi) dtheta = CLHEP::pi - stheta;
563 if (dtheta <= 0 + kCarTolerance)
return false;
567 pmin.
set(-rmax,-rmax,-rmax);
568 pmax.
set( rmax, rmax, rmax);
569 if (dtheta >= CLHEP::pi && delPhi >=
CLHEP::twopi)
return true;
572 G4double sinStart = std::sin(stheta);
573 G4double cosStart = std::cos(stheta);
584 std::sin(startPhi),std::cos(startPhi),
585 std::sin(startPhi+delPhi),std::cos(startPhi+delPhi),
590 pmin.
set(xymin.
x(),xymin.
y(),zmin);
591 pmax.
set(xymax.
x(),xymax.
y(),zmax);
G4double G4ParticleHPJENDLHEData::G4double result
void set(double x, double y, double z)
static const G4double kInfinity
double dot(const Hep3Vector &) const
G4double GetSurfaceTolerance() const
double B(double temperature)
double A(double temperature)
void set(double x, double y)
const G4double kCarTolerance
T max(const T t1, const T t2)
brief Return the largest of the two arguments
T min(const T t1, const T t2)
brief Return the smallest of the two arguments
static constexpr double halfpi
static constexpr double twopi
static constexpr double pi
static G4GeometryTolerance * GetInstance()