113#define sqr(t) (t)*(t)
120 template <
class T,
class KeyType>
class SplayTree;
122 typedef std::map<unsigned int, Linebase*>
LineMap;
123 typedef std::priority_queue<Pointbase>
PQueue;
129 typedef std::map<unsigned int, std::set<unsigned int> >
AdjEdgeMap;
273#define Absolute(a) ((a) >= 0.0 ? (a) : -(a))
289#define Fast_Two_Sum_Tail(a, b, x, y) \
293#define Fast_Two_Sum(a, b, x, y) \
294 x = (REAL) (a + b); \
295 Fast_Two_Sum_Tail(a, b, x, y)
297#define Two_Sum_Tail(a, b, x, y) \
298 bvirt = (REAL) (x - a); \
300 bround = b - bvirt; \
301 around = a - avirt; \
304#define Two_Sum(a, b, x, y) \
305 x = (REAL) (a + b); \
306 Two_Sum_Tail(a, b, x, y)
308#define Two_Diff_Tail(a, b, x, y) \
309 bvirt = (REAL) (a - x); \
311 bround = bvirt - b; \
312 around = a - avirt; \
315#define Two_Diff(a, b, x, y) \
316 x = (REAL) (a - b); \
317 Two_Diff_Tail(a, b, x, y)
322#define Split(a, ahi, alo) \
323 c = (REAL) (1.0 * a); \
324 abig = (REAL) (c - a); \
328#define Two_Product_Tail(a, b, x, y) \
329 Split(a, ahi, alo); \
330 Split(b, bhi, blo); \
331 err1 = x - (ahi * bhi); \
332 err2 = err1 - (alo * bhi); \
333 err3 = err2 - (ahi * blo); \
334 y = (alo * blo) - err3
336#define Two_Product(a, b, x, y) \
337 x = (REAL) (a * b); \
338 Two_Product_Tail(a, b, x, y)
343#define Two_One_Diff(a1, a0, b, x2, x1, x0) \
344 Two_Diff(a0, b , x_i, x0); \
345 Two_Sum( a1, x_i, x2, x1)
347#define Two_Two_Diff(a1, a0, b1, b0, x3, x2, x1, x0) \
348 Two_One_Diff(a1, a0, b0, x_j, x_0, x0); \
349 Two_One_Diff(x_j, x_0, b1, x3, x2, x1)
382 REAL avirt, bround, around;
383 int eindex, findex, hindex;
389 if ((fnow > enow) == (fnow > -enow)) {
397 if ((eindex < elen) && (findex < flen)) {
398 if ((fnow > enow) == (fnow > -enow)) {
409 while ((eindex < elen) && (findex < flen)) {
410 if ((fnow > enow) == (fnow > -enow)) {
423 while (eindex < elen) {
431 while (findex < flen) {
439 if ((Q != 0.0) || (hindex == 0)) {
460 for (eindex = 1; eindex < elen; ++eindex) {
495 REAL acxtail, acytail, bcxtail, bcytail;
497 REAL detlefttail, detrighttail;
499 REAL B[4], C1[8], C2[12], D[16];
501 int C1length, C2length, Dlength;
508 REAL avirt, bround, around;
511 REAL ahi, alo, bhi, blo;
512 REAL err1, err2, err3;
516 acx = (
REAL) (pa[0] - pc[0]);
517 bcx = (
REAL) (pb[0] - pc[0]);
518 acy = (
REAL) (pa[1] - pc[1]);
519 bcy = (
REAL) (pb[1] - pc[1]);
524 Two_Two_Diff(detleft, detlefttail, detright, detrighttail,
525 B3, B[2], B[1], B[0]);
531 if ((det >= errbound) || (-det >= errbound)) {
540 if ((acxtail == 0.0) && (acytail == 0.0)
541 && (bcxtail == 0.0) && (bcytail == 0.0)) {
547 det += (acx * bcytail + bcy * acxtail)
548 - (acy * bcxtail + bcx * acytail);
549 if ((det >= errbound) || (-det >= errbound)) {
571 return(D[Dlength - 1]);
576 REAL detleft, detright, det;
577 REAL detsum, errbound;
579 detleft = (pa[0] - pc[0]) * (pb[1] - pc[1]);
580 detright = (pa[1] - pc[1]) * (pb[0] - pc[0]);
581 det = detleft - detright;
584 if (detright <= 0.0) {
587 detsum = detleft + detright;
589 }
else if (detleft < 0.0) {
590 if (detright >= 0.0) {
593 detsum = -detleft - detright;
601 if ((det >= errbound) || (-det >= errbound)) {
634 template <
class T,
class KeyType>
637 template <
class T,
class KeyType>
662 template <
class T,
class KeyType>
731 template <
class T,
class KeyType>
740 template <
class T,
class KeyType>
749 template <
class T,
class KeyType>
763 KeyType keys=
x->keyValue();
765 KeyType rootk=
m_root->keyValue();
774 else if( keys > rootk )
788 x->increaseKeyValue(1.0e-10);
798 template <
class T,
class KeyType>
804 if(
m_root->keyValue() != keys ) {
res=NULL;
return; }
808 if(
m_root->m_left == NULL )
809 newTree =
m_root->m_right;
815 splay( keys, newTree );
816 newTree->m_right =
m_root->m_right;
826 template <
class T,
class KeyType>
832 KeyType rootk=
m_root->keyValue();
833 if( rootk != keys ) {
return; }
841 splay( keys, newTree );
842 newTree->m_right =
m_root->m_right;
855 template <
class T,
class KeyType>
870 splay( keys, newTree );
871 newTree->m_right =
m_root->m_right;
882 template <
class T,
class KeyType>
897 splay( keys, newTree );
898 newTree->m_right =
m_root->m_right;
908 template <
class T,
class KeyType>
914 while( ptr->m_left != NULL ) ptr = ptr->m_left;
922 template <
class T,
class KeyType>
928 while( ptr->m_right != NULL ) ptr = ptr->m_right;
937 template <
class T,
class KeyType>
942 if(
m_root->keyValue() != keys ) {
res=NULL;
return; }
951 template <
class T,
class KeyType>
972 template <
class T,
class KeyType>
986 template <
class T,
class KeyType>
995 template <
class T,
class KeyType>
1013 template <
class T,
class KeyType>
1021 leftTreeMax = rightTreeMin = &
header;
1025 KeyType rkey=t->keyValue();
1028 if(t->m_left == NULL)
break;
1030 if( t->m_left == NULL )
break;
1033 rightTreeMin->
m_left = t;
1037 else if( keys > rkey )
1039 if( t->m_right == NULL )
break;
1041 if( t->m_right == NULL )
break;
1051 leftTreeMax->
m_right = t->m_left;
1052 rightTreeMin->
m_left = t->m_right;
1053 t->m_left =
header.m_right;
1054 t->m_right =
header.m_left;
1061 template <
class T,
class KeyType>
1073 template <
class T,
class KeyType>
1086 template <
class T,
class KeyType>
1089 if( t != t->m_left )
1101 template <
class T,
class KeyType>
1104 if( t == t->m_left )
1113 template<
class T,
class KeyType>
1128 template<
class T,
class KeyType>
1143 template<
class T,
class KeyType>
1160 template<
class T,
class KeyType>
1174 template<
class T,
class KeyType>
1177 if(subtree==NULL)
return 0;
1181 return (lh>rh)?(++lh):(++rh);
1221 Pointbase(
const int& idd,
const double& xx,
const double& yy)
1227 Pointbase(
const int& idd,
const double& xx,
const double& yy,
const Type& ttype)
1307 extern double orient2d(
double* pa,
double* pb,
double* pc);
1322 return sqr(pa[0]-pb[0])+
sqr(pa[1]-pb[1]);
1327 node->data()->setKeyValue(
y);
1347 return (pa.
x==pb.x && pa.
y==pb.y);
1353 return( (pa.
y > pb.y) || ( (pa.
y==pb.y) && (pa.
x < pb.x)) );
1359 return( (pa.
y < pb.y) || ( (pa.
y==pb.y) && (pa.
x > pb.x)) );
1365 return !(pa.
x==pb.x && pa.
y==pb.y);
1373 for(
int i=0; i<2; ++i)
m_endp[i]=0;
1392 this->
m_id=line.m_id;
1393 this->
m_endp[0]=line.m_endp[0];
1394 this->
m_endp[1]=line.m_endp[1];
1395 this->
m_key=line.m_key;
1396 this->
m_type=line.m_type;
1425 Polygon(
const std::vector<double>&
x,
const std::vector<double>&
y);
1443 void set_contour (
const std::vector<double>&
x,
const std::vector<double>&
y);
1447 unsigned int prev(
const unsigned int& i);
1448 unsigned int next(
const unsigned int& i);
1459 void addDiagonal(
const unsigned int& i,
const unsigned int& j);
1463 double angleCosb(
double *
A,
double *B,
double *
C);
1526 assert(
x.size()==
y.size());
1529 unsigned int i =
m_points.size()+1;
1560 m_xmin =
m_ymin = std::numeric_limits<double>::infinity();
1561 m_xmax =
m_ymax = - std::numeric_limits<double>::infinity();
1575 internal_poltrig::PointbaseMap::iterator itp=
m_points.begin();
1581 internal_poltrig::LineMap::iterator itl=
m_edges.begin();
1582 for(; itl!=
m_edges.end(); ++itl)
1594 unsigned int j(0),prevLoop(0),currentLoop(0);
1598 prevLoop=currentLoop;
1613 unsigned int j(0),prevLoop(0),currentLoop(0);
1617 prevLoop=currentLoop;
1624 if( currentLoop==0) j=1;
1640 internal_poltrig::PointbaseMap::iterator it=
m_points.begin();
1648 if( p > pnext && pprev > p )
1650 else if (p > pprev && pnext > p)
1654 double pa[2], pb[2], pc[2];
1717 unsigned int previ=
prev(i);
1719 unsigned int helper=
m_edges[previ]->helper();
1739 unsigned int helper=leftedge->
helper();
1756 unsigned int previ=
prev(i);
1757 unsigned int helper=
m_edges[previ]->helper();
1765 helper=leftedge->
helper();
1779 unsigned int previ=
prev(i);
1780 unsigned int helper=
m_edges[previ]->helper();
1803 unsigned int helper=leftedge->
helper();
1817 std::cout<<
"Please check your input polygon:\n1)orientations?\n2)duplicated points?\n";
1825 unsigned int id=vertex.id;
1836 std::cout<<
"No duplicated points please!\n";
1852 double dxab = pa[0] - pb[0];
1853 double dyab = pa[1] - pb[1];
1855 double dxcb = pc[0] - pb[0];
1856 double dycb = pc[1] - pb[1];
1858 double dxab2 = dxab * dxab;
1859 double dyab2 = dyab * dyab;
1860 double dxcb2 = dxcb * dxcb;
1861 double dycb2 = dycb * dycb;
1862 double ab = dxab2 + dyab2;
1863 double cb = dxcb2 + dycb2;
1865 double cosb = dxab * dxcb + dyab * dycb;
1866 double denom = sqrt( ab * cb);
1882 assert(!
edges.empty());
1884 unsigned int nexte=0;
1885 if(
edges.size() == 1 ) nexte=*(
edges.begin());
1886 else if(
edges.size() > 1 )
1888 unsigned int nexte_ccw(0), nexte_cw(0);
1892 std::set<unsigned int>::iterator it=
edges.begin();
1893 for(; it!=
edges.end(); ++it)
1895 if(*it==edge->
id())
continue;
1896 double A[2], B[2],
C[2];
1906 if(
area > 0 &&
max < cosb ) { nexte_ccw=*it;
max=cosb; }
1907 else if(
min > cosb ) { nexte_cw=*it;
min=cosb; }
1910 nexte = (nexte_ccw!=0) ? nexte_ccw : nexte_cw;
1926 internal_poltrig::LineMap::iterator it=
edges.begin();
1931 poly.push_back(startp->
id);
1935 endp=
next->endPoint(1);
1941 if(endp==startp)
break;
1942 poly.push_back(endp->
id);
1948 std::cout<<
"Please check your input polygon:\n";
1949 std::cout<<
"1)orientations?\n2)with duplicated points?\n3)is a simple one?\n";
1954 if(
next->endPoint(0) !=endp )
next->reverse();
1957 m_mpolys.push_back(std::move(poly));
1968 internal_poltrig::Monopoly::iterator it=mpoly.begin(), itnext;
1969 for(; itnext=it, it!=mpoly.end(); ++it)
1972 if(itnext==mpoly.end()) itnext=mpoly.begin();
1974 point.
left=(point > pointnext)?
true:
false;
1975 qvertex.push(point);
1978 std::stack<internal_poltrig::Pointbase> spoint;
1979 for(
int i=0; i<2; ++i) { spoint.push(qvertex.top()); qvertex.pop(); }
1981 while ( qvertex.size() > 1 )
1986 if(topQueuePoint.
left!=topStackPoint.
left)
1988 while ( spoint.size() > 1 )
1994 v[0]=topQueuePoint.
id;
1997 sort(v.begin(),v.end());
2002 spoint.push(topStackPoint);
2003 spoint.push(topQueuePoint);
2007 while( spoint.size() > 1 )
2012 spoint.push(stack1Point);
2013 double pa[2], pb[2], pc[2];
2014 pa[0]=topQueuePoint.
x; pa[1]=topQueuePoint.
y;
2015 pb[0]=stack2Point.
x; pb[1]=stack2Point.
y;
2016 pc[0]=stack1Point.
x; pc[1]=stack1Point.
y;
2019 bool left=stack1Point.
left;
2020 if( (
area > 0 && left) || (
area < 0 && !left ) )
2023 v[0]=topQueuePoint.
id;
2024 v[1]=stack2Point.
id;
2025 v[2]=stack1Point.
id;
2026 sort(v.begin(),v.end());
2032 spoint.push(topQueuePoint);
2041 while( spoint.size() !=1 )
2048 v[0]=lastQueuePoint.
id;
2051 sort(v.begin(),v.end());
2063 internal_poltrig::Monopolys::iterator it=
m_mpolys.begin();
2076 const std::vector<double>& polygon_ycoords)
std::pair< std::vector< unsigned int >, bool > res
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
#define Two_Product(a, b, x, y)
#define Two_Diff_Tail(a, b, x, y)
#define Two_Sum(a, b, x, y)
#define Two_Two_Diff(a1, a0, b1, b0, x3, x2, x1, x0)
#define Fast_Two_Sum(a, b, x, y)
void diff(const Jet &rJet1, const Jet &rJet2, std::map< std::string, double > varDiff)
Difference between jets - Non-Class function required by trigger.
Header file for AthHistogramAlgorithm.
internal_poltrig::LineMap & edges()
std::vector< unsigned int > m_nVertices
void init_vertices_and_lines()
void handleEndVertex(const unsigned int &)
void handleRegularVertexUp(const unsigned int &)
void set_contour(const std::vector< double > &x, const std::vector< double > &y)
unsigned int prev(const unsigned int &i)
void handleSplitVertex(const unsigned int &)
internal_poltrig::PointbaseMap m_points
void partition2Monotone()
void handleStartVertex(const unsigned int &)
internal_poltrig::Monopolys m_mpolys
void addDiagonal(const unsigned int &i, const unsigned int &j)
internal_poltrig::LineMap m_diagonals
internal_poltrig::AdjEdgeMap m_startAdjEdgeMap
const Triangles * triangles()
internal_poltrig::PQueue m_qpoints
internal_poltrig::LineMap m_edges
void handleRegularVertexDown(const unsigned int &)
Polygon(const std::vector< double > &x, const std::vector< double > &y)
unsigned int selectNextEdge(internal_poltrig::Linebase *edge)
unsigned int next(const unsigned int &i)
internal_poltrig::EdgeBST m_edgebst
void triangulateMonotone(internal_poltrig::Monopoly &mpoly)
void handleMergeVertex(const unsigned int &)
double angleCosb(double *A, double *B, double *C)
internal_poltrig::PointbaseMap & points()
const Triangles * triangles() const
PolygonTriangulator(const std::vector< double > &polygon_xcoords, const std::vector< double > &polygon_ycoords)
std::list< Triangle > Triangles
std::vector< unsigned > Triangle
BTreeNode(const T &data, BTreeNode *lt, BTreeNode *rt)
void SetVisited(const bool &visited)
Pointbase * endPoint(const int &i) const
void setHelper(const unsigned int &i)
void increaseKeyValue(const double &diff)
void setKeyValue(const double &y)
Linebase & operator=(const Linebase &)=delete
Pointbase(const int &idd, const double &xx, const double &yy, const Type &ttype)
friend bool operator==(const Pointbase &, const Pointbase &)
Pointbase(const int &idd, const double &xx, const double &yy)
friend bool operator<(const Pointbase &, const Pointbase &)
friend bool operator>(const Pointbase &, const Pointbase &)
Pointbase(const double &xx, const double &yy, const Type &ttype)
Pointbase & operator=(const Pointbase &)=default
Pointbase(const double &xx, const double &yy)
friend bool operator!=(const Pointbase &, const Pointbase &)
void Delete(const KeyType &keys)
void InOrder(void(*Visit)(BTreeNode< T, KeyType > *u))
BTreeNode< T, KeyType > * clone(BTreeNode< T, KeyType > *t) const
void Find(const KeyType &keys, BTreeNode< T, KeyType > *&res)
void splay(const KeyType &keys, BTreeNode< T, KeyType > *&t) const
void DeleteMax(BTreeNode< T, KeyType > *&max)
void PreOrder(void(*Visit)(BTreeNode< T, KeyType > *u), BTreeNode< T, KeyType > *t)
SplayTree(const SplayTree &rhs)
void DeleteMin(BTreeNode< T, KeyType > *&min)
void InOrder(void(*Visit)(BTreeNode< T, KeyType > *u), BTreeNode< T, KeyType > *t)
BTreeNode< T, KeyType > * Root()
void Delete(const KeyType &keys, BTreeNode< T, KeyType > *&res)
void FindMin(BTreeNode< T, KeyType > *&min)
void InOrder(void(*Visit)(BTreeNode< T, KeyType > *u, double y), double y)
void PostOrder(void(*Visit)(BTreeNode< T, KeyType > *u), BTreeNode< T, KeyType > *t)
void rotateWithRightChild(BTreeNode< T, KeyType > *&k1) const
void reclaimMemory(BTreeNode< T, KeyType > *t) const
void FindMax(BTreeNode< T, KeyType > *&max)
void PostOrder(void(*Visit)(BTreeNode< T, KeyType > *u))
int Height(BTreeNode< T, KeyType > *t) const
const SplayTree & operator=(const SplayTree &rhs)
BTreeNode< T, KeyType > * Right(BTreeNode< T, KeyType > *node)
void rotateWithLeftChild(BTreeNode< T, KeyType > *&k2) const
BTreeNode< T, KeyType > * Left(BTreeNode< T, KeyType > *node)
void InOrder(void(*Visit)(BTreeNode< T, KeyType > *, double y), BTreeNode< T, KeyType > *t, double y)
BTreeNode< Linebase *, double > * m_root
void PreOrder(void(*Visit)(BTreeNode< T, KeyType > *u))
void FindMaxSmallerThan(const KeyType &keys, BTreeNode< T, KeyType > *&res)
std::vector< unsigned int > Triangle
bool operator<(const Pointbase &pa, const Pointbase &pb)
std::map< unsigned int, Pointbase * > PointbaseMap
std::map< unsigned int, Linebase * > LineMap
REAL orient2dadapt(REAL *pa, REAL *pb, REAL *pc, const REAL &detsum)
int fast_expansion_sum_zeroelim(const int &elen, REAL *e, const int &flen, REAL *f, REAL *h)
void UpdateKey(BTreeNode< Linebase *, double > *node, double y)
bool operator!=(const Pointbase &pa, const Pointbase &pb)
REAL orient2d(REAL *pa, REAL *pb, REAL *pc)
std::list< Monopoly > Monopolys
SplayTree< Linebase *, double > EdgeBST
std::list< Triangle > Triangles
std::list< unsigned int > Monopoly
bool operator>(const Pointbase &pa, const Pointbase &pb)
bool operator==(const Pointbase &pa, const Pointbase &pb)
REAL estimate(const int &elen, REAL *e)
std::priority_queue< Pointbase > PQueue
std::map< unsigned int, std::set< unsigned int > > AdjEdgeMap
double dist_sqr(const Pointbase &sp, const Pointbase &ep)
hold the test vectors and ease the comparison