Esempio n. 1
0
IntersectionData ofxIntersection::PlaneTriangleIntersection(IsPlane& plane, IsTriangle& triangle){
    
    IntersectionData idata;
    ofVec3f tp0=triangle.getP0();
    ofVec3f tp1=triangle.getP1();
    ofVec3f tp2=triangle.getP2();
    
    float dist1=PointPlaneDistance(tp0, plane);
    float dist2=PointPlaneDistance(tp1, plane);
    float dist3=PointPlaneDistance(tp2, plane);
    
    int pos1=ofSign(dist1);
    int pos2=ofSign(dist2);
    int pos3=ofSign(dist3);
    
    if(pos1==pos2 && pos1==pos3){
        idata.isIntersection=false;
        return idata;
    };

    vector<ofPoint>ispoints;
    bool bintersects=false;
    ofVec3f ip;
    
    if(pos1!=pos2){
        ip=LinePlaneIntersectionFast(tp0, tp1, plane);
        if(!containsValue(&ispoints, ip)){
            ispoints.push_back(ip);
        };
    }
    if(pos2!=pos3){
        ip=LinePlaneIntersectionFast(tp1, tp2, plane);
        if(!containsValue(&ispoints, ip)){
            ispoints.push_back(ip);
        };
    }
    if(pos3!=pos1){
        ip=LinePlaneIntersectionFast(tp2, tp0, plane);
        if(!containsValue(&ispoints, ip)){
            ispoints.push_back(ip);
        };
    }
    
    idata.isIntersection=true;
    idata.pos.set(ispoints.at(0));
    
    if(ispoints.size()==2){
        idata.dir.set(ispoints.at(1));
        idata.dir-=idata.pos;
        idata.dist=idata.dir.length();
    }
    
    return idata;

}
Esempio n. 2
0
static bool containsValue(Afy::Value const & pV, long pValue)
{
	switch (pV.type)
	{
		case Afy::VT_INT: return (int32_t)pValue == pV.i;
		case Afy::VT_COLLECTION: 
			if (pV.isNav()) {
				if (pV.nav) { Value const * lNext; for (lNext = pV.nav->navigate(GO_FIRST); NULL != lNext; lNext = pV.nav->navigate(GO_NEXT)) { if (containsValue(*lNext, pValue)) return true; } } return false;
			} else {
				{ size_t i; for (i = 0; i < pV.length; i++) if (containsValue(pV.varray[i], pValue)) return true; } return false;
			}
		default: return false;
	}
}
Esempio n. 3
0
MAPID valueMap::add(JS::HandleValue val, int mark)
{
    int ret = containsValue(val);
    if (ret != 0)
    {
        return ret;
    }

    //stHeapValue* p = new stHeapValue(val);
	/*stHeapValue p(val);
	p.mark = (char)mark;*/


	int J = 0;
	/*list<int>::iterator itBegin = lstFree.begin();
	if (itBegin != lstFree.end())
	{
		J = *itBegin;
		lstFree.erase(itBegin);
	}
	else*/
	// 2015.Nov.3rd
	// 先改成不回收利用
	// 脚本的成员函数如 Update 如果 ID 是使用回收来的,当时可能还存在于 idFunRet
	// 再次 callFunctionValue 时会把这个 ID 给移除掉
	// 可能是导致 调用到其他脚本的 Update,错乱了
	{
		J = valueMap::index++;
	}

	mmap_newelement(p, J, val, mark);

	Assert(!valueMap::tracing);
	VALUEMAPIT itJ = mmap_find(J);
	Assert(mit_invalid(itJ));

	// 1)
	mmap_add(J, p);

	// 2)
	Assert(!GCing);
    vmap_add(p->heapValue.get().asRawBits(), J);
    return J;
}
Esempio n. 4
0
MAPID valueMap::getID(const JS::Value& val, bool autoAdd)
{
//     VALUEMAPIT it = mMap.begin();
//     for (; it != mMap.end(); it++)
//     {
//         if (it->second.heapValue.get() == val)
//             return it->first;
//     }

    if (autoAdd)
    {
        JS::RootedValue rval(g_cx, val);
        return valueMap::add(rval, 10);
    }
	else
	{
		return containsValue(val);
	}
    return 0;
}
Esempio n. 5
0
MAPID valueMap::add(JS::HandleValue val, int mark)
{
    int ret = containsValue(val);
    if (ret != 0)
    {
        return ret;
    }

    //stHeapValue* p = new stHeapValue(val);
	stHeapValue p(val);
	p.mark = (char)mark;

	int J = 0;
	/*list<int>::iterator itBegin = lstFree.begin();
	if (itBegin != lstFree.end())
	{
		J = *itBegin;
		lstFree.erase(itBegin);
	}
	else*/
	// 2015.Nov.3rd
	// 先改成不回收利用
	// 脚本的成员函数如 Update 如果 ID 是使用回收来的,当时可能还存在于 idFunRet
	// 再次 callFunctionValue 时会把这个 ID 给移除掉
	// 可能是导致 调用到其他脚本的 Update,错乱了
	{
		J = valueMap::index++;
	}

	Assert(!valueMap::tracing);
	Assert(mMap.find(J) == mMap.end());

	// 1)
	mMap.insert(VALUEMAP::value_type(J, p));
	//mMap[valueMap::index] = p;

	// 2)
	VMap.insert(VMAP::value_type(p.heapValue.get().asRawBits(), J));
    
    return J;
}
Esempio n. 6
0
int main(int argc , char **argv ) 
{ struct TreeMap *t ;
  char *x ;
  char *input[20] ;
  int i ;
  char *find ;
  char *tmp ;
  int tmp___0 ;
  int len ;
  int tmp___1 ;
  int tmp___2 ;
  char *tkn ;
  int tmp___3 ;
  int len___0 ;
  int tmp___4 ;
  int tmp___5 ;
  int tmp___6 ;
  struct Entry *root ;
  int res ;
  int tmp___7 ;

  {
  if (argc < 2) {
    return (0);
  } else {

  }
  newTreeMap(& t);
  x = *(argv + 1);
  i = 0;
  tmp___0 = strtok(x, " ");
  tmp = (char *)tmp___0;
  tmp___1 = strlen(tmp);
  len = tmp___1 + 1;
  tmp___2 = malloc((unsigned int )len * sizeof(char ));
  find = (char *)tmp___2;
  strcpy(find, tmp);
  tmp___3 = strtok((void *)0, " ");
  tkn = (char *)tmp___3;
  while ((unsigned int )tkn != (unsigned int )((void *)0)) {
    if ((int )*(tkn + 0) == 34) {
      continue;
    } else {

    }
    tmp___4 = strlen(x);
    len___0 = tmp___4 + 1;
    tmp___5 = malloc((unsigned int )len___0 * sizeof(char ));
    input[i] = (char *)tmp___5;
    strcpy(input[i], tkn);
    i ++;
    tmp___6 = strtok((void *)0, " ");
    tkn = (char *)tmp___6;
  }
  val_i = 0;
  root = t->root;
  buildTree(i, input, & root);
  tmp___7 = containsValue(root, find);
  res = tmp___7;
  printf("%d", res);
  return (0);
}
}
Esempio n. 7
0
bool TestCustom59::runProgram(ISession & pSession, TestCustom59::TDeadlockProgram const & pProgram, char const * pTitle, bool pDeadlockExpected)
{
	bool lSuccess = true;
	getLogger().out() << std::endl << "Program: " << pTitle << std::endl;

	// Create 2 pins for this program.
	CREATEPIN(&pSession, &mPID1, NULL, 0); getLogger().out() << "pin1: " << std::hex << mPID1.pid << std::endl;
	CREATEPIN(&pSession, &mPID2, NULL, 0); getLogger().out() << "pin2: " << std::hex << mPID2.pid << std::endl;
	CREATEPIN(&pSession, &mPID3, NULL, 0); getLogger().out() << "pin3: " << std::hex << mPID3.pid << std::endl;
	mStep = 0;
	mStepCnt = mStepCntReset = (long)pProgram.size();

	// Start all threads of the program.
	HTHREAD * lT = (HTHREAD *)alloca(sizeof(HTHREAD) * pProgram.size());
	testCustom59_s ** lCtx = (testCustom59_s **)alloca(sizeof(testCustom59_s *) * pProgram.size());
	size_t iT;
	for (iT = 0; iT < pProgram.size(); iT++)
	{
		lCtx[iT] = new testCustom59_s(*this, &pProgram[iT][0], (long)pProgram[iT].size(), (long)iT);
		createThread(&TestCustom59::threadTestCustom59, lCtx[iT], lT[iT]);
	}

	// Wait for completion.
	MVTestsPortability::threadsWaitFor((int)pProgram.size(), lT);

	// Verifications and cleanup.
	bool lDeadlockFound = false;
	for (iT = 0; iT < pProgram.size(); iT++)
	{
		if (lCtx[iT]->mDeadlocked)
		{
			lDeadlockFound = true;

			// Verify that the pins of this test don't contain committed modifs from the threads that were rolled back by deadlock.
			IPIN * const lTstPIN = pSession.getPIN(mPID1);
			Value const * lV = lTstPIN->getValue(mPropIds[1]);
			if (lV && containsValue(*lV, lCtx[iT]->mThreadId))
			{
				getLogger().out() << "[" << std::dec << lCtx[iT]->mThreadIndex << ":" << std::hex << lCtx[iT]->mThreadId << "] *** UNEXPECTED SURVIVING MODIF!" << std::endl;
				MVTApp::output(*lTstPIN, getLogger().out(), &pSession);
				lSuccess = false;
			}
			lTstPIN->destroy();
		}
		else
		{
			// Verify that the pins of this test do contain committed modifs from the threads that were not rolled back by deadlock.
			bool lWrites = false;
			size_t iStep;
			for (iStep = 0; iStep < pProgram[iT].size() && !lWrites; iStep++)
				lWrites = (kSWrite1 == pProgram[iT][iStep] || kSWrite1 == pProgram[iT][iStep]);
			if (lWrites)
			{
				IPIN * const lTstPIN = pSession.getPIN(mPID1);
				Value const * lV = lTstPIN->getValue(mPropIds[1]);
				if (!lV || !containsValue(*lV, lCtx[iT]->mThreadId))
				{
					getLogger().out() << "[" << std::dec << lCtx[iT]->mThreadIndex << ":" << std::hex << lCtx[iT]->mThreadId << "] *** EXPECTED A MODIF!" << std::endl;
					MVTApp::output(*lTstPIN, getLogger().out(), &pSession);
					lSuccess = false; 
				}
				lTstPIN->destroy();
			}
		}
		delete lCtx[iT];
	}
	if (lDeadlockFound && !pDeadlockExpected)
		{ getLogger().out() << "*** UNEXPECTED DEADLOCK!" << std::endl; lSuccess = false; }
	else if (!lDeadlockFound && pDeadlockExpected)
		{ getLogger().out() << "*** EXPECTED A DEADLOCK!" << std::endl; lSuccess = false; }
	return lSuccess;
}