示例#1
0
文件: Car.cpp 项目: msvas/GoGoKart
bool Car::handleCarCollision(Car* otherCar) {
  bool collided = false;

  if(otherCar->getRight() > getLeft()) {
    if(otherCar->getLeft() < getLeft()) {
      if(otherCar->getBottom() < getFront()) {
        if(otherCar->getFront() > getBottom()) {
          collided = true;
          otherCar->xPosition = getLeft() - (carModel->getMax().x * scale);
        }
      }
    }
  }
  if(otherCar->getLeft() < getRight()) {
    if(otherCar->getRight() > getRight()) {
      if(otherCar->getBottom() < getFront()) {
        if(otherCar->getFront() > getBottom()) {
          collided = true;
          otherCar->xPosition = getRight() - (carModel->getMin().x * scale);
        }
      }
    }
  }

}
Type CTECList<Type>:: getFromIndex(int index)
{
	Type thingToGet;
	assert(size > 0 && index >= 0 && index < size);

	ArrayNode<Type> * previous, next;
		if(index == 0)
		{
			thingToGet = getFront();
		}
		else if(index == size - 1)
		{
			thingToGet = getEnd();
		}
		else
		{
			for(int spot = 0; spot < index + 1; spot++)
			{

			}
		}

		this -> calculateSize();
		return thingToGet;
}
示例#3
0
文件: Graph.c 项目: syugraj21/cmps101
/* DFS()
 * Pre: List S length == Number of vetices in G
 * Pos: finds the strongly connected components
 */ 
void DFS(GraphRef G, ListRef S){
	if(G == NULL){
		fprintf(stderr,"Graph Error: calling DFS on NULL Graph");
		exit(1);
	}
	if(getLength(S) != getOrder(G)){
		fprintf(stderr,"DFS Error: ListRef size != Graph size");
		exit(1);
	}
	int i;
	int u;
	int j;
	
	for(i=1; i<=getOrder(G);i++){
		G->color[i] = WHITE;
		G->parent[i] = NIL;
	}
	j =1;
	moveTo(S,getLength(S)-1);
	while(!offEnd(S) && j<=getOrder(G)){
		u = getFront(S);

		if(G->color[u] == WHITE){
			Visit(G,S,u);
		}
		deleteFront(S);
		j++;
	} 
}
示例#4
0
bool OovThreadedWaitQueuePrivate::waitPopPrivate(void *item)
    {
    std::unique_lock<std::mutex> lock(mProcessQueueMutex);
    bool gotItem = false;
    LOG_PROC("pop lock", this);
    // Wait while empty
    while(isQueueEmpty() && !mQuitPopping)
        {
        // Release lock and wait for signal.
        mProviderPushedSignal.wait(lock);
        // After signaled, lock is reaquired.
        }

    // In the normal case this will not be empty.
    // If it is empty, then there was a signal, but nothing was
    // in the queue. This means that the quit function was called.
    gotItem = !isQueueEmpty();
    LOG_PROC_INT("pop got item", this, gotItem);
    if(gotItem)
        {
        getFront(item);
        }

    LOG_PROC_INT("pop unlock", this, gotItem);
    // unlock and signal to provider thread that queue is processed.
    lock.unlock();
    mConsumerPoppedSignal.notify_one();
    LOG_PROC("pop done", this);
    return gotItem;
    }
示例#5
0
文件: Graph.c 项目: FernandoC/BFS
void BFS(GraphRef G, int s){
   int i, u, tmp;
   G->source = s;
   for ( i = 1;i <= getOrder(G); i++){
      G->color[i] = 'w';
      G->discover[i] = INF;
      G->parent[i] = NIL;
   }
   G->color[s] = 'g';
   G->discover[s] = 0;
   G->parent[s] = NIL;
   ListRef Q = newList();
   insertFront( Q, s );
   while( !isEmpty(Q) ){
      u = getFront(Q);
      deleteFront(Q);
      moveTo(G->adjacency[u], 0);
      while ( !offEnd(G->adjacency[u]) ){
         tmp = getCurrent(G->adjacency[u]);
         if ( G->color[tmp] == 'w'){
            G->color[tmp] = 'g';
            G->discover[tmp] = G->discover[u] + 1;
            G->parent[tmp] = u;
            insertBack( Q, tmp );
         }
         moveNext(G->adjacency[u]);
      }
      G->color[u] = 'b';
   }
   freeList(&Q);
}
dfa * createDFA(char *regex){
	nfa* automata=createNFA(regex);
	int i=0;
	//printf("Creating DFA with %d states\n\t",automata->nStates);
	dfa *deter_auto=(dfa*)malloc(sizeof(dfa));//deterministic automata
	deter_auto->nStates= automata->nStates;
	deter_auto->states = (int **)calloc(automata->nStates,sizeof(int*));
	deter_auto->quants = (int * )calloc(automata->nStates,sizeof(int ));
	if(automata==NULL){
		//printf("No automata found\n");
		return;
	}
	int index;
	for(;i<automata->nStates;i++){
		//printf("state #%d : ",i);
		index=1;
		deter_auto->states[i]=(int*)calloc(automata->states[i]->size+1,sizeof(int));
		deter_auto->states[i][0]=automata->states[i]->size;
		deter_auto->quants[i]=automata->quants[i];
		while(automata->states[i]->size!=0){
			//printf("%c ",getFront(automata->states[i]));
			deter_auto->states[i][index++]=getFront(automata->states[i]);
			dequeue(automata->states[i]);
		}
		//printf(" | ");
		//printf("  -  quant : %d\n\t",automata->quants[i]);
	}
	return deter_auto;
}
示例#7
0
文件: tree.c 项目: dtnakamura/CS-201
// Function to insert a new node in complete binary tree
void treeInsert(struct node **root, int data, struct Queue *queue)
{
    // Create a new node for give data
    struct node *temp = newNode(data);

    // If the tree is empty, initialize the root with a new node
    if (!*root)
        *root = temp;
    else
    {
        // get the front node of the queue
        struct node *front = getFront(queue);

        // If the left child of this front node doesn't exist,
        // set the left child as the new node
        if (!front->left)
            front->left = temp;
        // If the right child of this front node doesn't exist;
        // set the right child as the new node
        else if (!front->right)
            front->right = temp;
        // If the front node has both children, dequeue it
        if (hasBothChildren(front))
            removeFromFront(queue);
    }
    // Enqueue the new node for later insertions
    enqueue(temp, queue);
}
// Function to insert a new node in complete binary tree
void insert(struct node **root, int data, struct Queue* queue)
{
    // Create a new node for given data
    struct node *temp = newNode(data);

    // If the tree is empty, initialize the root with new node.
    if (!*root)
        *root = temp;

    else
    {
        // get the front node of the queue.
        struct node* front = getFront(queue);

        // If the left child of this front node doesn’t exist, set the
        // left child as the new node
        if (!front->left)
            front->left = temp;

        // If the right child of this front node doesn’t exist, set the
        // right child as the new node
        else if (!front->right)
            front->right = temp;

        // If the front node has both the left child and right child,
        // Dequeue() it.
        if (hasBothChild(front))
            Dequeue(queue);
    }

    // Enqueue() the new node for later insertions
    Enqueue(temp, queue);
}
示例#9
0
文件: Car.cpp 项目: msvas/GoGoKart
bool Car::checkTrackCollision(std::list<TrackTile*> allTracks) {
  bool collided = false;
  int i = 0;

  std::list<TrackTile*>::const_iterator iterator;
  for (iterator = allTracks.begin(); iterator != allTracks.end(); ++iterator) {
    if ((*iterator)->getY() == (this->yPosition - yPosition)) {
      //cout << "Tile " << (*iterator)->getLeft() << " " << (*iterator)->getRight() << " " << (*iterator)->getBottom() << " " << (*iterator)->getFront() << "\n";
      //cout << "Car " << getLeft() << " " << getRight() << " " << getBottom() << " " << getFront() << "\n";
      if(getLeft() < (*iterator)->getRight()) {
        //cout << "1\n";
        if(getRight() > (*iterator)->getLeft()) {
          //cout << "2\n";
          if(getFront() > (*iterator)->getBottom()) {
            //cout << "3\n";
            if(getBottom() < (*iterator)->getFront()) {
              collided = true;
              lastTile = currentTile;
              currentTile = i;
              checkLap(*iterator, allTracks.size());
              //cout << "Atual " << currentTile << "\n";
            }
          }
        }
      }
    }
    i++;
  }
  return collided;
}
void BFS(int v)
{
	for (int m = 0; m < n; m++)
	{
		visited[m] = 0;
	}
	int counter = 0;
	visited[v] = 1;
	queueInit();
	Queuepush(v);//큐에 v를 넣어준다
	fprintf(fout,"%d -> ", v);
	counter++;
	while (!QisEmpty())
	{
		v = getFront();//front를 v에 넣는다
		Queuepop();
		for (int w = 0; w < n; w++)
		{
			if ((visited[w]==0) && adj_mat[v][w])//너비 탐색을 위해서 w가 다음 값을 계속 탐색해서 edge가 있으면 탐색시작한다
			{
				Queuepush(w);//w를 push한다.
				visited[w] = 1;//방문한것으로 표시
				fprintf(fout,"%d ", w );//출력
				counter++;
				if (counter<n)
					fprintf(fout," -> ");
			}
		}
	}
}
示例#11
0
String Card::getAll() {
	String all = getQuantity()+","+getText()+","+getThumb()+","+getFront()+
			","+getBack()+","+getId()+","+getRate()+","+getValue()+","+getNote()+","+getOrientation()+",";
	for (int i = 0; i < stats.size(); i++) {
		all += stats[i]->getAll() + "$";
	}
	return all;
}
Vector3 RCMatrix4::getScale(const Matrix4& m){
	Vector3 result = {
		RCVector3::length(getLeft(m)),
		RCVector3::length(getUp(m)),
		RCVector3::length(getFront(m))
	};
	return result;
}
void printQueue()
{
	int i = 0, j = 0;
	for (i = (front + 1) % QUEUE_SIZE, j = 0; i < QUEUE_SIZE; i++, j++)
	{
		printf("%d", getFront());

	}
}
示例#14
0
void test_queue_front_zero (void) {
	int *original_queues = initialize(3);
	original_queues[1] = 2;
	original_queues[2] = 3;

	int *target_queues = queue_full(original_queues, 2, 0);
	TEST_ASSERT_EQUAL(5, getFront());
	TEST_ASSERT_EQUAL(1, getRear());
	TEST_ASSERT_EQUAL(2, target_queues[0]);
	TEST_ASSERT_EQUAL(3, target_queues[1]);
}
示例#15
0
void test_queue_front_max (void) {
	int *original_queues = initialize(3);
	original_queues[0] = 1;
	original_queues[1] = 2;

	int *target_queues = queue_full(original_queues, 1, 2);
	TEST_ASSERT_EQUAL(5, getFront());
	TEST_ASSERT_EQUAL(1, getRear());
	TEST_ASSERT_EQUAL(1, target_queues[0]);
	TEST_ASSERT_EQUAL(2, target_queues[1]);
}
示例#16
0
void test_queue_full_normal (void) {
	int *original_queues = initialize(3);
	original_queues[0] = 1;
	original_queues[2] = 3;

	int *target_queues = queue_full(original_queues, 0, 1);
	TEST_ASSERT_EQUAL(5, getFront());
	TEST_ASSERT_EQUAL(1, getRear());
	TEST_ASSERT_EQUAL(3, target_queues[0]);
	TEST_ASSERT_EQUAL(1, target_queues[1]);
}
示例#17
0
void printDestandPath(FILE* out, GraphRef G, ListRef path, int dest) {
	fprintf(out, "The distance from %d to %d is ", getSource(G), dest);
	if ( getFront(path) == NIL ) {
		fprintf(out, "infinity\n");
		fprintf(out, "No %d-%d path exists", getSource(G), dest);
	}else {
		fprintf(out, "%d\n", getDist(G, dest));
		fprintf(out, "A shortest %d-%d path is: ", getSource(G), dest);
		printList(out, path);
	}
	fprintf(out,"\n");
}
示例#18
0
文件: ui.cpp 项目: wesulee/mr
std::vector<Color> Gradient::generate(const int length) {
	assert(length >= 2);
	if (!sorted) {
		std::sort(pairs.begin(), pairs.end(), GradCmp());
		sorted = true;
	}

	std::vector<Color> colors;
	colors.reserve(static_cast<std::size_t>(length));

	if (pairs.empty()) {
		grad(colors, getFront(), getBack(), length);
		colors.push_back(getBack());
		return colors;
	}

	auto it = pairs.cbegin();
	Color start = getFront();
	Color end;
	int cDist = 0;		// current distance gone
	int dist;			// passed to grad()
	float prevDist = 0;
	for (auto itEnd = pairs.cend(); it != itEnd; ++it) {
		end = (*it).second;
		dist = static_cast<int>(((*it).first - prevDist) * length);
		grad(colors, start, end, dist);
		cDist += dist;
		start = end;
		prevDist = (*it).first;
	}

	end = getBack();
	dist = length - cDist - 1;
	grad(colors, start, end, dist);
	colors.push_back(end);
	assert(static_cast<int>(colors.size()) == length);

	return colors;
}
//回転行列の正規化
Matrix4 RCMatrix4::normalize(const Matrix4& m){
	Matrix4 result = m;
	//前方向のベクトルを取得
	Vector3 front = getFront(m);
	//上方向のベクトルを取得
	Vector3 up = getUp(m);
	// 左方向のベクトルを求める
	Vector3 left = RCVector3::normalize(RCVector3::cross(up, front));
	// 上方向のベクトルを求める
	up = RCVector3::normalize(RCVector3::cross(front, left));
	// 前方向のベクトルを求める
	front = RCVector3::cross(left, up);
	setLeft(result, left);
	setUp(result, up);
	setFront(result, front);
	return result;
}
示例#20
0
    //-----------------------------------------------------------------------
    BspNode* BspNode::getNextNode(const Vector3& point) const
    {

        if (mIsLeaf)
            OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS,
                "This method is not valid on a leaf node.",
                "BspNode::getNextNode");

        Plane::Side sd = getSide(point);
        if (sd == Plane::NEGATIVE_SIDE)
        {
            //LogManager::getSingleton().logMessage("back");
            return getBack();
        }
        else
        {
            //LogManager::getSingleton().logMessage("front");
            return getFront();
        }



    }
int isGraphBipartite(int **G)
{
	int colorArr[V],i;
	for( i=0;i<V;i++)
	colorArr[i]=-1;
	int src=0,v;
	//1 is first color
	//0 is second color
	colorArr[src]=1;
	
	enqueue(queue,src);
	
	while(!isEmpty)
	{
		int u=getFront(queue);
		dequeue(queue);
		
		for(v=0;v<V;v++)
		{
			if (G[u][v]==1 && colorArr[v] == -1)
			{
				colorArr[v] = 1 - colorArr[u];
                			enqueue(queue,v);
			}
			else if (G[u][v]==1 && colorArr[v] == colorArr[u])
                		return 0;
		}
	}
	if(V==3&&E==3)
    return 0;
  else
    if(V==7&&E==8)
    return 0;
    else
	return 1;
}
float RCMatrix4::pitch(const Matrix4& m){
	return RCVector3::pitch(getFront(m));
}
示例#23
0
void floodLevel(int n,int d,Queue *q) {
   int i;
   for (i = 0;i < n;i++) {
      setDist(q->contents[(getFront(q) + i) % QSIZE],d);
   }
}
示例#24
0
int main () {
    
    int menu = 0;
    int input = 0;
    node * list; 
    char c;
    
    list = createList(); 
    
    while (menu != 6) {
    
        printf("\nWhat would you like to test?\n");
        printf("\n[1] Add Front\n");
        printf("[2] Get Front\n");
        printf("[3] Remove Front\n");
        printf("[4] My Tests\n");
        printf("[5] Destroy List\n");
        printf("[6] Exit\n");
        scanf("%d", &menu);

        if (menu > 6 || menu < 1)
            while((c = getchar()) != '\n' && c != EOF); /*cleans input buffer, incase characters are input*/
            
        if (menu == 1) {
            
            printf("\nPlease Enter an Integer:");
            scanf("%d", &input);
            
            addFront(list, input);  /*returns users input to function to add to the list*/
            
            printf("Current List:");
            printList(list);        /*List printed everytime inorder for user to keep track*/
        
        }
        
        if (menu == 2) {
            
            printf("Front Value: %d", getFront(list));  /*gets value from function and prints it to screen*/
            
            printf("\nCurrent List:");
            printList(list);  
        
        }
        
        if (menu == 3) {
        
            removeFront(list);  /*calls function and sends list to remove first*/
            
            printf("Current List:");
            printList(list);
        
        }
        
        if (menu == 4) {
            
            /*my tests, I have tested very large and very small numbers in this array*/
            int testData[8] = {-456789123, 2, 0, 4, 1, 9, 9, 2096335345}; /*Given Data*/
            int arrayLength;
            int i;
            int testAddFront;
    
            arrayLength = sizeof(testData) / sizeof(int); /*Determines arraylength*/
        
            for (i=0; i<arrayLength; i++) {
                addFront(list, testData[i]);    /*Sends data to the addFront function*/ 
            }
            
            printf("\nAfter sending testData:\n");
            printList(list);
            
            getFront(list);
            printf("\n\nAfter getFront:\n");
            printf("%d", getFront(list));
            
            removeFront(list);
            printf("\n\nAfter removeFront:\n");
            printList(list);
            
            testAddFront = 999999;
            addFront(list, testAddFront);
            printf("\n\nAfter addFront:\n");
            printList(list);
        }
        
        if (menu == 5) {
        
            destroy(list); /*destroys list and frees memory*/
        
        }
        
        if (menu == 6) {
        
            break;  /*breaks out and ends program*/
            
        }
    }
    
    return 0;
}
示例#25
0
void chaos::GameObject::drawGizmo(GLfloat scale){
    renderer->drawDebugLine(getPosition(), getPosition()-scale*getFront(), glm::vec4(0,1,0,1));
    renderer->drawDebugLine(getPosition(), getPosition()+scale*getRight(), glm::vec4(1,0,0,1));
    renderer->drawDebugLine(getPosition(), getPosition()+scale*getUp(), glm::vec4(0,0,1,1));
}
示例#26
0
int main(int argc, char* argv[])
{
    int i;
    ListRef A = newList();
    ListRef B = newList();
	ListRef ACopy = NULL;
	ListRef AB_Cat = NULL;
	insertBack(A, 10);
	insertBack(A, 20);
	insertBack(A, 30);
	insertBack(A, 40);
	insertBack(A, 50);
	insertBack(A, 60);
	printf("equals(A,B)		: %d\n", equals(A, B));
	insertBack(B, 10);
	insertBack(B, 20);
	insertBack(B, 30);
	insertBack(B, 40);
	insertBack(B, 50);
	insertBack(B, 60);
	AB_Cat = catList(A, B);
	printf("printLIST(AB_Cat)	: ");
	printLIST(AB_Cat);
	ACopy = copyList(A);
	printf("printLIST(A)		: ");
	printLIST(A);
	printf("printLIST(ACopy)	: ");
	printLIST(ACopy);
	printf("equals(A,ACopy)		: %d\n", equals(A, ACopy));
	printf("equals(A,B)		: %d\n", equals(A, B));
	printf("printLIST(A)		: ");
	printLIST(A);
	moveTo(A, getLength(A));
	printf("offEnd(A)		: %d\n", offEnd(A));
	moveTo(A, 3);
	insertBeforeCurrent(A, 35);
	insertAfterCurrent(A, 45);
	printf("printLIST(A)		: ");
	printLIST(A);
	printf("getCurrent(A)		: %d\n", getCurrent(A));
	movePrev(A);
	printf("getCurrent(A)		: %d\n", getCurrent(A));
	deleteCurrent(A);
	printf("printLIST(A)		: ");
	printLIST(A);
	makeEmpty(B);
	deleteFront(A);
	printf("printLIST(A)		: ");
	printLIST(A);
	printf("getLength(A)		: %d\n", getLength(A));
	printf("isEmpty(A)		: %d\n", isEmpty(A));
	makeEmpty(A);
	printf("isEmpty(A)		: %d\n", isEmpty(A));
	printf("getLength(A)		: %d\n", getLength(A));
	/* printf("printLIST(A)		: ");
	printLIST(A); */
	insertFront(B, 50);
	insertBack(B, 60);
	insertFront(B, 40);
	insertBack(B, 70);
	insertFront(B, 30);
	insertBack(B, 80);
	insertFront(B, 20);
	insertBack(B, 90);
	insertFront(B, 10);
	printf("printLIST(B)		: ");
	printLIST(B);
	printf("offEnd(B)		: %d\n", offEnd(B));
	moveTo(B, 5);
	printf("offEnd(B)		: %d\n", offEnd(B));
	printf("getCurrent(B)		: %d\n", getCurrent(B));
	deleteCurrent(B);
	printf("printLIST(B)		: ");
	printLIST(B);
	/* printf("getCurrent(B) 	: %d\n", getCurrent(B));*/
	moveTo(B, 0);
	printf("getFront(B)		: %d\n", getFront(B));
	printf("getCurrent(B)		: %d\n", getCurrent(B));
	deleteFront(B);
	printf("printLIST(B)		: ");
	printLIST(B);
	printf("getFront(B)		: %d\n", getFront(B));
	/* printf("getCurrent(B)		: %d\n", getCurrent(B)); */
	moveTo(B, (getLength(B)-1));
	printf("getCurrent(B)		: %d\n", getCurrent(B));
	printf("getBack(B)		: %d\n", getBack(B));
	deleteBack(B);
	printf("getBack(B)		: %d\n", getBack(B));
	/* printf("getCurrent(B)		: %d\n", getCurrent(B)); */
	moveTo(B, (getLength(B)-1));
	printf("getCurrent(B)		: %d\n", getCurrent(B));
	printf("getBack(B)		: %d\n", getBack(B));
	deleteBack(B);
	printf("getBack(B)		: %d\n", getBack(B));
	printf("getCurrent(B)		: %d\n", getCurrent(B)); 
	
	
	
    return(0);
}
示例#27
0
//get item from top of stack
struct leaf* topStack(struct stack *s)
{
  getFront(s->stk);
}
示例#28
0
void Camera::shiftFront(const float step) {
    cameraMatrix = glm::translate(cameraMatrix, getFront() * step);
}
float RCMatrix4::yaw(const Matrix4& m){
	return RCVector3::yaw(getFront(m));
}
示例#30
0
String Card::getAll() {
	String all = getQuantity()+delim+getText()+delim+getThumb()+delim+getFront()+
			delim+getBack()+delim+getId()+delim+getRate()+delim+getValue()+delim+getNote()+delim;
	return all;
}