Beispiel #1
0
/*
 *------------------------------------------------------
 *	It will return TRUE if the point(x,y) is inside
 *	the polygon and FALSE otherwise. Assumes that
 *	the (x,y) input point received is already
 * 	expressed in the polygon coordinates
 *------------------------------------------------------
 */
int
pointInPoly2D( int whichFace, double x, double y)
{
	int nverts, i;
	Point2D p, v, v0, v1;
	double x0,y0,z0,x1,y1,z1,z;
	
	nverts = faces[whichFace].nverts;
	for(i = 0; i < nverts; i++){
		x0 = vert[faces[whichFace].v[i]].pos.x;
		y0 = vert[faces[whichFace].v[i]].pos.y;
		z0 = vert[faces[whichFace].v[i]].pos.z;
		x1 = vert[faces[whichFace].v[(i+1)%nverts]].pos.x;
		y1 = vert[faces[whichFace].v[(i+1)%nverts]].pos.y;
		z1 = vert[faces[whichFace].v[(i+1)%nverts]].pos.z;
		mapOntoPolySpace(whichFace, x0, y0, z0, &v0);
		mapOntoPolySpace(whichFace, x1, y1, z1, &v1);
		
		p.x = x - v0.x;
		p.y = y - v0.y;
		
		v.x = v1.x - v0.x;
		v.y = v1.y - v0.y;
		
		z = v.x * p.y - p.x * v.y;
		if ( Negative(z) /*z < 0.0*/ ) return FALSE;
	}
	return TRUE;
}
void CTimeWrapper :: PrintDelta( char *p_pcOutput )
{
    int sec;
    int ms;
    int us;

    if ( Negative() )
    {
        int diffUs = -tv_usec;

        sec = -tv_sec;
        ms = diffUs / 1000 + sec * 1000;
        us = diffUs % 1000;

        sprintf( p_pcOutput, "-%i.%.3i", ms, us );
    }
    else
    {
        sec = tv_sec;
        ms = tv_usec / 1000 + sec * 1000;
        us = tv_usec % 1000;

        sprintf( p_pcOutput, "%i.%.3i", ms, us );
    }
}
Beispiel #3
0
//-----------------------------------------------------------------------------
// TestMatrixNegative
//-----------------------------------------------------------------------------
bool TestMatrixNegative()
{
   Matrix A("1,2,3;4,5,6;7,8,9");
   Matrix C;
   Negative( A, C );
   Matrix B("-1,-2,-3;-4,-5,-6;-7,-8,-9");

   return ApproxEqual(B,C,TOLERANCE);
}
// Checks if a point is inside a triangle
bool PointInTriangle(const Vector3 &p, const Vector3 &v0, 
        const Vector3 &v1, const Vector3 &v2)
{
    // Get edges
    Vector3 e0 = v2 - v1;
    Vector3 e1 = v0 - v2;
    Vector3 e2 = v1 - v0;
    // Test if point is in the same plane as the triangle
    Vector3 n = Cross(e0, e1);
    if (!Equal(Dot(n, v0), Dot(n, p))) return false;
    // Test if point is in correct side of each edge
    Vector3 t0 = Cross(e2, p - v0);
    Vector3 t1 = Cross(e0, p - v1);
    Vector3 t2 = Cross(e1, p - v2);
    double s0 = Dot(t0, t1); 
    double s1 = Dot(t0, t2);
    if (Negative(s0) || Negative(s1)) return false;
    else return true;
}
Beispiel #5
0
/*
 *------------------------------------------------------
 *	It will return TRUE if the cell is inside
 *	the polygon and FALSE otherwise. If the flag
 * 	'currentPosition' is TRUE, then we test the
 *	currentPosition of the cell; if it is FALSE
 *	we test the previous position of the cell
 *------------------------------------------------------
 */
int
cellInPoly( CELL *c, int currentPosition )
{
	
	int nverts, whichFace;
	int i;
	Point2D p, v, q, v0, v1;
	double x0, y0, z0, x1, y1, z1, z;
	
	whichFace = c->whichFace;
	nverts = faces[whichFace].nverts;
	
	if ( currentPosition )
		mapOntoPolySpace(whichFace, c->x, c->y, c->z, &q);
	else mapOntoPolySpace(whichFace, c->xp, c->yp, c->zp, &q);
	
	for(i = 0; i < nverts; i++){
		x0 = vert[faces[whichFace].v[i]].pos.x;
		y0 = vert[faces[whichFace].v[i]].pos.y;
		z0 = vert[faces[whichFace].v[i]].pos.z;
		x1 = vert[faces[whichFace].v[(i+1)%nverts]].pos.x;
		y1 = vert[faces[whichFace].v[(i+1)%nverts]].pos.y;
		z1 = vert[faces[whichFace].v[(i+1)%nverts]].pos.z;
		mapOntoPolySpace(whichFace, x0, y0, z0, &v0);
		mapOntoPolySpace(whichFace, x1, y1, z1, &v1);
		
		p.x = q.x - v0.x;
		p.y = q.y - v0.y;
		
		v.x = v1.x - v0.x;
		v.y = v1.y - v0.y;
		
		z = v.x * p.y - p.x * v.y;
		
		if ( Negative(z) ){
			if (  currentPosition )
				fprintf( stderr, "\ncell in poly Z = %lg\n", z );
			else fprintf( stderr, "\ncell in poly previous Z = %lg\n", z );
			return FALSE;
		}
	}
	return TRUE;
}
BOOL QuoteTableCtrlGeneralSort::HandleRecvData(AnsGeneralSortEx* pData, int nIndex)
{
	GeneralSortData* pReportTotalData = (GeneralSortData*)pData->m_prptData;

	DeleteStock();
	int nDataNumber = 0;
	StockUserInfo* pStockInfo;
	long lMinsize = min(m_sDisplayRow, pData->m_nSize);
	for (int i = 0; i < lMinsize; i++)
	{
 		pStockInfo = GetStockUserInfo(pReportTotalData[i].m_ciStockCode.m_cCode,
 			pReportTotalData[i].m_ciStockCode.m_cCodeType);
		if ( pStockInfo != NULL)
		{
				AddStock(pStockInfo);
				nDataNumber++;
		}
	}
	if (nDataNumber < 1)
		return FALSE;
	
	InitRowData();
	//DrawTitle();
	long nUnit;
	short nDecimal;
	long  lClose;
	char  strText[64];
	int col;
	CGridCell* pCell;
	int nFixedRows = 1;
	for(int i = 0; i < nDataNumber; i++)
	{
	 
		pStockInfo = m_pStock.GetAt(i);

        lClose	 = pStockInfo->m_lPrevClose;
		nUnit    = 1000;
	    nDecimal = 2;
		
		//特殊处理价格
		BOOL bNegative = FALSE;
		#ifdef Support_XHX_Dll
			bNegative = MakeNegativeIndex(pStockInfo->m_ciStockCode.m_cCodeType);
		#endif

		col = 0;	
		pCell = (CGridCell*)GetCell(nFixedRows+i, col);
		if( pCell == NULL )
			continue;
		SetFixedData(nFixedRows+i,col,pCell,(StockUserInfo*)pStockInfo, -1, TRUE);
		
		// 价格
		if ( Negative(pReportTotalData[i].m_lNewPrice,bNegative) == 0 )
			CGeneralHelper::LongToString(lClose, lClose, nUnit, nDecimal, strText);
		else
			CGeneralHelper::LongToString(Negative(pReportTotalData[i].m_lNewPrice,bNegative), lClose, nUnit, nDecimal, strText);
		UpdateCellText(nFixedRows+i,1,strText,GRID_DATA_UPDATE_DEFAULT);
		
		// 排名值

 		switch(nIndex)
		{		     
		case 1:   // 5分钟涨幅排名
		case 4:   // 5分钟跌幅排名
			{
				long lNewClose = 0;
				if((pReportTotalData[i].m_lValue*((g_bOldMode)?1:10000) + 10000) > 0)
				{
					lNewClose = (long)(Negative(pReportTotalData[i].m_lNewPrice,bNegative) * 10000 /
						(pReportTotalData[i].m_lValue*((g_bOldMode)?1:10000) + 10000));
				}
				/*
				if(lNewClose > 0)
				{
					pStockInfo->m_lPrevClose = lNewClose;
				}
				*/
			}
			CGeneralHelper::LongToString((long)(pReportTotalData[i].m_lValue*((g_bOldMode)?1:10000)),0,100,nDecimal,strText, 0x0400);  
			break;

		case 2:   // 今日委比前六名
		case 5:   // 今日委比后六名
		case 6:   // 今日震幅排名
			CGeneralHelper::LongToString((long)(pReportTotalData[i].m_lValue*((g_bOldMode)?1:10000)),0,100,2,strText, 0x0400);  
			break;

		case 0:   // 今日涨幅排名
		case 3:   // 今日跌幅排名
			{
				CGeneralHelper::LongToString((long)(pReportTotalData[i].m_lValue*((g_bOldMode)?1:10000)),0,100,nDecimal,strText, 0x0400);  
				break;			
			}
			
		case 7:   // 今日量比排名
			CGeneralHelper::LongToString((long)(pReportTotalData[i].m_lValue),0,100,2,strText);
			break;
		case 8:   // 今日总金额排名				 
			CGeneralHelper::LongToString((long)(pReportTotalData[i].m_lValue),0,100,2,strText); // 服务器除以100传过来的机会
			break;
		default:
		    break;
		}
		UpdateCellText(nFixedRows+i,2,strText,GRID_DATA_UPDATE_DEFAULT );
	}
	Invalidate();
	return TRUE;
}
HRESULT ArmEmulator::Execute( CLR_UINT64 steps )
{
    TINYCLR_HEADER();

    //
    // Prepare Interop detours.
    //
    {
        for(AddressToHandlerMapIter it = m_callInterop.begin(); it != m_callInterop.end(); it++)
        {
            ApplyInterop( it->second );
        }
    }

    m_fStopExecution = false;

    for(CLR_UINT64 i=0; i<steps; i++)
    {
        CLR_UINT32 pc = m_pc;
        CLR_UINT32 instruction;
        bool       fRes;

        //
        // Special case: if we pass by the reset vector, reload the interop breakpoints.
        //
        if(pc == 0)
        {
            for(AddressToHandlerMapIter it = m_callInterop.begin(); it != m_callInterop.end(); it++)
            {
                ApplyInterop( it->second );
            }
        }

        {
            if(MemoryLoad( pc, instruction, DATATYPE_U4 ) == false)
            {
                CLR_Debug::Printf( "FETCH ABORT at 0x%08x %I64d\r\n", pc, i );

                TINYCLR_SET_AND_LEAVE(CLR_E_FAIL)
            }

       }

#if defined(ARMEMULATOR_MONITOR_CALLS)
        if(m_fMonitorCalls)
        {
            CLR_RT_AddressToSymbolMapIter it;
            size_t                        pos = m_callQueue.size();
            CLR_UINT32                    sp  = m_registers[ ArmProcessor::c_register_sp ];

            for(size_t pos2=pos; pos2-- > 0; )
            {
                TrackCall& tc = m_callQueue[ pos2 ];

                if((tc.m_lr == pc && tc.m_sp == sp) || (tc.m_sp && tc.m_sp < sp))
                {
                    while(pos-- > pos2)
                    {
                        TrackCall& tc2 = m_callQueue[ pos ];

                        tc2.m_te.End( this );

                        CLR_Debug::Printf( "%*s<<<< CALL %S (%s)\r\n", pos, "", tc2.m_name->c_str(), tc2.m_te.ToString() );

                        m_callQueue.pop_back();
                    }
                    pos++;
                }
                else
                {
                    break;
                }
            }

            it = m_symdef_Inverse.find( pc );
            if(it != m_symdef_Inverse.end())
            {
                while(true)
                {
                    if(it->second == L"NoClearZI_ER_RAM") break;
                    if(it->second == L"ClearZI_ER_RAM"  ) break;
                    if(it->second == L"ARM_Vectors"     ) break;

                    m_callQueue.resize( pos + 1 );

                    TrackCall& tc = m_callQueue[ pos ];

                    tc.m_pc    = pc;
                    tc.m_lr    = m_registers[ ArmProcessor::c_register_lr ];
                    tc.m_sp    = sp;
                    tc.m_name  = &it->second;

                    tc.m_te.Start( this );

                    CLR_Debug::Printf( "%*s>>>> CALL %S\r\n", pos, "", tc.m_name->c_str() );
                    break;
                }
            }
        }
#endif

        //--//--//--//--//--//--//--//--//--//--//--//

        if(instruction == c_InteropOpcode)
        {
            //
            // Copy, not reference, the entry can be removed from the map by the interop code.
            //
            TrackInterop ti = m_callInterop[ pc ];

            if(m_fStopExecution)
            {
                break;
            }

            if(ti.m_call)
            {
                if((this->*(ti.m_call))()) continue;

                instruction = ti.m_op;
            }

            if(m_fStopExecution)
            {
                break;
            }
        }

        //--//--//--//--//--//--//--//--//--//--//--//

#if defined(ARMEMULATOR_MONITOR_OPCODES)
        if(m_fMonitorOpcodes)
        {
            ArmProcessor::Opcode op;
            char                 rgBuf[ 128 ];

            op.InitText( rgBuf, MAXSTRLEN(rgBuf), pc );

            if(op.Decode( instruction ) == false)
            {
                CLR_Debug::Printf( "DECODE ABORT at 0x%08x %I64d\r\n", pc, i );

                TINYCLR_SET_AND_LEAVE(CLR_E_FAIL)
            }

            fRes = op.CheckConditions( *this );

            op.AppendText( "%-9I64d %-9I64d 0x%08x:  %08x  %c%c%c%c %c ", i, m_clockTicks, pc, instruction, Negative() ? 'N' : '-', Zero() ? 'Z' : '-', Carry() ? 'C' : '-', Overflow() ? 'V' : '-', fRes ? ' ' : '*' );

            op.Print();

            CLR_Debug::Printf( "%s\r\n", rgBuf );
        }
Beispiel #8
0
/*
 *---------------------------------------------------------
 *	This routine will return the edge index
 *	through which the cell was pushed across.
 *	The variable 'direction' will be TRUE if
 *	the edge was found from vstart->vend and FALSE if
 *	the edge is found from vend->vstart
 *---------------------------------------------------------
 */
int cellInPolyAndEdge( CELL *c, int *direction, Point3D *intersec3D, double *t, int prevEdge )
{
	
	int nverts, whichFace;
	int i, whichEdge, we[3], dir[3], it[3];
	Point2D p, v, qCurrent, qPrevious, intersec[3];
	Point2D v0, v1;
	Point3D p0, p1;
	double z[3], tt[3];
	
	whichFace = c->whichFace;
	nverts = faces[whichFace].nverts;
	/*
	 * Implementation dependent code! Assumes that we are
	 * always working with triangles!
	 */
	if ( nverts != 3 )
		errorMsg("Don't know how to deal with non-triangular faces (relax.c)!");
	/* 
	 * Map the current and previous cell's position to the
	 * 2D space of the face. I want to compute
	 * the intersection between a line defined by the
	 * previous and current cell's position and the edge
	 */
	mapOntoPolySpace(whichFace, c->x, c->y, c->z, &qCurrent );
	mapOntoPolySpace(whichFace, c->xp, c->yp, c->zp, &qPrevious );
	
#ifdef VERBOSE
	fprintf( stderr, "qPrevious [X] = %f [Y] = %f\n", qPrevious.x, qPrevious.y );
	fprintf( stderr, "qCurrent [X] = %f [Y] = %f\n", qCurrent.x, qCurrent.y );
#endif
	
	for(i = 0; i < nverts; i++)
	{
		we[i] = -1;
		tt[i] = -1;
		it[i] = -1;
		dir[i] = -1;
		p0.x = vert[faces[whichFace].v[i]].pos.x;
		p0.y = vert[faces[whichFace].v[i]].pos.y;
		p0.z = vert[faces[whichFace].v[i]].pos.z;
		p1.x = vert[faces[whichFace].v[(i+1)%nverts]].pos.x;
		p1.y = vert[faces[whichFace].v[(i+1)%nverts]].pos.y;
		p1.z = vert[faces[whichFace].v[(i+1)%nverts]].pos.z;
		
		mapOntoPolySpace(whichFace, p0.x, p0.y, p0.z, &v0);
		mapOntoPolySpace(whichFace, p1.x, p1.y, p1.z, &v1);
		
#ifdef VERBOSE
		fprintf( stderr, "[X0] = %f [Y0] = %f [Z0] = %f\n", p0.x, p0.y, p0.z );
		fprintf( stderr, "[X1] = %f [Y1] = %f [Z1] = %f\n", p1.x, p1.y, p1.z );
		fprintf( stderr, "v0 [X] = %f [Y] = %f\n", v0.x, v0.y );
		fprintf( stderr, "v1 [X] = %f [Y] = %f\n", v1.x, v1.y );
#endif
		
		p.x = qCurrent.x - v0.x;
		p.y = qCurrent.y - v0.y;
		v.x = v1.x - v0.x;
		v.y = v1.y - v0.y;
		
		z[i] = v.x * p.y - p.x * v.y;
		
		if (  Negative(z[i]) )
		{
			/* find which edge is this */
			we[i] = findEdgeForVert( faces[whichFace].v[i],
									faces[whichFace].v[(i+1)%nverts],
									&(dir[i]) );
			/*
			 * The difference between 'linesIntersect' and 'goodLinesIntersect' is that
			 * 'goodLinesIntersect' does not do a bounding box test, whereas 'linesIntersect'
			 * does. I have the 2 versions since I thought that sometimes, due to
			 * rounding off, the bounding box test was giving me wrong results.
			 */
			/*it[i] = goodLinesIntersect( qPrevious, qCurrent, v0, v1, &(intersec[i]), &(tt[i]) );*/
			it[i] = linesIntersect( qPrevious, qCurrent, v0, v1, &(intersec[i]), &(tt[i]) );
		}
	}
	/*
	 * If all z are greater or equal to 0.0, then the cell
	 * is inside the polygon. Otherwise we proceed to
	 * find out which edge it crossed
	 */
	/*if ( z[0] >= 0.0 && z[1] >= 0.0 && z[2] >= 0.0 ) return -1;*/
	if ( GreaterEqualZero(z[0]) && GreaterEqualZero(z[1]) && GreaterEqualZero(z[2]) )
		return -1;
	
	else{
#ifdef VERBOSE
		/*fprintf( stderr, "qCurrent [X] = %f [Y] = %f\n", qCurrent.x, qCurrent.y );
		 fprintf( stderr, "qPrevious [X] = %f [Y] = %f\n", qPrevious.x, qPrevious.y );
		 fprintf( stderr, "\nGeometry vertices for face %d\n", whichFace );*/
		fprintf( stderr, "\nCell NOT inside polygon!\n");
#endif
		
		for(i = 0; i < nverts; i++)
		{
			if ( Negative( z[i] ) /*z[i] < 0.0*/ && it[i] == DO_INTERSECT )
			{
				
#ifdef VERBOSE
				
				fprintf( stderr, "intersec [X] = %f [Y] = %f\n", intersec[i].x, intersec[i].y );
				fprintf( stderr, "[%d] z = %f e = %d dir = %d\n", i, z[i], we[i], dir[i] );
				fprintf( stderr, "intersect = %d t = %lg\n", it[i], tt[i]);
#endif
				/*	
				 * I have to make sure here that the just found intersection
				 * is not the same one as before
				 */
				if ( prevEdge != we[i] ){
					mapFromPolySpace(whichFace, intersec[i].x, intersec[i].y, intersec3D );
					*t = tt[i];
					*direction = dir[i];
#ifdef VERBOSE
					fprintf( stderr, "2D: x = %f y = %f\n", intersec[i].x, intersec[i].y);
					fprintf( stderr, "3D: x = %f y = %f z = %f\n", intersec3D->x, intersec3D->y, intersec3D->z );
#endif
					return we[i];
				}
			}
		}
		
		/*
		 * If I have reached this point we have a problem.
		 * Before leaving the program I am printing which
		 * should be useful info
		 */
		for(i = 0; i < nverts; i++)
		{
			//fprintf( stderr, "[%d] z = %lg t = %lg intersec = %d e = %d dir = %d\n",
				//	i, z[i], tt[i], it[i], we[i],dir[i] );
			if ( we[i] != -1 ){
				//fprintf( stderr, "edge = %d pf = %d nf = %d cell = %d\n",
					//	we[i], edges[we[i]].pf, edges[we[i]].nf, c->ctype );
				/*fprintf( stderr, "matrix for next->previous face:\n");
				 printMatrix( edges[we[i]].np );
				 fprintf( stderr, "matrix for previous->next face:\n");
				 printMatrix( edges[we[i]].pn );*/
			}
		}
		//fprintf( stderr, "For face %d we have the neighboring faces:\n", whichFace );
		for(i = 0; i < faces[whichFace].nPrimFaces; i++)
		{
			//fprintf( stderr, "[%d] angle = %f\n",
				//	faces[whichFace].primFaces[i],
				//	rad2deg(faces[whichFace].rotAngles[i]) );
		}
        
		return -2;
		//errorMsg("If I reached this point I could not find an edge to move cells!");
	}
}