Example #1
0
static void
newreno_after_idle(struct cc_var *ccv)
{
	int rw;

	/*
	 * If we've been idle for more than one retransmit timeout the old
	 * congestion window is no longer current and we have to reduce it to
	 * the restart window before we can transmit again.
	 *
	 * The restart window is the initial window or the last CWND, whichever
	 * is smaller.
	 *
	 * This is done to prevent us from flooding the path with a full CWND at
	 * wirespeed, overloading router and switch buffers along the way.
	 *
	 * See RFC5681 Section 4.1. "Restarting Idle Connections".
	 */
	if (V_tcp_do_rfc3390)
		rw = min(4 * CCV(ccv, t_maxseg),
		    max(2 * CCV(ccv, t_maxseg), 4380));
	else
		rw = CCV(ccv, t_maxseg) * 2;

	CCV(ccv, snd_cwnd) = min(rw, CCV(ccv, snd_cwnd));
}
Example #2
0
void SubPlotWnd::OnMouseMove(UINT nFlags, CPoint point)
{
	// TODO: Add your message handler code here and/or call default
	if (this->isDraging)
	{
		CPoint cursorPoint;
		::GetCursorPos(&cursorPoint);
		CPoint cursorPointOld = cursorPoint;

		CRect parentClientRect;
		this->GetParent()->GetClientRect(&parentClientRect);
		this->GetParent()->ClientToScreen(&parentClientRect);

		cursorPoint.x = max(cursorPoint.x, parentClientRect.left);
		cursorPoint.x = min(cursorPoint.x, parentClientRect.right);
		cursorPoint.y = max(cursorPoint.y, parentClientRect.top);
		cursorPoint.y = min(cursorPoint.y, parentClientRect.bottom);

		if (cursorPoint != cursorPointOld)
			::SetCursorPos(cursorPoint.x, cursorPoint.y);
		CRect rectWindow = this->rectBeforeDrag;
		rectWindow.OffsetRect(cursorPoint - this->cursorBeforeDrag);
		this->MoveWindow(rectWindow.left, rectWindow.top, rectWindow.Width(), rectWindow.Height(), 1);

		CWnd::OnMouseMove(nFlags, point);
	}
}
Example #3
0
void Rectan::Draw(Graphics* graphics)
{
	Pen myPen(m_Color, m_Width);
	graphics->DrawRectangle(&myPen, min(m_x1, m_x2), min(m_y1, m_y2), abs(m_x1 - m_x2), abs(m_y1 - m_y2)); 
	SolidBrush myBrush(m_Background_Color);
	graphics->FillRectangle(&myBrush, min(m_x1, m_x2), min(m_y1, m_y2), abs(m_x1 - m_x2), abs(m_y1 - m_y2));
}
void ErodeDistanceOperation::executePixel(float *color, int x, int y, void *data)
{
	const float distance = this->m_distance;
	const float mindist = distance * distance;

	MemoryBuffer *inputBuffer = (MemoryBuffer *)data;
	float *buffer = inputBuffer->getBuffer();
	rcti *rect = inputBuffer->getRect();
	const int minx = max(x - this->m_scope, rect->xmin);
	const int miny = max(y - this->m_scope, rect->ymin);
	const int maxx = min(x + this->m_scope, rect->xmax);
	const int maxy = min(y + this->m_scope, rect->ymax);
	const int bufferWidth = rect->xmax - rect->xmin;
	int offset;
	
	float value = 1.0f;

	for (int yi = miny; yi < maxy; yi++) {
		const float dy = yi - y;
		offset = ((yi - rect->ymin) * bufferWidth + (minx - rect->xmin)) * 4;
		for (int xi = minx; xi < maxx; xi++) {
			const float dx = xi - x;
			const float dis = dx * dx + dy * dy;
			if (dis <= mindist) {
				value = min(buffer[offset], value);
			}
			offset += 4;
		}
	}
	color[0] = value;
}
Example #5
0
bool InstrVAcc::Redraw2D (SURFHANDLE surf)
{
	int i;
	float yofs;
	VECTOR3 V;
	double vspd;
	double t = oapiGetSimTime();
	if (vessel->GetAirspeedVector (FRAME_HORIZON, V)) {
		vspd = V.y; // unit is 10m
	} else {
		vspd = 0.0;
	}
	if (t > pt) {
		const double yscale = 6.2455;
		double vacc = (vspd-pvspd)/(t-pt);
		yofs = -(float)((vacc >= 0.0 ? sqrt(min(40,vacc)) : -sqrt(min(40,-vacc))) * yscale);
		static const float y0[3] = {vtape_ycnt, vtape_ycnt-6, vtape_ycnt+6};
		for (i = 0; i < 3; i++)
			grp->Vtx[vtxofs+i].y = y0[i] + yofs;
	}
	pvspd = vspd;
	pt = t;

	return false;
}
Example #6
0
int MaximalSquare::maximalSquare(vector<vector<char>> &matrix) {
    size_t n = matrix.size();

    if (n == 0) return 0;

    size_t m = matrix[0].size();

    if (m == 0) return 0;

    vector<vector<int>> dp(n, vector<int>(m, 0));

    for (int i = 0; i < n; i++)
        dp[i][0] = (matrix[i][0] == '1') ? 1 : 0;

    for (int j = 0; j < m; j++)
        dp[0][j] = (matrix[0][j] == '1') ? 1 : 0;

    for (int i = 1; i < n; i++) {
        for (int j = 1; j < m; j++) {
            if (matrix[i][j] == '0')
                dp[i][j] = 0;
            else
                dp[i][j] = min(min(dp[i - 1][j], dp[i][j - 1]), dp[i - 1][j - 1]) + 1;
        }
    }

    int w = 0;

    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
            w = max(w, dp[i][j]);

    return w * w;
}
/**
  * Replaces the content of this image with that of a given 2D array representing
  * the image.
  *
  * @param width the width of the image. Must be within the dimensions of the image.
  *
  * @param height the height of the image. Must be within the dimensions of the image.
  *
  * @param bitmap a 2D array representing the image.
  *
  * @return MICROBIT_OK on success, or MICROBIT_INVALID_PARAMETER.
  *
  * @code
  * const uint8_t heart[] = { 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, }; // a cute heart
  * MicroBitImage i(10, 5);
  * i.printImage(10,5,heart);
  * @endcode
  *
  * @note all coordinates originate from the top left of an image.
  */
int MicroBitImage::printImage(int16_t width, int16_t height, const uint8_t *bitmap)
{
    const uint8_t *pIn;
    uint8_t *pOut;
    int pixelsToCopyX, pixelsToCopyY;

    // Sanity check.
    if (width <= 0 || height <= 0 || bitmap == NULL)
        return MICROBIT_INVALID_PARAMETER;

    // Calculate sane start pointer.
    pixelsToCopyX = min(width,this->getWidth());
    pixelsToCopyY = min(height,this->getHeight());

    pIn = bitmap;
    pOut = this->getBitmap();

    // Copy the image, stride by stride.
    for (int i=0; i<pixelsToCopyY; i++)
    {
        memcpy(pOut, pIn, pixelsToCopyX);
        pIn += width;
        pOut += this->getWidth();
    }

    return MICROBIT_OK;
}
Example #8
0
// ---
int sign_hash_buffer( CTN_Hash* hash, char* buffer, int len ) {
  int rest = len;
  int now = min( len, (int)0x7000 );
  char* ptr = buffer;

  if ( !hash || !buffer || len < 0 )
    return SIGN_BAD_PARAMETERS;

  MY_TRY {

    s_mset( hash, 0, sizeof(CTN_Hash) );
    CTN_SHAInit( hash );
    hash->Method = AVP_SIGN_METHOD;

    while( now ) {
      CTN_SHABuffer( hash, (CT_PTR)ptr, (CT_INT)now );
      ptr += now;
      rest -= now;
      now = min( rest, (int)0x7000 );
    }

    CTN_SHAEnd( hash );
    hash->flags |= CT_FLAGS_HASHDONE;

    return SIGN_OK;
  }
  MY_EXCEPT
}
float3 CAICallback::ClosestBuildSite(const UnitDef* unitdef,float3 pos,float searchRadius,int minDist)
{
	//todo fix so you cant detect enemy buildings with it
	CFeature* feature;
	int allyteam=gs->AllyTeam(team);

	int endr = (int)(searchRadius / (SQUARE_SIZE*2));
	const vector<SearchOffset>& ofs = GetSearchOffsetTable (endr);

	for(int so=0;so<endr*endr*4;so++) {
		float x = pos.x+ofs[so].dx*SQUARE_SIZE*2;
		float z = pos.z+ofs[so].dy*SQUARE_SIZE*2;
		float3 p(x,0,z);
		p = helper->Pos2BuildPos (p, unitdef);
		if(uh->TestUnitBuildSquare(p,unitdef,feature) && (!feature || feature->allyteam!=allyteam))
		{
			int xs=(int)(x/SQUARE_SIZE);
			int zs=(int)(z/SQUARE_SIZE);
			bool good=true;
			for(int z2=max(0,zs-unitdef->ysize/2-minDist);z2<min(gs->mapy,zs+unitdef->ysize+minDist);++z2){
				for(int x2=max(0,xs-unitdef->xsize/2-minDist);x2<min(gs->mapx,xs+unitdef->xsize+minDist);++x2){
					CSolidObject* so=readmap->groundBlockingObjectMap[z2*gs->mapx+x2];
					if(so && so->immobile && !dynamic_cast<CFeature*>(so)){
						good=false;
						break;
					}
				}
			}
			if(good) 
				return p;
		}
	}

	return float3(-1.0f,0.0f,0.0f);	
}
Example #10
0
File: MCL.c Project: xdanx/dandroid
float calculate_likelihood(float x, float y, float theta, float z)
{

	int closestWallIndex = -1;
	// We take into consideration the greatest distance
	float shortestDistance = 20000.0;
	float m;
	int i = 0;

	for (i = 0; i < NUMBER_OF_WALLS; i++)
	{
		float a_x = wallAxArray[i], a_y = wallAyArray[i];
		float b_x = wallBxArray[i], b_y = wallByArray[i];
		m = ((b_y - a_y)*(a_x - x) - (b_x - a_x)*(a_y - y)) / ((b_y - a_y)*cosDegrees(theta) - (b_x - a_x)*sinDegrees(theta));

		float px = x + m*cosDegrees(theta);
		float py = y + m*sinDegrees(theta);

		if( px >= min(a_x,b_x) && px <= max(a_x,b_x) && py >= min(a_y,b_y) && py <= max(a_y,b_y) && m >= 0)
		{
			if ( m <= shortestDistance )
			{
				shortestDistance = m;
				closestWallIndex = i;
			}
		}
	}
	float likelihood = exp(-pow(z - shortestDistance, 2) * 1.0 / (2 * pow(0.44, 2))) + 0.1;
	return likelihood;

}
Example #11
0
void pdb_legend(FILE *out, int natoms, int nres, t_atoms *atoms, rvec x[])
{
    real bfac_min, bfac_max, xmin, ymin, zmin;
    int i;
    int space = ' ';

    bfac_max = -1e10;
    bfac_min = 1e10;
    xmin = 1e10;
    ymin = 1e10;
    zmin = 1e10;
    for (i = 0; (i < natoms); i++)
    {
        xmin = min(xmin,x[i][XX]);
        ymin = min(ymin,x[i][YY]);
        zmin = min(zmin,x[i][ZZ]);
        bfac_min = min(bfac_min,atoms->pdbinfo[i].bfac);
        bfac_max = max(bfac_max,atoms->pdbinfo[i].bfac);
    }
    fprintf(stderr, "B-factors range from %g to %g\n", bfac_min, bfac_max);
    for (i = 1; (i < 12); i++)
    {
        fprintf(out,
                "%-6s%5u  %-4.4s%3.3s %c%4d%c   %8.3f%8.3f%8.3f%6.2f%6.2f\n",
                "ATOM  ", natoms + 1 + i, "CA", "LEG", space, nres + 1, space,
                (xmin + (i * 0.12)) * 10, ymin * 10, zmin * 10, 1.0, bfac_min
                    + ((i - 1.0) * (bfac_max - bfac_min) / 10));
    }
}
void TinyPPM::paint_on(ZCanvas *zcanvas)
{
#define CANVAS_PIXEL ((uint32_t*) (zcanvas->data+(y*zcanvas->width+x)*4))

	uint32_t background = 0x00a06000;
	uint32_t minx = min(zcanvas->width, width);
	uint32_t miny = min(zcanvas->height, height);
	uint32_t x, y;
	for (y=0; y<miny; y++)
	{
		for (x=0; x<minx; x++)
		{
			uint8_t *ptr = data+(y*width + x)*3;
			*CANVAS_PIXEL = ptr[0]<<16 | ptr[1]<<8 | ptr[0];
		}
		for (; x<zcanvas->width; x++)
		{
			*CANVAS_PIXEL = background;
		}
	}
	for (; y<zcanvas->height; y++)
	{
		for (x=0; x<zcanvas->width; x++)
		{
			*CANVAS_PIXEL = background;
		}
	}
}
Example #13
0
void
Sievelng<longint>::eratosthene() {
  int p;
  int ip = K+1; // Le rang du premier premier non precrible 
  int64 sqrt_B = root(B); // QUEL SQRT
  cerr << "size of sqrt_B = " << sizeof(sqrt_B) << endl;
  if (sqrt_B > max_prime()) {
    cerr << "Dans eratoshene,,, : pas assez de nombres premiers\n";
    cerr << "SQRT_B = " << sqrt_B << " maxp = " << max_prime() << "\n";
    cerr << "Crible aux. pour enumerer les premiers manquants " << endl;
    //    auxprimes.setup(100000020,MAX64);
    cerr <<" SIZE == " << SIZE << endl;
    int szx;
    if (SIZE > INT_MAX)
      szx = 2000000010;
    else szx = SIZE;
    cerr << "szx = " << szx << endl;
    auxprimes.setup(szx,MAX64);
    auxprimes.set_at_left(max_prime());
    auxprimes.eratosthene();
    cerr << "auxprime eratosthene is done" << endl;
    auxprimes.set_cursor_on(max_prime());
    cerr << "auxprime cursor is on maxprime() = " 
	 << auxprimes.current_prime() << endl;
    int64 p = auxprimes.next_prime();
    cerr << "Premier nombre premier complementaire  " << p << endl;
  }

  if (A <= 1)
    unset_bit(0);
  p = prime(ip++);
  cerr << "Crible 1 jusqu'a p= " <<  min(sqrt_B,max_prime()) << endl;
  cerr << "premier p = " << p << endl;
  while (p  <= min(sqrt_B,max_prime()))
    {
      //cerr << "sieve by " << p << endl;
      sieve_by(p);
      if (A <= p){ // Il est de toute facon <= LMAX
	set_bit(index(p));
      }
      p = prime(ip++);
    } 
  int cnt = 0;
  if (sqrt_B > max_prime()) {
    cerr << "Crible complementaire " << endl;
    int64 p = auxprimes.current_prime();
    while (p <= sqrt_B) {
      cnt++;
      if (p > SIZE)
	sieve_by_long(p);
      else sieve_by(p);
      p =  auxprimes.next_prime();
    }
    cerr << "Fin du crible complementaire" << endl;
  }
  cursor  = 0;
#if SIEVE_LNG_VERBOSE > 0
  cerr << "Nombre de premiers complementaires = " << cnt << endl;
#endif
}
Example #14
0
// A recursive function to find the smallest distance. The array P contains
// all points sorted according to x coordinate
float closestUtil(Point P[], int n)
{
    // If there are 2 or 3 points, then use brute force
    if (n <= 3)
        return bruteForce(P, n);
 
    // Find the middle point
    int mid = n/2;
    Point midPoint = P[mid];
 
    // Consider the vertical line passing through the middle point
    // calculate the smallest distance dl on left of middle point and
    // dr on right side
    float dl = closestUtil(P, mid);
    float dr = closestUtil(P + mid, n-mid);
 
    // Find the smaller of two distances
    float d = min(dl, dr);
 
    // Build an array strip[] that contains points close (closer than d)
    // to the line passing through the middle point
    Point strip[n];
    int j = 0;
    for (int i = 0; i < n; i++)
        if (abs(P[i].x - midPoint.x) < d)
            strip[j] = P[i], j++;
 
    // Find the closest points in strip.  Return the minimum of d and closest
    // distance is strip[]
    return min(d, stripClosest(strip, j, d) );
}
Example #15
0
/********************************************************
*	水平栅条特效
*********************************************************/
void EffectDisplay::HRasterDisplay(CDC* pDC, CDC* pMemDC)
{
	//扫描高度
	int nHeight = min(s_nPicHeight, s_nCDCHeight);
	//扫描宽度
	int nWidth = min(s_nPicWidth, s_nCDCWidth);

	int nScanLine = 16;

	for (int i = 0; i <= nWidth + s_nOffsetX; i++)
	{
		for (int j = 0; j <= nHeight; j += 2 * nScanLine)
		{
			pDC->BitBlt(0, j + s_nOffsetY, i, nScanLine, pMemDC,
				nWidth + s_nOffsetX - i, j + s_nOffsetY, SRCCOPY);

			int k = j + nScanLine;

			pDC->BitBlt(nWidth + s_nOffsetX - i, k + s_nOffsetY,
				i + s_nOffsetX, nScanLine, pMemDC, 0,
				k + s_nOffsetY, SRCCOPY);
		}
		DelayTime(1);
	}
}
Example #16
0
void Dynamixel::begin(int baud) {
	//TxDString("[DXL]start begin\r\n");

	afio_remap(AFIO_REMAP_USART1);//USART1 -> DXL
	afio_cfg_debug_ports(AFIO_DEBUG_FULL_SWJ_NO_NJRST);
#ifdef BOARD_CM900  //Engineering version case

	 gpio_set_mode(PORT_ENABLE_TXD, PIN_ENABLE_TXD, GPIO_OUTPUT_PP);
	 gpio_set_mode(PORT_ENABLE_RXD, PIN_ENABLE_RXD, GPIO_OUTPUT_PP);
	 gpio_write_bit(PORT_ENABLE_TXD, PIN_ENABLE_TXD, 0 );// TX Disable
	 gpio_write_bit(PORT_ENABLE_RXD, PIN_ENABLE_RXD, 1 );// RX Enable
#else
	 gpio_set_mode(PORT_TXRX_DIRECTION, PIN_TXRX_DIRECTION, GPIO_OUTPUT_PP);
	 gpio_write_bit(PORT_TXRX_DIRECTION, PIN_TXRX_DIRECTION, 0 );// RX Enable
#endif
	 timer_set_mode(TIMER2, TIMER_CH1, TIMER_OUTPUT_COMPARE);

	 timer_pause(TIMER2);

	 uint16 ovf = timer_get_reload(TIMER2);
	 timer_set_count(TIMER2, min(0, ovf));

	 timer_set_reload(TIMER2, 30000);//set overflow

	 ovf = timer_get_reload(TIMER2);
	 timer_set_compare(TIMER2, TIMER_CH1, min(1000, ovf));

	 timer_attach_interrupt(TIMER2, TIMER_CH1, TIM2_IRQHandler);

	 timer_generate_update(TIMER2);
	 timer_resume(TIMER2);

	 dxl_initialize(0, baud);
}
void center_model(model *m)
{
	vec_3D maximum, minimum;

	maximum.x = m->vertices[0];
	maximum.y = m->vertices[1];
	maximum.z = m->vertices[2];

	minimum.x = m->vertices[0];
	minimum.y = m->vertices[1];
	minimum.z = m->vertices[2];

	for(uint i = 0; i < m->n_vertices; i++){
		maximum.x = max(maximum.x,m->vertices[3*i + 0]);
		maximum.y = max(maximum.y,m->vertices[3*i + 1]);
		maximum.z = max(maximum.z,m->vertices[3*i + 2]);

		minimum.x = min(minimum.x, m->vertices[3*i + 0]);
		minimum.y = min(minimum.y, m->vertices[3*i + 1]);
		minimum.z = min(minimum.z, m->vertices[3*i + 2]);
	}

	for(uint i = 0; i < m->n_vertices; i++){
		m->vertices[3*i + 0] -= (maximum.x + minimum.x)/2;
		m->vertices[3*i + 1] -= (maximum.y + minimum.y)/2;
		m->vertices[3*i + 2] -= (maximum.z + minimum.z)/2;
	}
}
Example #18
0
// Projects a given star in 3D, and draws it to the screen. The star is drawn
// as a line, with a length proportional to the camera speed to give the
// illusion of non-instantaneous camera exposure. Draws the star in the
// provided colour.
void renderStar(Star star, float speed, int colour)
{
    float mn, mf; int xn, yn, xf, yf;

    // Don't draw a star if it is behind the camera! This should never occur
    // anyway, since we push them back when they pass the camera.
    if (star.z <= 0.0f) return;

    // Work out the perspective multipliers for the near and far points of the
    // line we will draw for the star. Also ensures that we don't draw nothing
    // if the camera is stopped.
    mn = Z_PLANE_DIST / star.z;
    mf = Z_PLANE_DIST / (star.z + max(speed * 2.0f, MIN_SPEED));

    // Make sure the line doesn't go off screen because apparently that crashes
    // the program occasionally.
    mn = min(mn, 0.5f / abs(star.x));
    mn = min(mn, 0.5f / abs(star.y));

    // Using the perspective multipliers, calculate the two (X, Y) coordinate
    // pairs for the star's line. Positions the line to be relative to the
    // centre of the screen, and stretches it.
    xn = (int) ((star.x * mn + 0.5f) * DISPLAY_WIDTH);
    yn = (int) ((star.y * mn + 0.5f) * DISPLAY_HEIGHT);
    xf = (int) ((star.x * mf + 0.5f) * DISPLAY_WIDTH);
    yf = (int) ((star.y * mf + 0.5f) * DISPLAY_HEIGHT);

    // If the line isn't completely off-screen, draw it.
    if (xf >= 0 && xf < DISPLAY_WIDTH && yf >= 0 && yf < DISPLAY_HEIGHT) {
        lcd_line(xn, yn, xf, yf, colour);
    }
}
Example #19
0
HRESULT CVTSStream::Read(PBYTE pbBuffer, DWORD dwBytesToRead, BOOL bAlign, LPDWORD pdwBytesRead)
{
    CAutoLock lck(&m_csLock);

    DWORD len = dwBytesToRead;
    BYTE* ptr = pbBuffer;

    while(len > 0)
    {
        BYTE buff[2048];
        if(!m_vob->Read(buff))
            break;

        int size = min(2048 - m_off, min(len, 2048));

        memcpy(ptr, &buff[m_off], size);

        m_off = (m_off + size)&2047;

        if(m_off > 0)
            m_vob->Seek(m_vob->GetPosition()-1);

        ptr += size;
        len -= size;
    }

    if(pdwBytesRead)
        *pdwBytesRead = ptr - pbBuffer;

    return S_OK;
}
Example #20
0
// Move the given window to the centre of the screen
// and bring it to the top.
void CentreWindow(HWND hwnd)
{
	RECT winrect, workrect;
	
	// Find how large the desktop work area is
	SystemParametersInfo(SPI_GETWORKAREA, 0, &workrect, 0);
	int workwidth = workrect.right -  workrect.left;
	int workheight = workrect.bottom - workrect.top;
	
	// And how big the window is
	GetWindowRect(hwnd, &winrect);
	int winwidth = winrect.right - winrect.left;
	int winheight = winrect.bottom - winrect.top;
	// Make sure it's not bigger than the work area
	winwidth = min(winwidth, workwidth);
	winheight = min(winheight, workheight);

	// Now centre it
	SetWindowPos(hwnd, 
		HWND_TOP,
		workrect.left + (workwidth-winwidth) / 2,
		workrect.top + (workheight-winheight) / 2,
		winwidth, winheight, 
		SWP_SHOWWINDOW);
	SetForegroundWindow(hwnd);
}
Example #21
0
File: 460.c Project: rofi93/UVA
int main(){
 int t,x,y,xx,yy,x1,y1,xx1,yy1,X,Y,XX,YY;
 int line = 0;

 scanf("%d", &t);
 while(t--){
  scanf("%d %d %d %d", &x, &y, &xx, &yy);
  scanf("%d %d %d %d", &x1, &y1, &xx1, &yy1);

  X = max(x, x1);
  Y = max(y, y1);
  XX = min(xx, xx1);
  YY = min(yy, yy1);

  if(line)
   printf("\n");
  line = 1;

  if(X < XX && Y < YY)
   printf("%d %d %d %d\n", X, Y, XX, YY);
  else
   printf("No Overlap\n");
 }

 return 0;
}
Example #22
0
static BOOL vrdpIntersectRectWithBounds (RECTL *prclIntersect,
                                         const RECTL *prcl,
                                         const VRDEORDERBOUNDS *pBounds)
{
    if (   prcl->left   < pBounds->pt2.x     /* left < bounds_right */
        && prcl->right  > pBounds->pt1.x     /* right < bounds_left */
        && prcl->top    < pBounds->pt2.y     /* top < bounds_bottom */
        && prcl->bottom > pBounds->pt1.y     /* bottom < bounds_top */
        )
    {
        /* There is intersection. */
        prclIntersect->left   = max(prcl->left, pBounds->pt1.x);
        prclIntersect->right  = min(prcl->right, pBounds->pt2.x);
        prclIntersect->top    = max(prcl->top, pBounds->pt1.y);
        prclIntersect->bottom = min(prcl->bottom, pBounds->pt2.y);

        Assert(prclIntersect->left < prclIntersect->right);
        Assert(prclIntersect->top < prclIntersect->bottom);

        return TRUE;
    }

    /* No intersection. */
    return FALSE;
}
int AlphaBetaPruning::AlphaBetaMin(Board &BBoard, int Depth, ePlayer eCurrentPlayer)
{
    Move m[8];
    int iNumberOfValidMoves = FillValidMoves(m, BBoard);
    int iRetValue;
    if (Depth == 0 || iNumberOfValidMoves == 0)
    {
        iRetValue = BBoard.Evaluate(eCurrentPlayer);
        goto ret;
    }

    int iMinValue = INF;
    for (int i = 0; i < iNumberOfValidMoves; i++)
    {
        Move &x = m[i];
        BBoard.ReflectMove(x, Opponent(eCurrentPlayer));
        iMinValue = min(iMinValue, AlphaBetaMax(BBoard, Depth-1, eCurrentPlayer));
        BBoard.RemoveMove(x);
        if (iMinValue <= m_iAlpha)
        {
            iRetValue = m_iAlpha;
            goto ret;
        }
        m_iBeta = min(m_iBeta, iMinValue);
    }
    iRetValue = iMinValue;
ret:
    return iRetValue;
}
Example #24
0
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%lf%lf", &v1[i], &v2[i]);
    qsort(v1+1, n, sizeof(double), cmp);
    qsort(v2+1, n, sizeof(double), cmp);
    double s1=0, s2=0, sol=0;
    int c=0, l=n;
    for(int i=n; i>=1; i--)
    {
        s1 += v1[i];
        c++;
        sol = max(sol,min(s1-c,s2-c));
        while(l>=1 && s2-c<s1-c)
        {
            s2 += v2[l];
            c++;
            sol = max(sol,min(s1-c,s2-c));
            l--;
        }
    }
    printf("%.4f", sol);
    return 0;
}
Example #25
0
// merge superpixels that are separated by a weak boundary
void merge( uint *S, uint h, uint w, float *E, float thr ) {
  // compute m and min for each region
  uint x; uint m=0; for( x=0; x<w*h; x++ ) m=S[x]>m ? S[x] : m; m++;
  float *es=new float[m]; for( x=0; x<m; x++ ) es[x]=1000;
  for( x=0; x<w*h; x++ ) es[S[x]]=min(E[x],es[S[x]]);
  // check for regions to merge and compute label mapping
  uint *map = new uint[m]();
  for( x=0; x<w; x++ ) for( uint y=0; y<h; y++ ) if( S[x*h+y]==0 ) {
    uint i, j, s, s1, s2, k=0, U[8]; NEIGHBORS8(S);
    for( i=0; i<8; i++ ) if( (s=N[i])!=0 ) {
      for( j=0; j<k; j++ ) if(s==U[j]) break; if(j==k) U[k++]=s;
    }
    for( i=0; i<k-1; i++ ) for( j=i+1; j<k; j++ ) {
      s1=U[i]; while(map[s1]) s1=map[s1];
      s2=U[j]; while(map[s2]) s2=map[s2];
      if( s1!=s2 && E[x*h+y]-min(es[s1],es[s2])<thr ) {
        es[s1]=es[s2]=min(es[s1],es[s2]);
        if( s1<s2 ) { s=s1; s1=U[j]; } else { s=s2; s1=U[i]; }
        while(map[s1]) { s2=map[s1]; map[s1]=s; s1=s2; } map[s1]=s;
      }
    }
  }
  // perform mapping and remove obsolete boundaries
  uint m1=1; for( uint s=1; s<m; s++ ) map[s] = map[s] ? map[map[s]] : m1++;
  for( x=0; x<w*h; x++ ) if(S[x]) S[x]=map[S[x]];
  for( x=0; x<w; x++ ) for( uint y=0; y<h; y++ ) if( S[x*h+y]==0 ) {
    uint i, s=0; NEIGHBORS8(S); for(i=0; i<8; i++) if(N[i]) { s=N[i]; break; }
    for( i; i<8; i++ ) if(N[i] && N[i]!=s) break; if(i==8) S[x*h+y]=s;
  }
  delete [] es; delete [] map;
}
Example #26
0
void StatState::draw(sf::RenderWindow &window){

    window.draw(woodSprite);
    window.draw(resultsSprite);

    window.draw(player1Score);

    whitePiece.setPosition(27, 320);
    for(int i = 0; i < min(chipClock.getElapsedTime().asSeconds() * 15,(float)whiteChips); ++i){
        whitePiece.move(18,0);
        window.draw(whitePiece);
    }

    window.draw(player2Score);

    blackPiece.setPosition(27, 510);
    for(int i = 0; i < min(chipClock.getElapsedTime().asSeconds() * 15,(float)blackChips); ++i){
        blackPiece.move(18,0);
        window.draw(blackPiece);
    }

    window.draw(winner);
    window.draw(mainMenuButton);

}
Example #27
0
void fourier_base(const Array<COMPLEX,1> &in, Array<COMPLEX,1> &out, bool direct) {
 
  // !!!! L must always be the number of time bins !!!!
  const int L( (direct ? in.extent(0) : out.extent(0)) );
  //const int L(max(in.extent(0),out.extent(0)));  <-- bug

  fftw_complex *inFFT, *outFFT;
  fftw_plan p;
  inFFT = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * L);
  outFFT = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * L);

  const COMPLEX * restrict in_ptr = in.dataFirst();
  COMPLEX * restrict out_ptr = out.dataFirst();
  const int imax(min(L,in.extent(0)));
  for (int i =0; i<imax; ++i) { inFFT[i][0] = real(in_ptr[i]); inFFT[i][1] = imag(in_ptr[i]);}
  for (int i =imax; i<L; ++i) { inFFT[i][0] = 0; inFFT[i][1] = 0;}

  p = fftw_plan_dft_1d(L, inFFT, outFFT, (direct ? FFTW_BACKWARD : FFTW_FORWARD), FFTW_ESTIMATE);
  fftw_execute(p); 

  const int jmax(min(L,out.extent(0)));
  for (int j =0; j<jmax; ++j)  {out_ptr[j] = COMPLEX(outFFT[j][0] ,outFFT[j][1]);}

  fftw_destroy_plan(p); 
  fftw_free(inFFT); fftw_free(outFFT);
}
Example #28
0
/*===========================================================================*
 *                             fs_rdlink                                     *
 *===========================================================================*/
int fs_rdlink()
{
  block_t b;                   /* block containing link text */
  struct buf *bp;              /* buffer containing link text */
  register struct inode *rip;  /* target inode */
  register int r;              /* return value */
  size_t copylen;
  
  copylen = min( (size_t) fs_m_in.REQ_MEM_SIZE, UMAX_FILE_POS);

  /* Temporarily open the file. */
  if( (rip = get_inode(fs_dev, (ino_t) fs_m_in.REQ_INODE_NR)) == NULL)
	  return(EINVAL);

  if(!S_ISLNK(rip->i_mode))
	  r = EACCES;
  else if ((b = read_map(rip, (off_t) 0)) == NO_BLOCK)
	r = EIO;
  else {
	/* Passed all checks */
	/* We can safely cast to unsigned, because copylen is guaranteed to be
	   below max file size */
	copylen = min( copylen, (unsigned) rip->i_size);
	bp = get_block(rip->i_dev, b, NORMAL);
	r = sys_safecopyto(VFS_PROC_NR, (cp_grant_id_t) fs_m_in.REQ_GRANT,
			   (vir_bytes) 0, (vir_bytes) b_data(bp),
	  		   (size_t) copylen);
	put_block(bp, DIRECTORY_BLOCK);
	if (r == OK)
		fs_m_out.RES_NBYTES = copylen;
  }
  
  put_inode(rip);
  return(r);
}
Example #29
0
boolean Thought_Bubble::dump(output_stream &stream, boolean just_prepare, boolean , boolean ) {
   if (just_prepare) return(FALSE);
   int dump_index = about_to_dump(this,stream); // rewritten on 020802
	if (dump_index < 0) return(FALSE); // new on 051099
#if TT_DEBUG_ON
	if (tt_debug_mode == 160299 && !tt_dumping_to_test_equality_or_describe) {
		print_spaces(min(tt_debug_dump_depth,max_debug_depth),tt_error_file());
		tt_error_file() << "About to dump ";
		print(tt_error_file());
		tt_error_file() << endl;
		tt_debug_dump_depth++;
	};
#endif
   if (cubby != NULL) { // && cubby->pointer_to_leader() == this) {
		// changed to top_level_dump on 060201 since there should be no connections between stuff in the thought bubble and outside 
      cubby->top_level_dump(stream);
	} else if (robot->pointer_to_body() != NULL) { // a bit of a hack to distinguish trained robots with empty thought bubbles from untrained ones
		stream.put(NOTHING_MARKER);
	} else {
		stream.put((char) NONE_GIVEN);
	};
#if TT_DEBUG_ON
	if (tt_debug_mode == 160299 && !tt_dumping_to_test_equality_or_describe) {
		print_spaces(min(tt_debug_dump_depth,max_debug_depth),tt_error_file());
		tt_error_file() << "Finished dumping ";
		print(tt_error_file());
		tt_error_file() << endl;
		tt_debug_dump_depth--;
	};
#endif
	return(TRUE);
};
Example #30
0
/* Get a block of data from the input.  If buffer is NULL, just return the amount
 * that would be read. */
int RageSound::GetData( char *pBuffer, int iFrames )
{
	if( m_Param.m_LengthSeconds != -1 )
	{
		/* We have a length; only read up to the end. */
		const float LastSecond = m_Param.m_StartSecond + m_Param.m_LengthSeconds;
		int FramesToRead = int(LastSecond*samplerate()) - m_iDecodePosition;

		/* If it's negative, we're past the end, so cap it at 0. Don't read
		 * more than size. */
		iFrames = clamp( FramesToRead, 0, iFrames );
	}

	int iGot;
	if( m_iDecodePosition < 0 )
	{
		/* We havn't *really* started playing yet, so just feed silence.  How
		 * many more bytes of silence do we need? */
		iGot = -m_iDecodePosition;
		iGot = min( iGot, iFrames );
		if( pBuffer )
			memset( pBuffer, 0, iGot*framesize );
	} else {
		/* Feed data out of our streaming buffer. */
		ASSERT( m_pSource );
		iGot = min( int(m_DataBuffer.num_readable()/framesize), iFrames );
		if( pBuffer )
			m_DataBuffer.read( pBuffer, iGot*framesize );
	}

	return iGot;
}