示例#1
0
  virtual bool insert_cell(const Cell& cell,
			   const std::string& mode,
			   const std::string& separator) {
    bool bold = false;
    int rr = 0, gg = 0, bb = 0;
    if (mode=="+++") {
      rr = HALF_COLOR;
      gg = FULL_COLOR;
      bb = HALF_COLOR;
      bold = true;
    } else if (mode=="---") {
      rr = FULL_COLOR;
      gg = HALF_COLOR;
      bb = HALF_COLOR;
    } else if (mode=="->") {
      rr = HALF_COLOR;
      gg = HALF_COLOR;
      bb = FULL_COLOR;
      bold = true;
    }
    if (rr!=0||gg!=0||bb!=0) {
      Poly<Appearance> appear = sheet.getCellAppearance(x,y);
      if (appear.isValid()) {
	appear->begin();
	appear->setBackgroundRgb16(rr,gg,bb,
				   AppearanceRange::full());
	if (bold) {
	  appear->setWeightBold(true,AppearanceRange::full());
	}
	appear->end();
      }
    }
    x++;
    return true;
  }
示例#2
0
void simplePolygon( Poly &p ){
	Point c = centerMass( p ) ;
	for( int i = 0; i < p.size(); i++){
		p[i].ang = atan2( c.x - p[i].x , c.y - p[i].y );
	}
	sort( p.begin(), p.end() );
}
示例#3
0
ReducerPack<Q>::MultipleWithPos::MultipleWithPos(
  const Poly& poly,
  NewConstTerm multipleParam
):
  pos(poly.begin()),
  end(poly.end()),
  current(poly.ring().allocMonomial())
{
  multiple.mono = poly.ring().monoid().alloc().release();
  poly.ring().monoid().copy(*multipleParam.mono, *multiple.mono);
  multiple.coef = multipleParam.coef;
}
示例#4
0
void ReducerHash<Q>::insert(ConstMonoRef multiplier, const Poly& f) {
  mNodesTmp.clear();
  const auto end = f.end();
  for (auto it = f.begin(); it != end; ++it) {
    auto p = mHashTable.insertProduct
      (it.getMonomial(), multiplier, it.getCoefficient());
    if (p.second)
      mNodesTmp.emplace_back(p.first);
  }
  if (!mNodesTmp.empty())
    mQueue.push(mNodesTmp.begin(), mNodesTmp.end());
}
示例#5
0
void ReducerNoDedup<Q>::insert(ConstMonoRef multiple, const Poly& poly) {
  if (poly.isZero())
    return;
  mLeadTermKnown = false;

  const auto end = poly.end();
  for (auto it = poly.begin(); it != end; ++it) {
    NewTerm t = {it.coef(), mRing.monoid().alloc().release()};
    mRing.monoid().multiply(multiple, it.mono(), *t.mono);
    mQueue.push(t);
  }
}
示例#6
0
void ReducerHash<Q>::insertTail(NewConstTerm multiplier, const Poly& f) {
  if (f.nTerms() <= 1)
    return;

  mNodesTmp.clear();
  auto it = f.begin();
  const auto end = f.end();
  for (++it; it != end; ++it) {
    auto p = mHashTable.insertProduct(it.term(), multiplier);
    if (p.second)
      mNodesTmp.emplace_back(p.first);
  }
  if (!mNodesTmp.empty())
    mQueue.push(mNodesTmp.begin(), mNodesTmp.end());
}
示例#7
0
void ReducerNoDedup<Q>::insertTail(NewConstTerm multiple, const Poly& poly) {
  if (poly.termCount() <= 1)
    return;
  mLeadTermKnown = false;

  auto it = poly.begin();
  const auto end = poly.end();
  for (++it; it != end; ++it) {
    NewTerm t;
    t.mono = mRing.allocMonomial();
    mRing.monoid().multiply(*multiple.mono, it.mono(), *t.mono);
    mRing.coefficientMult(multiple.coef, it.coef(), t.coef);
    mQueue.push(t);
  }
}
示例#8
0
Poly convexHull( Poly p ){
	sort( p.begin(), p.end() );
	int n = p.size(), k = 0;
	Poly h ( 2 * n );
	for( int i = 0; i < n; i++ ){
		while( k >= 2 && ccw( h[k-2], h[k-1], p[i] ) <= 0 ) k--;
		h[k++] = p[i];
	}
	int t = k + 1;
	for( int i = n - 2; i >= 0; i-- ){
		while( k >= t && ccw( h[k-2], h[k-1], p[i] ) <= 0 ) k--;
		h[k++] = p[i];
	}
	h.resize( k - 1 );
	return h;
	
}
示例#9
0
Poly convexHull( Poly p ){
	sort( p.begin(), p.end() );
	int n = p.size(), k = 0;
	Poly h ( 2 * n );
	for( int i = 0; i < n; i++ ){
		while( k >= 2 && ccw( h[k-2], h[k-1], p[i] ) <= 0 ) k--;
		h[k++] = p[i];
	}
	int t = k + 1;
	for( int i = n - 2; i >= 0; i-- ){
		while( k >= t && ccw( h[k-2], h[k-1], p[i] ) <= 0 ) k--;
		h[k++] = p[i];
	}
	// devuelve el primero y el ultimo punto iguales, por eso se le resta 1
	h.resize( k - 1 );
	return h;
	
}
示例#10
0
int lining( Poly p ){
	int n = p.size(), res = 2;
	sort( p.begin(), p.end(), sort_y);
	for( int i = 0; i < n; i++){
		double pd[ n ];
		int k = 0;
		for( int j = i + 1 ; j < n; j++ ){
			pd[ k++ ] = slope( p[j], p[i] );
		}
		sort( pd, pd + k );
		int tmp = 2;
		for( int j = 1; j < k; j++){
			if ( fabs( pd[j] - pd[j-1] ) <= EPS ) tmp++;
			else tmp = 2;
			res = max( tmp , res );
		}
	}
	return res ;
}
示例#11
0
文件: math.hpp 项目: go4and/lib
bool contains(const Poly & poly, const Point & p)
{
    bool result = false;
    const auto * prev = &poly.back();
    for(auto i = poly.begin(), end = poly.end(); i != end; ++i)
    {
        const auto * cur = &*i;
        if(cur->y > prev->y)
        {
            auto dy = cur->y - prev->y;
            if(p.y >= prev->y && p.y < cur->y &&
               (p.x - prev->x) * dy <= (p.y - prev->y) * (cur->x - prev->x))
               result = !result;
        } else {
            auto dy = cur->y - prev->y;
            if(p.y < prev->y && p.y >= cur->y &&
               (p.x - prev->x) * dy >= (p.y - prev->y) * (cur->x - prev->x))
               result = !result;
        }
        prev = cur;
    }
    return result;
}
示例#12
0
  virtual bool begin_row(const std::string& mode) {
    row_mode = mode;
    bool bold = false;
    int rr = 0, gg = 0, bb = 0;
    if (row_mode=="+++") {
      rr = HALF_COLOR;
      gg = FULL_COLOR;
      bb = HALF_COLOR;
      bold = true;
    } else if (row_mode=="---") {
      rr = FULL_COLOR;
      gg = HALF_COLOR;
      bb = HALF_COLOR;
    } else if (row_mode=="!") {
      rr = HALF_COLOR;
      gg = HALF_COLOR;
      bb = HALF_COLOR;
    } else if (row_mode=="@@") {
      rr = HALF_COLOR;
      gg = FULL_COLOR;
      bb = FULL_COLOR;
      bold = true;
    }
    if (rr!=0||gg!=0||bb!=0) {
      Poly<Appearance> appear = sheet.getRowAppearance(y);
      if (appear.isValid()) {
	appear->begin();
	appear->setBackgroundRgb16(rr,gg,bb,
				   AppearanceRange::full());
	if (bold) {
	  appear->setWeightBold(true,AppearanceRange::full());
	}
	appear->end();
      }
    }
    return true;
  }
示例#13
0
TournamentReducer::MultipleWithPos::MultipleWithPos
(const Poly& poly, const_term multiple):
  pos(poly.begin()),
  end(poly.end()),
  multiple(allocTerm(poly.ring(), multiple)),
  current(poly.ring().allocMonomial()) {}
示例#14
0
int main(){

	int runs;
	scanf("%d",&runs);
	while( runs--){
		int n;
		scanf("%d",&n);
		int R[ n + 1 ];
		Poly p;
		for( int i = 0; i < n; i++){
			int x , y;
			scanf("%d %d",&x,&y);
			p.push_back( Point( x, y ) );
		}
		sort( p.begin(), p.end() );
		for( int i = 0; i < n ; i++ ) {
			p[i].id = i ;
			R[i] = i + 1;
		}
		
		int sig[ n + 1 ];
		int id = 0;
		for( int i = 0; i < n; i++){
			int id = i + 1;
			bool cagao = false;
			for( int j = i + 1; j < n; j++){
				if ( p[i].y < p[j].y ) cagao = true;
				if ( p[j].y > p[id].y ) id = j;
			}
			if ( !cagao ) {
				sig[i] = id;
			}else{
				sig[i] = -1;
			}
		}
		Poly h;
		for( int i = 0; i < n; i++){
			if ( sig[i] != -1 ){
				for( int pos = i ; pos != n; pos = sig[pos] ){
					h.push_back( p[pos] );
				}
				break;
			}
		}
		int s = 0;
		if ( h[0].y < h[1].y) s++;
		double res = 0.0;
		for( int i = s; i < h.size()-1 ; i++){
			// a = h[i], b = h[i+1], c es la interseccion de la recta a,R[a].id
			// con el vector b(b.x+5, b.y)
			Recta ac ( h[i+1], Point( h[i+1].x+5, h[i+1].y ));
			Recta cb ( h[i], p[ R[ h[i].id ] ] );
			bool paralelas = false;
			Point c = ac.intersect( cb ,paralelas );
			res += dist( h[i], c );
		}
		printf("%.2lf\n", res );
		
	}

	return 0;
}