コード例 #1
0
ファイル: dataflow_model.cpp プロジェクト: fpeder/stream-lang
void model::compute_schedule()
{
    //using namespace isl;

    assert(!m_actors.empty());
    assert(!m_channels.empty());

    isl::context isl_ctx;
    isl::printer isl_printer(isl_ctx);

    int rows = m_channels.size();
    int cols = m_actors.size();

    isl::matrix flow_matrix(isl_ctx, rows, cols);

    for (int r = 0; r < rows; ++r)
        for(int c = 0; c < cols; ++c)
            flow_matrix(r,c) = 0;

    int row = 0;
    for (const auto & chan: m_channels)
    {
        flow_matrix(row, chan.source->id) = chan.push;
        flow_matrix(row, chan.sink->id) = - chan.pop;
        ++row;
    }

    if (debug::is_enabled())
    {
        cout << "Flow:" << endl;
        isl::print(flow_matrix);
    }

    isl::matrix steady_counts = flow_matrix.nullspace();

    if (debug::is_enabled())
    {
        cout << "Steady Counts:" << endl;
        isl::print(steady_counts);
    }

    // Initialization counts:

    // Number of tokens produced should be at least number of tokens consumed
    // after the initial epoch + one steady period.

    isl::space statement_space(isl_ctx, isl::set_tuple(m_actors.size()));
    auto init_counts = isl::set::universe(statement_space);
    auto init_cost = isl::expression::value(statement_space, 0);
    for (int i = 0; i < m_actors.size(); ++i)
    {
        auto stmt = isl::expression::variable(statement_space, isl::space::variable, i);
        init_counts.add_constraint( stmt >= 0 );
        init_cost = stmt + init_cost;
    }
    for (const auto & chan: m_channels)
    {
        auto source = isl::expression::variable(statement_space,
                                                isl::space::variable,
                                                chan.source->id);
        auto sink = isl::expression::variable(statement_space,
                                              isl::space::variable,
                                              chan.sink->id);
        int source_steady = steady_counts(chan.source->id,0).value().numerator();
        int sink_steady = steady_counts(chan.sink->id,0).value().numerator();

        // p(a)*i(a) - o(b)*i(b) + [p(a)*s(a) - o(b)*s(b) - e(b) + o(b)] >= 0

        auto constraint =
                chan.push * source - chan.pop * sink
                + (chan.push * source_steady - chan.pop * sink_steady - chan.peek + chan.pop)
                >= 0;

        init_counts.add_constraint(constraint);
    }

    if (debug::is_enabled())
    {
        cout << "Viable initialization counts:" << endl;
        isl_printer.print(init_counts); cout << endl;
    }

    auto init_optimum = init_counts.minimum(init_cost);
    init_counts.add_constraint( init_cost == init_optimum );
    auto init_optimum_point = init_counts.single_point();

    if (debug::is_enabled())
    {
        cout << "Initialization Counts:" << endl;
        isl_printer.print(init_optimum_point); cout << endl;
    }

    assert(steady_counts.column_count() == 1);
    assert(steady_counts.row_count() == m_actors.size());

    for (auto & actor_record : m_actors)
    {
        actor & a = actor_record.second;
        a.init_count =
                (int) init_optimum_point(isl::space::variable, a.id).numerator();
        a.steady_count =
                steady_counts(a.id, 0).value().numerator();
    }
}
コード例 #2
0
ファイル: qgsdoublespinbox.cpp プロジェクト: ACorradini/QGIS
void QgsDoubleSpinBox::changed( const double& value )
{
  mClearButton->setVisible( mShowClearButton && isEnabled() && value != minimum() );
}
コード例 #3
0
ファイル: image.cpp プロジェクト: chrisidefix/nurbs
void MatrixImage<T>::drawLine(int i1, int j1, int i2, int j2, T color){
  int i,j ;
  double mx,b ;
  if(i1<0 || j1<0 || i1>this->rows() || j1>=this->cols()  ){
#ifdef USE_EXCEPTION
    throw OutOfBound2D(i1,j1,0,this->rows()-1,0,this->cols()-1) ;
#else
    Error error("MatrixImage<T>::drawLine") ;
    error << "Error in drawing line\n Invalid index ("<< i1 << ", " << j1 << ") to ( " << i2 << ", " << j2 << ") \n" ;
    error.warning() ;
#endif
    return ;
  }
  if(i2 <0 || j2<0 || i2>this->rows() || j2>=this->cols() ){
#ifdef USE_EXCEPTION
    throw OutOfBound2D(i2,j2,0,this->rows()-1,0,this->cols()-1) ;
#else
    Error error("MatrixImage<T>::drawLine") ;
    error << "Error in drawing line\n Invalid index ("<< i1 << ", " << j1 << ") to ( " << i2 << ", " << j2 << ") \n" ;
    error.warning() ;
#endif
    return ;
  }

  // check if line is vertical
  if(j1==j2){
    for(i=minimum(i1,i2);i<=maximum(i1,i2);i++)
     this->operator()(i,j1) = color ;
    return ;
  }
  mx = (double)(i1-i2)/(double)(j1-j2) ;
  b = (double)i1 - mx*j1 ;
  if(absolute(i1-i2)>absolute(j1-j2)){ // draw vertically
    if(i1>i2){
      for(i=i1;i>=i2;i--){
	j = int(((double)i-b)/mx) ;
	this->operator()(i,j) = color ;
      }
    }
    else{
      for(i=i1;i<=i2;i++){
	j = (int)((i-b)/mx) ;
	this->operator()(i,j) = color ;
      }
    }
  }
  else{
    if(j1>j2){
      for(j=j1;j>=j2;j--){
	i = (int)(mx*j+b) ;
	this->operator()(i,j) = color ;
      }
    }
    else{
      for(j=j1;j<=j2;j++){
	i = (int)(mx*j+b) ;
	this->operator()(i,j) = color ;
      }
    }
  }

}
コード例 #4
0
ファイル: CClientUse.cpp プロジェクト: azmanomer/Source
void CClient::Cmd_EditItem( CObjBase * pObj, int iSelect )
{
	ADDTOCALLSTACK("CClient::Cmd_EditItem");
	// ARGS:
	//   iSelect == -1 = setup.
	//   m_Targ_Text = what are we doing to it ?
	//
	if ( pObj == NULL )
		return;

	CContainer * pContainer = dynamic_cast <CContainer *> (pObj);
	if ( pContainer == NULL )
	{
		addGumpDialogProps( pObj->GetUID());
		return;
	}

	if ( iSelect == 0 )
		return;	// cancelled.

	if ( iSelect > 0 )
	{
		// We selected an item.
		if ( static_cast<size_t>(iSelect) >= COUNTOF(m_tmMenu.m_Item))
			return;

		if ( m_Targ_Text.IsEmpty())
		{
			addGumpDialogProps( m_tmMenu.m_Item[static_cast<size_t>(iSelect)] );
		}
		else
		{
			OnTarg_Obj_Set( CGrayUID( m_tmMenu.m_Item[static_cast<size_t>(iSelect)] ).ObjFind() );
		}
		return;
	}
	
	CMenuItem item[ minimum( COUNTOF( m_tmMenu.m_Item ), MAX_MENU_ITEMS ) ];	// Most as we want to display at one time.
	item[0].m_sText.Format( "Contents of %s", static_cast<LPCTSTR>(pObj->GetName()));

	size_t count = 0;
	for ( CItem *pItem = pContainer->GetContentHead(); pItem != NULL; pItem = pItem->GetNext() )
	{
		count++;
		m_tmMenu.m_Item[count] = pItem->GetUID();
		item[count].m_sText = pItem->GetName();
		ITEMID_TYPE idi = pItem->GetDispID();
		item[count].m_id = static_cast<WORD>(idi);
		item[count].m_color = 0;

		if ( !pItem->IsType( IT_EQ_MEMORY_OBJ ) )
		{
			HUE_TYPE wHue = pItem->GetHue();
			if ( wHue != 0 )
			{
				wHue = (wHue == 1? 0x7FF : wHue-1 );
				item[count].m_color = wHue;
			}
		}
		
		if ( count >= (COUNTOF( item ) - 1) )
			break;
	}
	
	ASSERT(count < COUNTOF(item));
	addItemMenu( CLIMODE_MENU_EDIT, item, count, pObj );
}
コード例 #5
0
ファイル: qgsdoublespinbox.cpp プロジェクト: ACorradini/QGIS
void QgsDoubleSpinBox::setShowClearButton( const bool showClearButton )
{
  mShowClearButton = showClearButton;
  mClearButton->setVisible( mShowClearButton && isEnabled() && value() != minimum() );
}
コード例 #6
0
ファイル: range.hpp プロジェクト: ChristophHaag/mesa-mesa
 typename super::size_type
 size() const {
    return tuple::apply(minimum(), tuple::map(sizes(), os));
 }
コード例 #7
0
ファイル: Fl_Osc_Dial.cpp プロジェクト: peter1000/Carla
void Fl_Osc_Dial::OSC_value(char v)
{
    value(v + value() - floorf(value()) +
          minimum());
}
コード例 #8
0
ファイル: fl_gauge.cpp プロジェクト: qartis/dori
void Fl_Gauge::draw(void)
{
    int X = x();
    int Y = y();
    int W = w();
    int H = h();

    draw_box();

    X += Fl::box_dx(box());
    Y += Fl::box_dy(box());
    W -= Fl::box_dw(box());
    H -= Fl::box_dh(box());

    double frac = (value() - minimum()) / (maximum() - minimum());
    double angle = (angle2() - angle1()) * frac +  angle1();

    float cx = X + W/2.0f;
    float cy = Y + H/2.0f;

    float d = (float)((W < H)? W : H);

    double num_major_ticks = (maximum() - minimum()) / major_step_size;
    double num_minor_ticks = (maximum() - minimum()) / minor_step_size;

    double minor_angle = (angle2() - angle1()) / num_minor_ticks;
    double major_angle = (angle2() - angle1()) / num_major_ticks;
    int i;

    fl_color(FL_WHITE);
    fl_line_style(FL_SOLID, 1);

/* minor ticks */
    fl_push_matrix();
    fl_color(FL_WHITE);
    fl_translate(cx, cy);
    fl_scale(d, d);
    fl_rotate(-angle1());
    for (i = 0; i <= num_minor_ticks; i++) {
        fl_begin_line();
        fl_vertex(0, 0.40);
        fl_vertex(0, 0.45);
        fl_end_line();
        fl_rotate(-minor_angle);
    }
    fl_pop_matrix();

/* major ticks */
    fl_push_matrix();
    fl_color(FL_WHITE);
    fl_line_style(FL_SOLID, 3);
    fl_translate(cx, cy);
    fl_scale(d, d);
    fl_rotate(-angle1());
    for (i = 0; i <= num_major_ticks; i++) {
        fl_begin_line();
        fl_vertex(0, 0.40);
        fl_vertex(0, 0.47);
        fl_end_line();
        fl_rotate(-major_angle);
    }
    fl_pop_matrix();

/* tick labels */
    char buf[128];
    fl_color(FL_WHITE);
    for (i = 0; i <= num_major_ticks; i++) {
        snprintf(buf, sizeof(buf), "%.0lf", minimum() + i * major_step_size);
        double angle = 360.0 + -angle1() - 90 - i * major_angle;
        double rad = angle * M_PI/180.0;
        int width = 0;
        int height = 0;
        fl_measure(buf, width, height);
        if (width < 1) {
            width = 9;
        }
        if (height < 1) {
            height = 16;
        }
        double radius = d / 3;
        double x = cx + radius * cos(rad);
        double y = cy - radius * sin(rad);
        if (rad < M_PI/2.0 || rad > 3 * M_PI/2.0) {
            x = cx + (radius - width/2.0) * cos(rad);
        }
        x -= width/2.0;
        fl_draw(buf, x, y + height/2.0);
    }

    fl_push_matrix();
    fl_translate(cx, cy);
    fl_scale(d, d);

    fl_color(FL_WHITE);

    fl_rotate(-angle);

/* arrow */
    fl_begin_polygon();
    fl_vertex(-0.02, 0.03);
    fl_vertex(-0.02, 0.35);
    fl_vertex( 0.00, 0.37);
    fl_vertex( 0.02, 0.35);
    fl_vertex( 0.02, 0.03);
    fl_end_polygon();

/* border */
    fl_begin_loop();
    fl_circle(0.0, 0.0, 0.48);
    fl_end_loop();

    fl_pop_matrix();

    fl_color(FL_GRAY);
    fl_pie(cx - d * 0.05, cy - d * 0.05, d * 0.1, d * 0.1, 0, 360.0);
    fl_color(FL_BLACK);
    fl_pie(cx - d * 0.025, cy - d * 0.025, d * 0.05, d * 0.05, 0, 360.0);

    draw_label();
}
コード例 #9
0
void rangeFinder(double *out, const double *points, const double *origin, const double *R, const double *parameters, const size_t NPOINTS) {

	#define H parameters[0]
	#define RHO parameters[1]
	#define MIN parameters[2]

	/*
	 * ux : componente x versore sensore
	 * uy : componente y versone sensore
	 * u  : distanza lungo l'asse del punto
	 */
	double ux[6], uy[6], *dist, inf;
	int i;
	inf = mxGetInf();
	dist = (double*)calloc(6*NPOINTS,sizeof(double));

	/* definizione dei versori */
	for (i=0; i<6; i++) { 
		ux[i] = cos(i*M_PI/3); 
		uy[i] = -sin(i*M_PI/3); 
	}

	for (i=0; i<NPOINTS; i++) {

		/* 
		 * p_world : distanza tra punto ostacolo e ricevitore nel sistema di riferimento globale
		 * p : distanza tra punto di riferimento e ricevitore nel sistema di riferimento body
		 * pu : proiezione lungo l'asse
		 * pv2 : proiezione perpendicolare all'asse al quadrato
		 */
		double p_world[3], p[3], pu[6], pv2[6], pabs;
		int j;

		difference(p_world,&points[3*i],origin);
		project(p,p_world,R);
		absolute2(&pabs, p);

		#ifdef __DEBUG_1
    		mexPrintf("\nPOINT %d -- P = [ %4f %4f %4f ]\n",i,p[0],p[1],p[2]);
    	#endif
	
		for (j=0; j<6; j++) {
			dotProductXY(&pu[j], p, &ux[j], &uy[j]);
			pv2[j] = pabs - (pu[j]*pu[j]);

			if (pu[j] > MIN && pu[j] <= H) {
				if ( pv2[j] <= pow((RHO * ((H - pu[j])/H)),2)) {
					dist[6*i+j] = pu[j];
				} else {
					dist[6*i+j] = inf;
				}
			} else {
				dist[6*i+j] = inf;
			}
			#ifdef __DEBUG_1
    			mexPrintf("  SENSOR %d -- PU = [ %4f ], PV^2 = [ %4f ]\n",j,pu[0],pv2[1]);
    		#endif
		}
	}

	for (i=0; i<6; i++) {
		double *dd;
		dd = (double*)calloc(1*NPOINTS,sizeof(double));
		#ifdef __DEBUG_1
			mexPrintf("\nSENSOR %d\n",i);
		#endif
		select(dd, dist, NPOINTS, 6, i);
		minimum(&out[i],dd,NPOINTS);
		#ifdef __DEBUG_1
			mexPrintf(" dist = %4f\n",out[i]);
		#endif
		free(dd);
	}
	free(dist);

}
コード例 #10
0
ファイル: mrcf.c プロジェクト: conioh/os-design
USHORT
MrcfReadNBits (
    LONG cbits,
    PMRCF_BIT_IO BitIo
    )

/*++

Routine Description:

    Get next N bits from bit buffer

Arguments:

    cbits - count of bits to get

    BitIo - Supplies a pointer to the bit buffer statics

Return Value:

    USHORT - Returns next cbits bits.

--*/

{
    ULONG abits;        // Bits to return
    LONG cbitsPart;    // Partial count of bits
    ULONG cshift;       // Shift count
    ULONG mask;         // Mask

    //
    //  Largest number of bits we should read at one time is 12 bits for
    //  a 12-bit offset.  The largest length field component that we
    //  read is 8 bits.  If this routine were used for some other purpose,
    //  it can support up to 15 (NOT 16) bit reads, due to how the masking
    //  code works.
    //

    ASSERT(cbits <= 12);

    //
    //  No shift and no bits yet
    //

    cshift = 0;
    abits = 0;

    while (cbits > 0) {

        //
        //  If not bits available get some bits
        //

        if ((BitIo->cbitsBB) == 0) {

            MrcfFillBitBuffer(BitIo);
        }

        //
        //  Number of bits we can read
        //

        cbitsPart = minimum((BitIo->cbitsBB), cbits);

        //
        //  Mask for bits we want, extract and store them
        //

        mask = (1 << cbitsPart) - 1;
        abits |= ((BitIo->abitsBB) & mask) << cshift;

        //
        //  Remember the next chunk of bits
        //

        cshift = cbitsPart;

        //
        //  Update bit buffer, move remaining bits down and
        //  update count of bits left
        //

        (BitIo->abitsBB) >>= cbitsPart;
        (BitIo->cbitsBB) -= cbitsPart;

        //
        //  Update count of bits left to read
        //

        cbits -= cbitsPart;
    }

    //
    //  Return requested bits
    //

    return (USHORT)abits;
}
コード例 #11
0
ファイル: plm_7stud.cpp プロジェクト: dmakk767/pokerspot
void Cplm_7Stud::doRake()
{
    if (lowRake_ == 0 && hiRake_ == 0)
        resetRake(); // set the rake limits

    Cpot* pot = table_->getMainPot();

    bool secondUpCard = false;

    // RULE:
    //      $1 at the second upcard
    if (upCards_ >= 2)
    {   //
        // Take second up card rake
        //
        rake_ = 1;
        secondUpCard = true;
    }

    // RULE:
    //    $1 when the pot reaches certain low limit
    if (secondUpCard && lowRake_ != 0)
    {
        if (pot->getTotalChips() >= lowRake_)
        {   //
            // Take low limit rake
            //
            rake_ += 1;
        }
    }

    // RULE:
    //    $1 when the pot reaches certain higher limit
    if (secondUpCard && hiRake_ != 0)
    {
        if (pot->getTotalChips() >= hiRake_)
        {   //
            // Take hi limit rake
            //
            rake_ += 1;
        }
    }

    // RULE
    //   If there are only 2-3 players playing (that is,
    //   has been dealt cards), the rake is 1 if pot reaches
    //   20, otherwise rake is 0.

    const int NoRakeLimit = 20;

    // Players in these states have been dealt cards
    int state = PLAYER_STATE_PLAYING |
                PLAYER_STATE_FOLDED |
                PLAYER_STATE_ALLIN |
                PLAYER_STATE_ALLIN_RAISE;

    if (table_->countPlayers(state) < 4)
    {
        if (pot->getTotalChips() < NoRakeLimit)
        {
            // NoRakeLimit not reached, no rake
            rake_ = 0;
        }
        else
        {
            // NoRakeLimit reached
            if (secondUpCard)
                rake_ = minimum(CChips(1, 0), rake_);
        }
    }

    saveRake();
}
コード例 #12
0
ファイル: plm_allin.cpp プロジェクト: angeldv95/pokerspot
void Cplm::splitPot(CPlayer* player, const CChips& pay)
{
    int i = 0;
    bool wasSplit = false;

    // If player has 0 chips left need to split pot
    bool splitInAnyCase = (player->getChips() == 0);

    // Take the chips from the player now - 
    // if this is network allin, 'pay' will be
    // smaller - otherwise player's chips should
    // be smaller
    CChips chips = minimum(player->getChips(), pay);
    player->setChips(player->getChips() - chips);

    Cpot* pot = table_->getMainPot();

    // find the pot which will be split (if any),
    // and distribute chips as we go
    while (pot->getNext() != NULL)
    {
        if (pot->isActive())
        {
            // player has to pay the difference between what
            // he has paid so far and the current pot bet
            ASSERT(pot->getBet() >= pot->getPlayerChips(player));
            CChips pay_this_pot = pot->getBet() - pot->getPlayerChips(player);

            if (chips >= pay_this_pot)
            {   //
                // player can match this pot's bet - pay it,
                // make player eligible, and continue to next pot
                //
                pot->addPlayerChips(player, pay_this_pot);
                chips -= pay_this_pot;
                pot->makeEligible(player);
            }
            else
            {
                //
                // player cannot match this pot's bet -
                // if player has chips left, split the pot,
                // and we're done
                // 
                if (splitInAnyCase || chips > 0)
                {
                    // okay split this pot
                    splitPot(pot, player, chips, pay_this_pot);
                    pot->makeEligible(player);
                    chips = 0;
                    wasSplit = true;
                }
                else
                {
                    // player's chips matched evenly, no need to split
                    // any pot
                    wasSplit = true;
                }

                // we're done, exit loop
                break;
            }


            if (DEBUG & DEBUG_PLM)
            {
                printf("%s pays %d chips to side pot %d, chips left: %d\n",
                    player->getUsername(), pay_this_pot, i++, pay);
            }
        }
        pot = pot->getNext();
    }

    if (!wasSplit)
    {
        // Split the last pot 
        ASSERT(pot->isActive()); // last pot must be active
        ASSERT(pot->getBet() >= pot->getPlayerChips(player));
        CChips pay_this_pot = pot->getBet() - pot->getPlayerChips(player);
        splitPot(pot, player, chips, pay_this_pot);
        pot->makeEligible(player);
    }
}
コード例 #13
0
ファイル: Fl_Roller.cpp プロジェクト: GustavoMOG/efltk
void Fl_Roller::draw()
{
    if (damage()&(FL_DAMAGE_ALL|FL_DAMAGE_HIGHLIGHT)) draw_box();
    int X=0; int Y=0; int W=w(); int H=h(); box()->inset(X,Y,W,H);
    if (W<=0 || H<=0) return;

    double s = step();
    if (!s) s = (maximum()-minimum())/100;
    int offset = int(value()/s);

    const double ARC = 1.5;      // 1/2 the number of radians visible
    const double delta = .2;     // radians per knurl
    if (type()==HORIZONTAL)
    {
        // draw shaded ends of wheel:
        int h1 = W/4+1;          // distance from end that shading starts
        fl_color(button_color()); fl_rectf(X+h1,Y,W-2*h1,H);
        for (int i=0; h1; i++)
        {
            fl_color((Fl_Color)(FL_GRAY-i-1));
            int h2 = FL_GRAY-i-1 > FL_DARK3 ? 2*h1/3+1 : 0;
            fl_rectf(X+h2,Y,h1-h2,H);
            fl_rectf(X+W-h1,Y,h1-h2,H);
            h1 = h2;
        }
        if (active_r())
        {
            // draw ridges:
            double junk;
            for (double y = -ARC+modf(offset*sin(ARC)/(W/2)/delta,&junk)*delta;;
                    y += delta)
            {
                int y1 = int((sin(y)/sin(ARC)+1)*W/2);
                if (y1 <= 0) continue; else if (y1 >= W-1) break;
                fl_color(FL_DARK3); fl_line(X+y1,Y+1,X+y1,Y+H-1);
                if (y < 0) y1--; else y1++;
                fl_color(FL_LIGHT1);fl_line(X+y1,Y+1,X+y1,Y+H-1);
            }
            // draw edges:
            h1 = W/8+1;          // distance from end the color inverts
            fl_color(FL_DARK2);
            fl_line(X+h1,Y+H-1,X+W-h1,Y+H-1);
            fl_color(FL_DARK3);
            fl_line(X,Y+H,X,Y);
            fl_line(X,Y,X+h1,Y);
            fl_line(X+W-h1,Y,X+W,Y);
            fl_color(FL_LIGHT2);
            fl_line(X+h1,Y,X+W-h1,Y);
            fl_line(X+W,Y,X+W,Y+H);
            fl_line(X+W,Y+H,X+W-h1,Y+H);
            fl_line(X+h1,Y+H,X,Y+H);
        }
    }                            // vertical one
    else
    {
        offset = (1-offset);
        // draw shaded ends of wheel:
        int h1 = H/4+1;          // distance from end that shading starts
        fl_color(button_color()); fl_rectf(X,Y+h1,W,H-2*h1);
        for (int i=0; h1; i++)
        {
            fl_color((Fl_Color)(FL_GRAY-i-1));
            int h2 = FL_GRAY-i-1 > FL_DARK3 ? 2*h1/3+1 : 0;
            fl_rectf(X,Y+h2,W,h1-h2);
            fl_rectf(X,Y+H-h1,W,h1-h2);
            h1 = h2;
        }
        if (active_r())
        {
            // draw ridges:
            double junk;
            for (double y = -ARC+modf(offset*sin(ARC)/(H/2)/delta,&junk)*delta;
                    ; y += delta)
            {
                int y1 = int((sin(y)/sin(ARC)+1)*H/2);
                if (y1 <= 0) continue; else if (y1 >= H-1) break;
                fl_color(FL_DARK3); fl_line(X+1,Y+y1,X+W-1,Y+y1);
                if (y < 0) y1--; else y1++;
                fl_color(FL_LIGHT1);fl_line(X+1,Y+y1,X+W-1,Y+y1);
            }
            // draw edges:
            h1 = H/8+1;          // distance from end the color inverts
            fl_color(FL_DARK2);
            fl_line(X+W-1,Y+h1,X+W-1,Y+H-h1);
            fl_color(FL_DARK3);
            fl_line(X+W,Y,X,Y);
            fl_line(X,Y,X,Y+h1);
            fl_line(X,Y+H-h1,X,Y+H);
            fl_color(FL_LIGHT2);
            fl_line(X,Y+h1,X,Y+H-h1);
            fl_line(X,Y+H,X+W,Y+H);
            fl_line(X+W,Y+H,X+W,Y+H-h1);
            fl_line(X+W,Y+h1,X+W,Y);
        }
    }
    if (focused())
    {
        focus_box()->draw(0,0,w(),h(), FL_BLACK, FL_INVISIBLE);
    }
}
コード例 #14
0
ファイル: mosp.c プロジェクト: geoffchu/chuffed
	MOSP(int _n, int _m) : n(_n), m(_m) {

		generateInstance();

		createVars(s, n, 0, n-1);
		createVars(e, n, 0, n-1);
		createVars(sb, n, n);
		createVars(eb, n, n);
		createVars(o, n, n);
		createVar(stacks, 0, n);

		// create customer graph
		bool g[n][n];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				g[i][j] = false;
				for (int k = 0; k < m; k++) {
					if (a[i][k] && a[j][k]) {
						g[i][j] = true;
						break;
					}
				}
			}
		}

		// AllDiff constraint on e
		all_different(e);

		// Min constraints on s[i]
		for (int i = 0; i < n; i++) {
			vec<IntVar*> x;
			for (int j = 0; j < n; j++) if (g[i][j]) x.push(e[j]);
			minimum(x, s[i]);
		}

		// open constraints
		for (int i = 0; i < n; i++) {
			for (int t = 0; t < n; t++) {
				int_rel_reif(s[i], IRT_LE, t, sb[i][t]);
				int_rel_reif(e[i], IRT_GE, t, eb[i][t]);
				vec<BoolView> x;
				x.push(sb[i][t]);
				x.push(eb[i][t]);
				array_bool_and(x, o[t][i]);
			}
		}

		// stack constraints
		for (int i = 0; i < n; i++) {
			bool_linear(o[i], IRT_LE, stacks);
		}

		// dominance breaking constraints
		vec<vec<BoolView> > r;
		createVars(r, n, n);

		// Find out which stacks can immediately close
		for (int t = 0; t < n; t++) {
			for (int i = 0; i < n; i++) {
				vec<BoolView> a;
				for (int j = 0; j < n; j++) if (g[i][j]) a.push(sb[j][t]);
				a.push(eb[i][t]);
				array_bool_and(a, r[i][t]);
			}
		}

		// If none of the lex better stacks can instantly close
		// and this one can, close it now
		for (int t = 0; t < n-1; t++) {
			for (int i = 0; i < n; i++) {
				vec<BoolView> a, b;
				for (int j = 0; j < i; j++) a.push(r[j][t]);
				b.push(r[i][t]);
				b.push(eb[i][t+1]);
				bool_clause(a, b);
			}
		}

		// branch on end times
		branch(e, VAR_MIN_MIN, VAL_MIN);

		// set optimization target
		optimize(stacks, OPT_MIN);

	}
コード例 #15
0
ファイル: kruler.cpp プロジェクト: KDE/kwidgetsaddons
int
KRuler::minValue() const
{
    return minimum();
}
void HORN_SCHUNCK_MAIN
(
                         /*****************************************************/
float **f1,              /* in     : 1st image                                */
float **f2,              /* in     : 2nd image                                */
float **u,               /* out    : x-component of displacement field        */
float **v,               /* out    : y-component of displacement field        */
int   nx,                /* in     : size in x-direction                      */
int   ny,                /* in     : size in y-direction                      */
int   bx,                /* in     : boundary size in x-direction             */
int   by,                /* in     : boundary size in y-direction             */
float hx,                /* in     : grid spacing in x-direction              */
float hy,                /* in     : grid spacing in y-direction              */
float m_alpha,           /* in     : smoothness weight                        */
float epsilon_d,         /* in     : diffusivity param data term              */
float epsilon_s,
float w_bright_grad,
int   num_iter_inner,    /* in     : inner solver iterations                  */
int   num_iter_outer,    /* in     : outer nonlin update iterations           */
float n_warp_eta,        /* in     : warping reduction factor between levels  */
float n_omega,
int   n_warp_levels      /* in     : desired number of warping levels         */
                         /*****************************************************/
)

/* computes optic flow with Horn/Schunck + Warping */

{

                        /*****************************************************/
float **du;             /* x-component of flow increment                     */
float **dv;             /* y-component of flow increment                     */
float **f1_res;         /* 1st image, resampled                              */
float **f2_res;         /* 2nd image, resampled                              */
float **f2_res_warp;    /* 2nd image, resampled  and warped                  */
float **tmp;            /* temporary array for resampling                    */
int   max_rec_depth;    /* maximum recursion depth (warping level -1)        */
int   n_warp_max_levels;/* maximum possible number of warping levels         */
                        /*****************************************************/



/* compute maximal number of warping levels given the downsampling factor eta 
   and the image dimensions */
compute_max_warp_levels(nx,ny,n_warp_eta,&n_warp_max_levels);

/* limit number of desired warping levels by number of possible levels  */
/* we have to substract one, since: n warping levels -> n-1 recursions  */
max_rec_depth=minimum(n_warp_levels,n_warp_max_levels)-1;


/* ---- alloc memory ---- */

malloc_multi(6,2,sizeof(float),nx,ny,bx,by,0,0,&du,&dv,&f1_res,&f2_res,
             &f2_res_warp,&tmp);

/* call Horn/Schunck warping routine with desired number of levels */
HORN_SCHUNCK_WARP(f1, f2, nx, ny,
		  f1_res, f2_res, f2_res_warp,
		  du, dv, u, v, tmp,
		  nx, ny, bx, by, hx, hy,
		  m_alpha, epsilon_d, epsilon_s, w_bright_grad,
		  num_iter_inner, num_iter_outer, n_omega, n_warp_eta,
		  max_rec_depth,0);




/* ---- free memory ---- */
free_multi(6,2,sizeof(float),nx,ny,bx,by,0,0,&du,&dv,&f1_res,&f2_res,
           &f2_res_warp,&tmp);


}
コード例 #17
0
ファイル: kruler.cpp プロジェクト: KDE/kwidgetsaddons
void
KRuler::paintEvent(QPaintEvent * /*e*/)
{
    //  debug ("KRuler::drawContents, %s",(horizontal==dir)?"horizontal":"vertical");

    QStylePainter p(this);
#ifdef PROFILING
    QTime time;
    time.start();
    for (int profile = 0; profile < 10; profile++) {
#endif

        int value  = this->value(),
            minval = minimum(),
            maxval;
        if (d->dir == Qt::Horizontal) {
            maxval = maximum()
                     + d->offset
                     - (d->lengthFix ? (height() - d->endOffset_length) : d->endOffset_length);
        } else {
            maxval = maximum()
                     + d->offset
                     - (d->lengthFix ? (width() - d->endOffset_length) : d->endOffset_length);
        }
        //ioffsetval = value-offset;
        //    pixelpm = (int)ppm;
        //    left  = clip.left(),
        //    right = clip.right();
        double f, fend,
               offsetmin = (double)(minval - d->offset),
               offsetmax = (double)(maxval - d->offset),
               fontOffset = (((double)minval) > offsetmin) ? (double)minval : offsetmin;

        // draw labels
        QFont font = p.font();
        font.setPointSize(LABEL_SIZE);
        p.setFont(font);
        // draw littlemarklabel

        // draw mediummarklabel

        // draw bigmarklabel

        // draw endlabel
        if (d->showEndL) {
            if (d->dir == Qt::Horizontal) {
                p.translate(fontOffset, 0);
                p.drawText(END_LABEL_X, END_LABEL_Y, d->endlabel);
            } else { // rotate text +pi/2 and move down a bit
                //QFontMetrics fm(font);
#ifdef KRULER_ROTATE_TEST
                p.rotate(-90.0 + rotate);
                p.translate(-8.0 - fontOffset - d->fontWidth + xtrans,
                            ytrans);
#else
                p.rotate(-90.0);
                p.translate(-8.0 - fontOffset - d->fontWidth, 0.0);
#endif
                p.drawText(END_LABEL_X, END_LABEL_Y, d->endlabel);
            }
            p.resetMatrix();
        }

        // draw the tiny marks
        if (d->showtm) {
            fend = d->ppm * d->tmDist;
            for (f = offsetmin; f < offsetmax; f += fend) {
                if (d->dir == Qt::Horizontal) {
                    p.drawLine((int)f, BASE_MARK_X1, (int)f, BASE_MARK_X2);
                } else {
                    p.drawLine(BASE_MARK_X1, (int)f, BASE_MARK_X2, (int)f);
                }
            }
        }
        if (d->showlm) {
            // draw the little marks
            fend = d->ppm * d->lmDist;
            for (f = offsetmin; f < offsetmax; f += fend) {
                if (d->dir == Qt::Horizontal) {
                    p.drawLine((int)f, LITTLE_MARK_X1, (int)f, LITTLE_MARK_X2);
                } else {
                    p.drawLine(LITTLE_MARK_X1, (int)f, LITTLE_MARK_X2, (int)f);
                }
            }
        }
        if (d->showmm) {
            // draw medium marks
            fend = d->ppm * d->mmDist;
            for (f = offsetmin; f < offsetmax; f += fend) {
                if (d->dir == Qt::Horizontal) {
                    p.drawLine((int)f, MIDDLE_MARK_X1, (int)f, MIDDLE_MARK_X2);
                } else {
                    p.drawLine(MIDDLE_MARK_X1, (int)f, MIDDLE_MARK_X2, (int)f);
                }
            }
        }
        if (d->showbm) {
            // draw big marks
            fend = d->ppm * d->bmDist;
            for (f = offsetmin; f < offsetmax; f += fend) {
                if (d->dir == Qt::Horizontal) {
                    p.drawLine((int)f, BIG_MARK_X1, (int)f, BIG_MARK_X2);
                } else {
                    p.drawLine(BIG_MARK_X1, (int)f, BIG_MARK_X2, (int)f);
                }
            }
        }
        if (d->showem) {
            // draw end marks
            if (d->dir == Qt::Horizontal) {
                p.drawLine(minval - d->offset, END_MARK_X1, minval - d->offset, END_MARK_X2);
                p.drawLine(maxval - d->offset, END_MARK_X1, maxval - d->offset, END_MARK_X2);
            } else {
                p.drawLine(END_MARK_X1, minval - d->offset, END_MARK_X2, minval - d->offset);
                p.drawLine(END_MARK_X1, maxval - d->offset, END_MARK_X2, maxval - d->offset);
            }
        }

        // draw pointer
        if (d->showpointer) {
            QPolygon pa(4);
            if (d->dir == Qt::Horizontal) {
                pa.setPoints(3, value - 5, 10, value + 5, 10, value/*+0*/, 15);
            } else {
                pa.setPoints(3, 10, value - 5, 10, value + 5, 15, value/*+0*/);
            }
            p.setBrush(p.background().color());
            p.drawPolygon(pa);
        }

#ifdef PROFILING
    }
    int elapsed = time.elapsed();
    debug("paint time %i", elapsed);
#endif

}
コード例 #18
0
ファイル: CGrayMap.cpp プロジェクト: DarkLotus/Source
bool CGrayMapBlockState::CheckTile_Item( DWORD wItemBlockFlags, signed char zBottom, height_t zHeight, DWORD dwID )
{
	ADDTOCALLSTACK("CGrayMapBlockState::CheckTile_Item");
	// RETURN:
	//  true = continue processing

	// hover flag has no effect for non-hovering entities
	if ( (wItemBlockFlags & CAN_I_HOVER) && !(m_dwBlockFlags & CAN_C_HOVER) )
		wItemBlockFlags &= ~CAN_I_HOVER;

	if ( ! wItemBlockFlags )	// no effect.
		return( true );

	signed char zTop = zBottom;
	
	if ( (wItemBlockFlags & CAN_I_CLIMB) && (wItemBlockFlags & CAN_I_PLATFORM) )
		zTop = minimum(zTop + ( zHeight / 2 ), UO_SIZE_Z);	// standing position is half way up climbable items (except platforms).
	else
		zTop = minimum(zTop + zHeight, UO_SIZE_Z);

	if ( zTop < m_Bottom.m_z )	// below something i can already step on.
		return true;

	if ( zBottom > m_Top.m_z )	// above my head.
		return true;

	if ( zTop < m_Lowest.m_z )
	{
		m_Lowest.m_dwBlockFlags = wItemBlockFlags;
		m_Lowest.m_dwTile = dwID;
		m_Lowest.m_z = zTop;
	}

	if ( ! ( wItemBlockFlags &~ m_dwBlockFlags ))
	{	// this does not block me.
		if ( ! ( wItemBlockFlags & ( CAN_I_CLIMB | CAN_I_PLATFORM | CAN_I_HOVER ) ) )
		{
			return true;
		}
	}

	if ( zBottom <= (m_zClimb + ((wItemBlockFlags & CAN_I_CLIMB) ? zHeight / 2 : 0)) )
	{
		if ( zTop >= m_Bottom.m_z )
		{
			if ( zTop == m_Bottom.m_z )
			{
				if ( ! ( wItemBlockFlags & CAN_I_CLIMB ) ) // climbable items have the highest priority
					if ( m_Bottom.m_dwBlockFlags & CAN_I_PLATFORM ) //than items with CAN_I_PLATFORM
						return ( true );
			}
			m_Bottom.m_dwBlockFlags = wItemBlockFlags;
			m_Bottom.m_dwTile = dwID;
			m_Bottom.m_z = zTop;

			if ( wItemBlockFlags & CAN_I_CLIMB ) // return climb height
				m_zClimbHeight = (( zHeight + 1 )/2); //if height is an odd number, then we need to add 1; if it isn't, this does nothing
			else
				m_zClimbHeight = 0;
		}
	}
	else
	{
		// I could potentially fit under this. ( it would be above me )
/*		if ( zBottom >= m_Top.m_z ) // ignore tiles above those already considered
		{
			return true;
		}*/
/*		else if (wItemBlockFlags &~(m_dwBlockFlags)) // if this does not block me... (here CAN_I_CLIMB = CAN_C_FLY makes sense, as we cannot reach the climbable)
		{
			if (!(wItemBlockFlags & (CAN_I_PLATFORM | CAN_I_ROOF))) // if it is not a platform or roof, skip
			{
				return true;
			}
		}*/
		if ( zBottom < m_Top.m_z )
		{
			m_Top.m_dwBlockFlags = wItemBlockFlags;
			m_Top.m_dwTile = dwID;
			m_Top.m_z = zBottom;
		}
	}
	return true;

}
コード例 #19
0
ファイル: Fl_Osc_Dial.cpp プロジェクト: peter1000/Carla
void Fl_Osc_Dial::OSC_value(int v)
{
    value(v + value() - floorf(value()) +
          (minimum() == 64 ? 0 : minimum()));
}
コード例 #20
0
ファイル: CGrayMap.cpp プロジェクト: DarkLotus/Source
bool CGrayMapBlockState::CheckTile( DWORD wItemBlockFlags, signed char zBottom, height_t zHeight, DWORD dwID )
{
	ADDTOCALLSTACK("CGrayMapBlockState::CheckTile");
	// RETURN:
	//  true = continue processing

	signed char zTop = zBottom;
	if ( (wItemBlockFlags & CAN_I_CLIMB) )
		zTop = minimum(zTop + ( zHeight / 2 ), UO_SIZE_Z);	// standing position is half way up climbable items.
	else
		zTop = minimum(zTop + zHeight, UO_SIZE_Z);

	if ( zTop < m_Bottom.m_z )	// below something i can already step on.
		return true;
	
	// hover flag has no effect for non-hovering entities
	if ( (wItemBlockFlags & CAN_I_HOVER) && !(m_dwBlockFlags & CAN_C_HOVER) )
		wItemBlockFlags &= ~CAN_I_HOVER;

	if ( ! wItemBlockFlags )	// no effect.
		return( true );

	// If this item does not block me at all then i guess it just does not count.
	if ( ! ( wItemBlockFlags &~ m_dwBlockFlags ))
	{	// this does not block me.
		if ( wItemBlockFlags & CAN_I_PLATFORM ) // i can always walk on the platform.
		{
			zBottom = zTop;
		}
		else if ( ! ( wItemBlockFlags & CAN_I_CLIMB ))
		{
			zTop = zBottom; // or i could walk under it.
		}
	}

	if ( zTop < m_Lowest.m_z )
	{
		m_Lowest.m_dwBlockFlags = wItemBlockFlags;
		m_Lowest.m_dwTile = dwID;
		m_Lowest.m_z = zTop;
	}

	// if i can't fit under this anyhow. it is something below me. (potentially)
	// we can climb a bit higher to reach climbables and platforms
	if ( zBottom < (m_z + (( m_iHeight + ((wItemBlockFlags & (CAN_I_CLIMB|CAN_I_PLATFORM)) ? zHeight : 0) ) / 2)) )
	{
		// This is the new item ( that would be ) under me.
		// NOTE: Platform items should take precedence over non-platforms.
		//       (Water acts as a platform for ships, so this also takes precedence)
		if ( zTop >= m_Bottom.m_z )
		{
			if ( zTop == m_Bottom.m_z )
			{
				if ( m_Bottom.m_dwBlockFlags & CAN_I_PLATFORM )
					return( true );
				else if ( (m_Bottom.m_dwBlockFlags & CAN_I_WATER) && !(wItemBlockFlags & CAN_I_PLATFORM))
					return( true );
			}
			m_Bottom.m_dwBlockFlags = wItemBlockFlags;
			m_Bottom.m_dwTile = dwID;
			m_Bottom.m_z = zTop;
		}
	}
	else
	{
		// I could potentially fit under this. ( it would be above me )
		if ( zBottom <= m_Top.m_z )
		{
			m_Top.m_dwBlockFlags = wItemBlockFlags;
			m_Top.m_dwTile = dwID;
			m_Top.m_z = zBottom;
		}
	}

	return true;
}
コード例 #21
0
ファイル: CClientUse.cpp プロジェクト: azmanomer/Source
bool CClient::Cmd_Skill_Tracking( unsigned int track_sel, bool fExec )
{
	ADDTOCALLSTACK("CClient::Cmd_Skill_Tracking");
	// look around for stuff.

	ASSERT(m_pChar);
	if ( track_sel == UINT_MAX )
	{
		// Tacking (unlike other skills) is used during menu setup.
		m_pChar->Skill_Cleanup();	// clean up current skill.

		CMenuItem item[6];
		item[0].m_sText = g_Cfg.GetDefaultMsg( DEFMSG_TRACKING_SKILLMENU_TITLE );

		item[1].m_id = ITEMID_TRACK_HORSE;
		item[1].m_color = 0;
		item[1].m_sText = g_Cfg.GetDefaultMsg( DEFMSG_TRACKING_SKILLMENU_ANIMALS );
		item[2].m_id = ITEMID_TRACK_OGRE;
		item[2].m_color = 0;
		item[2].m_sText = g_Cfg.GetDefaultMsg( DEFMSG_TRACKING_SKILLMENU_MONSTERS );
		item[3].m_id = ITEMID_TRACK_MAN;
		item[3].m_color = 0;
		item[3].m_sText = g_Cfg.GetDefaultMsg( DEFMSG_TRACKING_SKILLMENU_HUMANS );
		item[4].m_id = ITEMID_TRACK_WOMAN;
		item[4].m_color = 0;
		item[4].m_sText = g_Cfg.GetDefaultMsg( DEFMSG_TRACKING_SKILLMENU_PLAYERS );

		m_tmMenu.m_Item[0] = 0;
		addItemMenu( CLIMODE_MENU_SKILL_TRACK_SETUP, item, 4 );
		return( true );
	}

	if ( track_sel > 0 ) // Not Cancelled
	{
		ASSERT( track_sel < COUNTOF( m_tmMenu.m_Item ));
		if ( fExec )
		{
			// Tracking menu got us here. Start tracking the selected creature.
			m_pChar->SetTimeout( 1*TICK_PER_SEC );
			m_pChar->m_Act_Targ = m_tmMenu.m_Item[track_sel]; // selected UID
			m_pChar->Skill_Start( SKILL_TRACKING );
			return true;
		}

		static const NPCBRAIN_TYPE sm_Track_Brain[] =
		{
			NPCBRAIN_QTY,	// not used here.
			NPCBRAIN_ANIMAL,
			NPCBRAIN_MONSTER,
			NPCBRAIN_HUMAN,
			NPCBRAIN_NONE	// players
		};

		if ( track_sel >= COUNTOF(sm_Track_Brain))
			track_sel = COUNTOF(sm_Track_Brain)-1;
		NPCBRAIN_TYPE track_type = sm_Track_Brain[ track_sel ];

		CMenuItem item[ minimum( MAX_MENU_ITEMS, COUNTOF( m_tmMenu.m_Item )) ];
		size_t count = 0;

		item[0].m_sText = g_Cfg.GetDefaultMsg( DEFMSG_TRACKING_SKILLMENU_TITLE );
		m_tmMenu.m_Item[0] = track_sel;

		CWorldSearch AreaChars( m_pChar->GetTopPoint(), m_pChar->Skill_GetBase(SKILL_TRACKING)/10 + 10 );
		for (;;)
		{
			CChar * pChar = AreaChars.GetChar();
			if ( pChar == NULL )
				break;
			if ( m_pChar == pChar )
				continue;

			if ( GetPrivLevel() < pChar->GetPrivLevel() && pChar->IsStatFlag(STATF_Insubstantial) )
				continue;

			CCharBase * pCharDef = pChar->Char_GetDef();
			NPCBRAIN_TYPE basic_type = pChar->GetNPCBrain();
			if ( basic_type == NPCBRAIN_DRAGON )
				basic_type = NPCBRAIN_MONSTER;
			if ( track_type != basic_type && track_type != NPCBRAIN_QTY )
			{
				if ( track_type != NPCBRAIN_NONE )		// no match.
					continue;
				if ( pChar->IsStatFlag( STATF_DEAD ))	// can't track ghosts
					continue;
				if ( ! pChar->m_pPlayer )
					continue;

				// Check action difficulty when trying to track players
				int tracking = m_pChar->Skill_GetBase( SKILL_TRACKING );
				int detectHidden = m_pChar->Skill_GetBase( SKILL_DETECTINGHIDDEN );
				if ( (g_Cfg.m_iRacialFlags & RACIALF_ELF_DIFFTRACK) && pChar->IsElf() )
					tracking /= 2;			// elves are more difficult to track (Difficult to Track racial trait)

				int hiding = pChar->Skill_GetBase( SKILL_HIDING );
				int stealth = pChar->Skill_GetBase( SKILL_STEALTH );
				int divisor = maximum(hiding + stealth, 1);

				int chance;
				if ( g_Cfg.m_iFeatureSE & FEATURE_SE_UPDATE )
					chance = 50 * (tracking * 2 + detectHidden) / divisor;
				else
					chance = 50 * (tracking + detectHidden + 10 * Calc_GetRandVal(20) ) / divisor;

				if ( Calc_GetRandVal(100) > chance )
					continue;
			}

			count ++;
			item[count].m_id = static_cast<WORD>(pCharDef->m_trackID);
			item[count].m_color = 0;
			item[count].m_sText = pChar->GetName();
			m_tmMenu.m_Item[count] = pChar->GetUID();
			if ( count >= (COUNTOF( item )-1) )
				break;
		}

		// Some credit for trying.
		if ( count > 0 )
		{
			m_pChar->Skill_UseQuick( SKILL_TRACKING, 20 + Calc_GetRandLLVal( 30 ));

			ASSERT(count < COUNTOF(item));
			addItemMenu( CLIMODE_MENU_SKILL_TRACK, item, count );
			return( true );
		}
		else
		{
			m_pChar->Skill_UseQuick( SKILL_TRACKING, 10 + Calc_GetRandLLVal( 30 ));
		}
	}

	// Tracking failed or was cancelled.
	static LPCTSTR const sm_Track_FailMsg[] =
	{
		g_Cfg.GetDefaultMsg( DEFMSG_TRACKING_CANCEL ),
		g_Cfg.GetDefaultMsg( DEFMSG_TRACKING_FAIL_ANIMAL ),
		g_Cfg.GetDefaultMsg( DEFMSG_TRACKING_FAIL_MONSTER ),
		g_Cfg.GetDefaultMsg( DEFMSG_TRACKING_FAIL_HUMAN ),
		g_Cfg.GetDefaultMsg( DEFMSG_TRACKING_FAIL_HUMAN )
	};

	if (track_sel >= COUNTOF(sm_Track_FailMsg))
		track_sel = COUNTOF(sm_Track_FailMsg) - 1;

	SysMessage( sm_Track_FailMsg[track_sel] );
	return( false );
}
コード例 #22
0
ファイル: Solvers.cpp プロジェクト: jmainpri/RobotKin
// Based on a paper by Samuel R. Buss and Jin-Su Kim // TODO: Cite the paper properly
rk_result_t Robot::selectivelyDampedLeastSquaresIK_chain(const vector<size_t> &jointIndices, VectorXd &jointValues,
                                              const Isometry3d &target, const Isometry3d &finalTF)
{
    return RK_SOLVER_NOT_READY;
    // FIXME: Make this work


    // Arbitrary constant for maximum angle change in one step
    gammaMax = M_PI/4; // TODO: Put this in the constructor so the user can change it at a whim


    vector<Linkage::Joint*> joints;
    joints.resize(jointIndices.size());
    // FIXME: Add in safety checks
    for(int i=0; i<joints.size(); i++)
        joints[i] = joints_[jointIndices[i]];

    // ~~ Declarations ~~
    MatrixXd J;
    JacobiSVD<MatrixXd> svd;
    Isometry3d pose;
    AngleAxisd aagoal;
    AngleAxisd aastate;
    Vector6d goal;
    Vector6d state;
    Vector6d err;
    Vector6d alpha;
    Vector6d N;
    Vector6d M;
    Vector6d gamma;
    VectorXd delta(jointValues.size());
    VectorXd tempPhi(jointValues.size());
    // ~~~~~~~~~~~~~~~~~~

//    cout << "\n\n" << endl;

    tolerance = 1*M_PI/180; // TODO: Put this in the constructor so the user can set it arbitrarily
    maxIterations = 1000; // TODO: Put this in the constructor so the user can set it arbitrarily

    size_t iterations = 0;
    do {

        values(jointIndices, jointValues);

        jacobian(J, joints, joints.back()->respectToRobot().translation()+finalTF.translation(), this);

        svd.compute(J, ComputeFullU | ComputeThinV);

    //    cout <<  "\n\n" << svd.matrixU() << "\n\n\n" << svd.singularValues().transpose() << "\n\n\n" << svd.matrixV() << endl;

    //    for(int i=0; i<svd.matrixU().cols(); i++)
    //        cout << "u" << i << " : " << svd.matrixU().col(i).transpose() << endl;


    //    std::cout << "Joint name: " << joint(jointIndices.back()).name()
    //              << "\t Number: " << jointIndices.back() << std::endl;
        pose = joint(jointIndices.back()).respectToRobot()*finalTF;

    //    std::cout << "Pose: " << std::endl;
    //    std::cout << pose.matrix() << std::endl;

    //    AngleAxisd aagoal(target.rotation());
        aagoal = target.rotation();
        goal << target.translation(), aagoal.axis()*aagoal.angle();

        aastate = pose.rotation();
        state << pose.translation(), aastate.axis()*aastate.angle();

        err = goal-state;

    //    std::cout << "state: " << state.transpose() << std::endl;
    //    std::cout << "err: " << err.transpose() << std::endl;

        for(int i=0; i<6; i++)
            alpha[i] = svd.matrixU().col(i).dot(err);

    //    std::cout << "Alpha: " << alpha.transpose() << std::endl;

        for(int i=0; i<6; i++)
        {
            N[i] = svd.matrixU().block(0,i,3,1).norm();
            N[i] += svd.matrixU().block(3,i,3,1).norm();
        }

    //    std::cout << "N: " << N.transpose() << std::endl;

        double tempMik = 0;
        for(int i=0; i<svd.matrixV().cols(); i++)
        {
            M[i] = 0;
            for(int k=0; k<svd.matrixU().cols(); k++)
            {
                tempMik = 0;
                for(int j=0; j<svd.matrixV().cols(); j++)
                    tempMik += fabs(svd.matrixV()(j,i))*J(k,j);
                M[i] += 1/svd.singularValues()[i]*tempMik;
            }
        }

    //    std::cout << "M: " << M.transpose() << std::endl;

        for(int i=0; i<svd.matrixV().cols(); i++)
            gamma[i] = minimum(1, N[i]/M[i])*gammaMax;

    //    std::cout << "Gamma: " << gamma.transpose() << std::endl;

        delta.setZero();
        for(int i=0; i<svd.matrixV().cols(); i++)
        {
    //        std::cout << "1/sigma: " << 1/svd.singularValues()[i] << std::endl;
            tempPhi = 1/svd.singularValues()[i]*alpha[i]*svd.matrixV().col(i);
    //        std::cout << "Phi: " << tempPhi.transpose() << std::endl;
            clampMaxAbs(tempPhi, gamma[i]);
            delta += tempPhi;
    //        std::cout << "delta " << i << ": " << delta.transpose() << std::endl;
        }

        clampMaxAbs(delta, gammaMax);

        jointValues += delta;

        std::cout << iterations << " | Norm:" << delta.norm() << "\tdelta: "
                  << delta.transpose() << "\tJoints:" << jointValues.transpose() << std::endl;

        iterations++;
    } while(delta.norm() > tolerance && iterations < maxIterations);
}
コード例 #23
0
ファイル: CClientUse.cpp プロジェクト: azmanomer/Source
bool CClient::Cmd_Skill_Menu( RESOURCE_ID_BASE rid, int iSelect )
{
	ADDTOCALLSTACK("CClient::Cmd_Skill_Menu");
	// Build the skill menu for the curent active skill.
	// Only list the things we have skill and ingrediants to make.
	//
	// ARGS:
	//	m_Targ_UID = the object used to get us here.
	//  rid = which menu ?
	//	iSelect = -2 = Just a test of the whole menu.,
	//	iSelect = -1 = 1st setup.
	//	iSelect = 0 = cancel
	//	iSelect = x = execute the selection.
	//
	// RETURN: false = fail/cancel the skill.
	//   m_tmMenu.m_Item = the menu entries.

	ASSERT(m_pChar);
	if ( rid.GetResType() != RES_SKILLMENU )
		return( false );

	bool fShowMenu = false;
	bool fLimitReached = false;

	if ( iSelect == 0 )
	{
		// menu cancelled
		return( Cmd_Skill_Menu_Build( rid, iSelect, NULL, 0, fShowMenu, fLimitReached ) > 0);
	}

	CMenuItem item[ minimum( COUNTOF( m_tmMenu.m_Item ), MAX_MENU_ITEMS ) ];
	size_t iShowCount = Cmd_Skill_Menu_Build( rid, iSelect, item, COUNTOF(item), fShowMenu, fLimitReached);

	if ( iSelect < -1 )		// just a test.
	{
		return( iShowCount ? true : false );
	}

	if ( iSelect > 0 )	// seems our resources disappeared.
	{
		if ( iShowCount <= 0 )
		{
			SysMessageDefault( DEFMSG_CANT_MAKE );
		}
		return( iShowCount > 0 ? true : false );
	}

	if ( iShowCount <= 0 )
	{
		SysMessageDefault( DEFMSG_CANT_MAKE_RES );
		return( false );
	}

	if ( iShowCount == 1 && fShowMenu == true && fLimitReached == false )
	{
		static int sm_iReentrant = 0;
		if ( sm_iReentrant < 12 )
		{
			sm_iReentrant++;

			// If there is just one menu then select it.
			bool fSuccess = Cmd_Skill_Menu( rid, m_tmMenu.m_Item[1] );

			sm_iReentrant--;
			return( fSuccess );
		}

		if ( g_Cfg.m_wDebugFlags & DEBUGF_SCRIPTS )
			g_Log.EventDebug("SCRIPT: Too many empty skill menus to continue seeking through menu '%s'\n", g_Cfg.ResourceGetDef(rid)->GetResourceName());
	}
	
	ASSERT(iShowCount < COUNTOF(item));
	addItemMenu( CLIMODE_MENU_SKILL, item, iShowCount );
	return( true );
}
コード例 #24
0
/*!
  Set the maximum value of the range

  \param value Maximum value
  \sa setRange(), setMinimum(), maximum()
*/
void QwtCounter::setMaximum( double value )
{
    setRange( minimum(), value );
}
コード例 #25
0
ファイル: qgsdoublespinbox.cpp プロジェクト: ACorradini/QGIS
void QgsDoubleSpinBox::changeEvent( QEvent *event )
{
  QDoubleSpinBox::changeEvent( event );
  mClearButton->setVisible( mShowClearButton && isEnabled() && value() != minimum() );
}
コード例 #26
0
/*!
  Handle key events

  - Ctrl + Qt::Key_Home\n
    Step to minimum()
  - Ctrl + Qt::Key_End\n
    Step to maximum()
  - Qt::Key_Up\n
    Increment by incSteps(QwtCounter::Button1)
  - Qt::Key_Down\n
    Decrement by incSteps(QwtCounter::Button1)
  - Qt::Key_PageUp\n
    Increment by incSteps(QwtCounter::Button2)
  - Qt::Key_PageDown\n
    Decrement by incSteps(QwtCounter::Button2)
  - Shift + Qt::Key_PageUp\n
    Increment by incSteps(QwtCounter::Button3)
  - Shift + Qt::Key_PageDown\n
    Decrement by incSteps(QwtCounter::Button3)

  \param event Key event
*/
void QwtCounter::keyPressEvent ( QKeyEvent *event )
{
    bool accepted = true;

    switch ( event->key() )
    {
        case Qt::Key_Home:
        {
            if ( event->modifiers() & Qt::ControlModifier )
                setValue( minimum() );
            else
                accepted = false;
            break;
        }
        case Qt::Key_End:
        {
            if ( event->modifiers() & Qt::ControlModifier )
                setValue( maximum() );
            else
                accepted = false;
            break;
        }
        case Qt::Key_Up:
        {
            incrementValue( d_data->increment[0] );
            break;
        }
        case Qt::Key_Down:
        {
            incrementValue( -d_data->increment[0] );
            break;
        }
        case Qt::Key_PageUp:
        case Qt::Key_PageDown:
        {
            int increment = d_data->increment[0];
            if ( d_data->numButtons >= 2 )
                increment = d_data->increment[1];
            if ( d_data->numButtons >= 3 )
            {
                if ( event->modifiers() & Qt::ShiftModifier )
                    increment = d_data->increment[2];
            }
            if ( event->key() == Qt::Key_PageDown )
                increment = -increment;
            incrementValue( increment );
            break;
        }
        default:
        {
            accepted = false;
        }
    }

    if ( accepted )
    {
        event->accept();
        return;
    }

    QWidget::keyPressEvent ( event );
}
コード例 #27
0
ファイル: qgsdoublespinbox.cpp プロジェクト: ACorradini/QGIS
void QgsDoubleSpinBox::clear()
{
  setValue( minimum() );
}
コード例 #28
0
ファイル: qstyleitem.cpp プロジェクト: CNOT/julia-studio
void QStyleItem::initStyleOption()
{
    QString type = elementType();
    if (m_styleoption)
        m_styleoption->state = 0;

    switch (m_itemType) {
    case Button: {
            if (!m_styleoption)
                m_styleoption = new QStyleOptionButton();

            QStyleOptionButton *opt = qstyleoption_cast<QStyleOptionButton*>(m_styleoption);
            opt->text = text();
            opt->features = (activeControl() == "default") ?
                            QStyleOptionButton::DefaultButton :
                            QStyleOptionButton::None;
        }
        break;
    case ItemRow: {
            if (!m_styleoption)
                m_styleoption = new QStyleOptionViewItemV4();

            QStyleOptionViewItemV4 *opt = qstyleoption_cast<QStyleOptionViewItemV4*>(m_styleoption);
            opt->features = 0;
            if (activeControl() == "alternate")
                opt->features |= QStyleOptionViewItemV2::Alternate;
        }
        break;

    case Splitter: {
            if (!m_styleoption) {
                m_styleoption = new QStyleOption;
            }
        }
        break;

    case Item: {
            if (!m_styleoption) {
                m_styleoption = new QStyleOptionViewItemV4();
            }
            QStyleOptionViewItemV4 *opt = qstyleoption_cast<QStyleOptionViewItemV4*>(m_styleoption);
            opt->features = QStyleOptionViewItemV4::HasDisplay;
            opt->text = text();
            opt->textElideMode = Qt::ElideRight;
            QPalette pal = m_styleoption->palette;
            pal.setBrush(QPalette::Base, Qt::NoBrush);
            m_styleoption->palette = pal;
        }
        break;
    case Header: {
            if (!m_styleoption)
                m_styleoption = new QStyleOptionHeader();

            QStyleOptionHeader *opt = qstyleoption_cast<QStyleOptionHeader*>(m_styleoption);
            opt->text = text();
            opt->sortIndicator = activeControl() == "down" ?
                                 QStyleOptionHeader::SortDown
                                     : activeControl() == "up" ?
                                     QStyleOptionHeader::SortUp : QStyleOptionHeader::None;
            if (activeControl() == QLatin1String("beginning"))
                opt->position = QStyleOptionHeader::Beginning;
            else if (activeControl() == QLatin1String("end"))
                opt->position = QStyleOptionHeader::End;
            else if (activeControl() == QLatin1String("only"))
                opt->position = QStyleOptionHeader::OnlyOneSection;
            else
                opt->position = QStyleOptionHeader::Middle;

        }
        break;
    case ToolButton :{
            if (!m_styleoption)
                m_styleoption = new QStyleOptionToolButton();

            QStyleOptionToolButton *opt =
                    qstyleoption_cast<QStyleOptionToolButton*>(m_styleoption);
            opt->subControls = QStyle::SC_ToolButton;
            opt->state |= QStyle::State_AutoRaise;
            opt->activeSubControls = QStyle::SC_ToolButton;
        }
        break;
    case ToolBar: {
            if (!m_styleoption)
                m_styleoption = new QStyleOptionToolBar();
        }
        break;
    case Tab: {
            if (!m_styleoption)
                m_styleoption = new QStyleOptionTabV3();

            QStyleOptionTabV3 *opt =
                    qstyleoption_cast<QStyleOptionTabV3*>(m_styleoption);
            opt->text = text();
            opt->shape = info() == "South" ? QTabBar::RoundedSouth : QTabBar::RoundedNorth;
            if (activeControl() == QLatin1String("beginning"))
                opt->position = QStyleOptionTabV3::Beginning;
            else if (activeControl() == QLatin1String("end"))
                opt->position = QStyleOptionTabV3::End;
            else if (activeControl() == QLatin1String("only"))
                opt->position = QStyleOptionTabV3::OnlyOneTab;
            else
                opt->position = QStyleOptionTabV3::Middle;

        } break;

    case Menu: {
            if (!m_styleoption)
                m_styleoption = new QStyleOptionMenuItem();
        }
        break;
    case Frame: {
            if (!m_styleoption)
                m_styleoption = new QStyleOptionFrameV3();

            QStyleOptionFrameV3 *opt = qstyleoption_cast<QStyleOptionFrameV3*>(m_styleoption);
            opt->frameShape = QFrame::StyledPanel;
            opt->lineWidth = 1;
            opt->midLineWidth = 1;
        }
        break;
    case TabFrame: {
            if (!m_styleoption)
                m_styleoption = new QStyleOptionTabWidgetFrameV2();
            QStyleOptionTabWidgetFrameV2 *opt = qstyleoption_cast<QStyleOptionTabWidgetFrameV2*>(m_styleoption);
            opt->shape = (info() == "South") ? QTabBar::RoundedSouth : QTabBar::RoundedNorth;
            if (minimum())
                opt->selectedTabRect = QRect(value(), 0, minimum(), height());
            opt->tabBarSize = QSize(minimum() , height());
            // oxygen style needs this hack
            opt->leftCornerWidgetSize = QSize(value(), 0);
        }
        break;
    case MenuItem:
    case ComboBoxItem:
        {
            if (!m_styleoption)
                m_styleoption = new QStyleOptionMenuItem();

            QStyleOptionMenuItem *opt = qstyleoption_cast<QStyleOptionMenuItem*>(m_styleoption);
            opt->checked = false;
            opt->text = text();
            opt->palette = widget()->palette();
        }
        break;
    case CheckBox:
    case RadioButton:
        {
            if (!m_styleoption)
                m_styleoption = new QStyleOptionButton();

            QStyleOptionButton *opt = qstyleoption_cast<QStyleOptionButton*>(m_styleoption);
            if (!on())
                opt->state |= QStyle::State_Off;
            opt->text = text();
        }
        break;
    case Edit: {
            if (!m_styleoption)
                m_styleoption = new QStyleOptionFrameV3();

            QStyleOptionFrameV3 *opt = qstyleoption_cast<QStyleOptionFrameV3*>(m_styleoption);
            opt->lineWidth = 1; // this must be non-zero
        }
        break;
    case ComboBox :{
            if (!m_styleoption)
                m_styleoption = new QStyleOptionComboBox();
            QStyleOptionComboBox *opt = qstyleoption_cast<QStyleOptionComboBox*>(m_styleoption);
            opt->currentText = text();
        }
        break;
    case SpinBox: {
            if (!m_styleoption)
                m_styleoption = new QStyleOptionSpinBox();

            QStyleOptionSpinBox *opt = qstyleoption_cast<QStyleOptionSpinBox*>(m_styleoption);
            opt->frame = true;
            if (value() & 0x1)
                opt->activeSubControls = QStyle::SC_SpinBoxUp;
            else if (value() & (1<<1))
                opt->activeSubControls = QStyle::SC_SpinBoxDown;
            opt->subControls = QStyle::SC_All;
            opt->stepEnabled = 0;
            if (value() & (1<<2))
                opt->stepEnabled |= QAbstractSpinBox::StepUpEnabled;
            if (value() & (1<<3))
                opt->stepEnabled |= QAbstractSpinBox::StepDownEnabled;
        }
        break;
    case Slider:
    case Dial:
        {
            if (!m_styleoption)
                m_styleoption = new QStyleOptionSlider();

            QStyleOptionSlider *opt = qstyleoption_cast<QStyleOptionSlider*>(m_styleoption);
            opt->minimum = minimum();
            opt->maximum = maximum();
            // ### fixme - workaround for KDE inverted dial
            opt->sliderPosition = value();
            opt->singleStep = step();

            if (opt->singleStep)
            {
                qreal numOfSteps = (opt->maximum - opt->minimum) / opt->singleStep;

                // at least 5 pixels between tick marks
                if (numOfSteps && (width() / numOfSteps < 5))
                    opt->tickInterval = qRound((5*numOfSteps / width()) + 0.5)*step();
                else
                    opt->tickInterval = opt->singleStep;
            }
            else // default Qt-components implementation
                opt->tickInterval = opt->maximum != opt->minimum ? 1200 / (opt->maximum - opt->minimum) : 0;

            if (style() == QLatin1String("oxygen") && type == QLatin1String("dial"))
                opt->sliderValue  = maximum() - value();
            else
                opt->sliderValue = value();
            opt->subControls = QStyle::SC_SliderGroove | QStyle::SC_SliderHandle;
            opt->tickPosition = (activeControl() == "below") ?
                                QSlider::TicksBelow : (activeControl() == "above" ?
                                                       QSlider::TicksAbove:
                                                       QSlider::NoTicks);
            if (opt->tickPosition != QSlider::NoTicks)
                opt->subControls |= QStyle::SC_SliderTickmarks;

            opt->activeSubControls = QStyle::SC_None;
        }
        break;
    case ProgressBar: {
            if (QProgressBar *bar= qobject_cast<QProgressBar*>(widget())){
                bar->setMaximum(maximum());
                bar->setMinimum(minimum());
                if (maximum() != minimum())
                    bar->setValue(1);
            }
            if (!m_styleoption)
                m_styleoption = new QStyleOptionProgressBarV2();

            QStyleOptionProgressBarV2 *opt = qstyleoption_cast<QStyleOptionProgressBarV2*>(m_styleoption);
            opt->orientation = horizontal() ? Qt::Horizontal : Qt::Vertical;
            opt->minimum = minimum();
            opt->maximum = maximum();
            opt->progress = value();
        }
        break;
    case GroupBox: {
            if (!m_styleoption)
                m_styleoption = new QStyleOptionGroupBox();

            QStyleOptionGroupBox *opt = qstyleoption_cast<QStyleOptionGroupBox*>(m_styleoption);
            opt->text = text();
            opt->lineWidth = 1;
            opt->subControls = QStyle::SC_GroupBoxLabel;
            if (sunken()) // Qt draws an ugly line here so I ignore it
                opt->subControls |= QStyle::SC_GroupBoxFrame;
            else
                opt->features |= QStyleOptionFrameV2::Flat;
            if (activeControl() == "checkbox")
                opt->subControls |= QStyle::SC_GroupBoxCheckBox;

            if (QGroupBox *group= qobject_cast<QGroupBox*>(widget())) {
                group->setTitle(text());
                group->setCheckable(opt->subControls & QStyle::SC_GroupBoxCheckBox);
            }
        }
        break;
    case ScrollBar: {
            if (!m_styleoption)
                m_styleoption = new QStyleOptionSlider();

            QStyleOptionSlider *opt = qstyleoption_cast<QStyleOptionSlider*>(m_styleoption);
            opt->minimum = minimum();
            opt->maximum = maximum();
            opt->pageStep = horizontal() ? width() : height();
            opt->orientation = horizontal() ? Qt::Horizontal : Qt::Vertical;
            opt->sliderPosition = value();
            opt->sliderValue = value();
            opt->activeSubControls = (activeControl() == QLatin1String("up"))
                                     ? QStyle::SC_ScrollBarSubLine :
                                     (activeControl() == QLatin1String("down")) ?
                                     QStyle::SC_ScrollBarAddLine:
                                     QStyle::SC_ScrollBarSlider;

            opt->sliderValue = value();
            opt->subControls = QStyle::SC_All;

            QScrollBar *bar = qobject_cast<QScrollBar *>(widget());
            bar->setMaximum(maximum());
            bar->setMinimum(minimum());
            bar->setValue(value());
        }
        break;
    default:
        break;
    }

    if (!m_styleoption)
        m_styleoption = new QStyleOption();

    m_styleoption->rect = QRect(m_paintMargins, m_paintMargins, width() - 2* m_paintMargins, height() - 2 * m_paintMargins);

    if (isEnabled())
        m_styleoption->state |= QStyle::State_Enabled;
    if (m_active)
        m_styleoption->state |= QStyle::State_Active;
    if (m_sunken)
        m_styleoption->state |= QStyle::State_Sunken;
    if (m_raised)
        m_styleoption->state |= QStyle::State_Raised;
    if (m_selected)
        m_styleoption->state |= QStyle::State_Selected;
    if (m_focus)
        m_styleoption->state |= QStyle::State_HasFocus;
    if (m_on)
        m_styleoption->state |= QStyle::State_On;
    if (m_hover)
        m_styleoption->state |= QStyle::State_MouseOver;
    if (m_horizontal)
        m_styleoption->state |= QStyle::State_Horizontal;

    if (widget()) {
        widget()->ensurePolished();
        if (type == QLatin1String("tab") && style() != QLatin1String("mac")) {
            // Some styles actually check the beginning and end position
            // using widget geometry, so we have to trick it
            widget()->setGeometry(0, 0, width(), height());
            if (activeControl() != "beginning")
                m_styleoption->rect.translate(1, 0); // Don't position at start of widget
            if (activeControl() != "end")
                widget()->resize(200, height());
        }
#ifdef Q_OS_WIN
        else widget()->resize(width(), height());
#endif

        widget()->setEnabled(isEnabled());
        m_styleoption->fontMetrics = widget()->fontMetrics();
        if (!m_styleoption->palette.resolve())
            m_styleoption->palette = widget()->palette();
        if (m_hint.contains("mac.mini")) {
            widget()->setAttribute(Qt::WA_MacMiniSize);
        } else if (m_hint.contains("mac.small")) {
            widget()->setAttribute(Qt::WA_MacSmallSize);
        }
    }
}
コード例 #29
0
ファイル: main.cpp プロジェクト: keitee/kb
T1 minimum(T1 a, T... args)
{
   return minimum(a, minimum(args...));
}
コード例 #30
0
/*
 * Skip forward by exactly the requested bytes or else return
 * ARCHIVE_FATAL.  Note that this differs from the contract for
 * read_ahead, which does not guarantee a minimum count.
 */
static off_t
archive_decompressor_none_skip(struct archive_read *a, off_t request)
{
	struct archive_decompress_none *state;
	off_t bytes_skipped, total_bytes_skipped = 0;
	size_t min;

	state = (struct archive_decompress_none *)a->decompressor->data;
	if (state->fatal)
		return (-1);
	/*
	 * If there is data in the buffers already, use that first.
	 */
	if (state->avail > 0) {
		min = minimum(request, (off_t)state->avail);
		bytes_skipped = archive_decompressor_none_read_consume(a, min);
		request -= bytes_skipped;
		total_bytes_skipped += bytes_skipped;
	}
	if (state->client_avail > 0) {
		min = minimum(request, (off_t)state->client_avail);
		bytes_skipped = archive_decompressor_none_read_consume(a, min);
		request -= bytes_skipped;
		total_bytes_skipped += bytes_skipped;
	}
	if (request == 0)
		return (total_bytes_skipped);
	/*
	 * If a client_skipper was provided, try that first.
	 */
#if ARCHIVE_API_VERSION < 2
	if ((a->client_skipper != NULL) && (request < SSIZE_MAX)) {
#else
	if (a->client_skipper != NULL) {
#endif
		bytes_skipped = (a->client_skipper)(&a->archive,
		    a->client_data, request);
		if (bytes_skipped < 0) {	/* error */
			state->client_total = state->client_avail = 0;
			state->client_next = state->client_buff = NULL;
			state->fatal = 1;
			return (bytes_skipped);
		}
		total_bytes_skipped += bytes_skipped;
		a->archive.file_position += bytes_skipped;
		request -= bytes_skipped;
		state->client_next = state->client_buff;
		a->archive.raw_position += bytes_skipped;
		state->client_avail = state->client_total = 0;
	}
	/*
	 * Note that client_skipper will usually not satisfy the
	 * full request (due to low-level blocking concerns),
	 * so even if client_skipper is provided, we may still
	 * have to use ordinary reads to finish out the request.
	 */
	while (request > 0) {
		const void* dummy_buffer;
		ssize_t bytes_read;
		bytes_read = archive_decompressor_none_read_ahead(a,
		    &dummy_buffer, 1);
		if (bytes_read < 0)
			return (bytes_read);
		if (bytes_read == 0) {
			/* We hit EOF before we satisfied the skip request. */
			archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
			    "Truncated input file (need to skip %jd bytes)",
			    (intmax_t)request);
			return (ARCHIVE_FATAL);
		}
		min = (size_t)(minimum(bytes_read, request));
		bytes_read = archive_decompressor_none_read_consume(a, min);
		total_bytes_skipped += bytes_read;
		request -= bytes_read;
	}
	return (total_bytes_skipped);
}

static int
archive_decompressor_none_finish(struct archive_read *a)
{
	struct archive_decompress_none	*state;

	state = (struct archive_decompress_none *)a->decompressor->data;
	free(state->buffer);
	free(state);
	a->decompressor->data = NULL;
	return (ARCHIVE_OK);
}