Пример #1
0
short newCorner( short alpha, short beta, short gamma, 
                 short c1, short c2, short c3)
{ // generates a cube corner (3 x face) 
  // alpha beta gamma indicate the rotation
  // c1, c2, c3 are the colors for the three faces in order
  // return index to face table  (containing 3 new faces)
  
  short fo, po;
  short x, y, z;
  short a, b ,c, d, e, f, g;
  
  // determin vertex coordinates  
  x = (U + U/2 +3);
  y = (U + U/2 +3);
  z = (U + U/2 +3);
  
  // rotation
  initMatrix( mo, alpha, beta, gamma, 0, 0, 0);

  // verify there is room in the tables
    if ((facec>=3) && (pyc>=3) && (pc>=7))
    {
      // generate all points necessary for the cube corner
      // in base position
        a = newPoint( x,   y,   z);        // A        
        b = newPoint( x,   y-U, z);        // B
        c = newPoint( x-U, y-U, z);        // C
        d = newPoint( x-U, y,   z);        // D
        e = newPoint( x,   y-U, z-U);      // E
        f = newPoint( x,   y,   z-U);      // F
        g = newPoint( x-U, y,   z-U);      // G
        
      // generate all the polygons and faces 
      // with proper orientation (normal outbound)
        newFace ( newPoly( a, b, c, d), c1);
        newFace ( newPoly( d, g, f, a), c2);
        fo = newFace( newPoly( a, f, e, b), c3); 
        
      // add an object with 3 faces
        po = newObj( fo, 3);
        
      // rotate as required
        rotateObject( mo, po);

      // returns the object index
        return po;
    } // if 
    else 
        while( 1);
} // new cube corner
Пример #2
0
TyPtr Ty::newPoly (TyPtr ty, Subs& subs)
{
	switch (ty->kind)
	{
	case tyPoly:
		{
			for (const auto& r : subs.rules)
				if (r.left == ty)
					return r.right;
			
			auto newtype = Ty::makePoly();		
			subs += Subs::Rule { ty, newtype };
			return newtype;
		}

	case tyConcrete:
		if (ty->subtypes.nil())
			return ty;
		return
			Ty::makeConcrete(ty->name,
				ty->subtypes.map([&] (TyPtr t)
				{
					return newPoly(t, subs);
				}));

	default:
		return ty;
	}
}
Пример #3
0
Poly
polyMultiply2( Poly A, Poly B){
        Poly l = newPoly();
        if (NULL == l)
                return l;

        Position a = first( A );
        while ( NULL != a)
        {
                Position b = first( B );
                Position pl = l; 

                while (NULL != b)
                {
                        int exp = a->exp * b->exp;
                        while ( NULL != pl->next && pl->next->exp > exp)        //start position for this round of insertion
                                pl  = pl->next;

                        if ( NULL != pl->next && pl->next->exp == exp)
                                pl->next->coeff += a->coeff * b->coeff;
                        else
                                insertAfter( a->coeff * b->coeff, exp, l, pl);

                        b = b->next;
                }
                a = a->next;
        }
        return l;
}
Пример #4
0
int main(int argc, char const *argv[]){
        int i,a,b;
        int tmp;
        Poly li, lp, mulp, sump;
        li = newPoly();
        lp = newPoly();

        if ( NULL == li || NULL == lp)
                return 1;
        li->exp = 0;
        lp->exp = 0;

        srand( time(NULL) );
	for(i = 0 ; i< LSIZE; i++){
                a = rand()/(RAND_MAX/LSIZE);
                b = rand()/(RAND_MAX/LSIZE);
                addItem( a, b, li);
                addItem( b, a, lp);
	}

        //removeDup( li);
        //removeDup( lp);

        printPoly( li );
        printPoly( lp );

        mulp = polyMultiply2( li, lp);
        printf("\nmultiply : " );
        printPoly( mulp );
        deletePoly( mulp);

        sump = polyAdd( li, lp);
        printf("\nadd : " );
        printPoly( sump );
        deletePoly( sump );

        printf("\n li ^2: ");
        printPoly( polyExp(li,2) );

        //swapNext( first(li), li );
        deletePoly( li );
        deletePoly( lp );

	return 0;
}
Пример #5
0
Poly* addPoly( Poly* p1, Poly* p2 )
{
    Mono *m1, *m2;
    Poly* result = newPoly();

    m1 = (p1==NULL ? NULL : p1->first);
    m2 = (p2==NULL ? NULL : p2->first);

    while( m1!=NULL && m2!=NULL )
    {
       if( m1->exp == m2->exp )
       {
          if( m1->coeff + m2->coeff != 0 )
          {
             appendMono( result, newMono(m1->coeff + m2->coeff, m1->exp, NULL) );
          }
          m1 = m1->next;
          m2 = m2->next;
       }
       else if( m1->exp < m2->exp )
       {
          appendMono( result, newMono(m1->coeff, m1->exp, NULL) );
          m1 = m1->next;
       }
       else /*m1->exp > m2->exp */
       {
          appendMono( result, newMono(m2->coeff, m2->exp, NULL) );
          m2 = m2->next;
       }
    }

    /* append leftover monomials, if any */
    while( m1!=NULL )
    {
       appendMono( result, newMono(m1->coeff, m1->exp, NULL) );
       m1 = m1->next;
    }

    while( m2!=NULL )
    {
       appendMono( result, newMono(m2->coeff, m2->exp, NULL) );
       m2 = m2->next;
    }

   if( result->last != NULL )
   {
       result->deg = result->last->exp;
   }
   else
   {
       result->deg = 0;  /* zero polynomial */
   }

   return result;
}
Пример #6
0
Poly PolyAdd(Poly polya, Poly polyb)
{
    Poly poly = newPoly();
    Poly ptr = poly;
    Poly ptra = polya->next;
    Poly ptrb = polyb->next;
    Poly newnode;
    
    while (ptra != NULL || ptrb != NULL)
    {
        newnode = newPoly();
        if (ptra == NULL || (ptrb != NULL && ptra->index < ptrb->index))
        {
            newnode->coef = ptrb->coef;
            newnode->index = ptrb->index;
            ptrb = ptrb->next;
        }
        else if (ptrb == NULL || (ptra != NULL && ptra->index > ptrb->index))
        {
            newnode->coef = ptra->coef;
            newnode->index = ptra->index;
            ptra = ptra->next;
        }
        else if (ptra != NULL && ptrb != NULL && ptra->index == ptrb->index)
        {
            newnode->coef = ptrb->coef + ptra->coef;
            newnode->index = ptra->index;
            ptrb = ptrb->next;
            ptra = ptra->next;
        }
        ptr->next = newnode;
        ptr = ptr->next;
    }
    ptr->next = NULL;
    
    return poly;
}
Пример #7
0
Poly polyAdd( Poly A, Poly B){
        Poly sum = newPoly();
        Position a = first( A );
        while ( NULL != a)
        {
                addItem( a->coeff, a->exp, sum);
                a = a->next;
        }
        
        a = first( B );
        while ( NULL != a)
        {
                addItem( a->coeff, a->exp, sum);
                a = a->next;
        }
        return sum;
}
Пример #8
0
short newSide( short alpha, short beta, short gamma, short c1)
{ // generates a cube center side (1 x face) 
  // alpha beta gamma indicate the rotation
  // c1 is the colors 
  // return index to face table  (containing 1 new face)
  
  short f, po;
  short x, y, z;
  short a, b ,c, d;
  
  // determin vertex coordinates  
  x = (+ U/2 );
  y = (+ U/2 );
  z = (U + U/2 +3);
  
  // rotation
  initMatrix( mo, alpha, beta, gamma, 0, 0, 0);

  // verify there is room in the tables
  if ((facec>=1) && (pyc>=1) && (pc>=4))
  {
      // generate all points necessary for the cube corner
      // in base position
      a = newPoint( x,   y,   z);        // A        
      b = newPoint( x,   y-U, z);        // B
      c = newPoint( x-U, y-U, z);        // C
      d = newPoint( x-U, y,   z);        // D
        
      // generate all the polygons and faces 
      // with proper orientation (normal outbound)
      f = newFace ( newPoly( a, b, c, d), c1);
        
      // add an object with 1 face
      po = newObj( f, 1);

      // rotate as required
      rotateObject( mo, po);
              
      // returns the object index
      return po;
  } // if 
    else 
        while( 1);
} // new cube side
Пример #9
0
Poly
polyMultiply( Poly A, Poly B){
        Poly l = newPoly();
        if (NULL == l)
                return l;

        Position a = first( A );
        while ( NULL != a)
        {
                Position b = first( B );
                while (NULL != b)
                {
                        addItem( a->coeff * b->coeff, a->exp + b->exp, l);
                        b = b->next;
                }
                a = a->next;
        }
        return l;
}
Пример #10
0
Poly* readPoly()
{
    int n, c, k;

    Poly* poly = newPoly();
    if( poly == NULL ) return NULL;

    scanf( "%d", &n);
    poly->deg = n;
    poly->first = poly->last = NULL;

    do
    {
        scanf( "%d %d", &c, &k );
        appendMono( poly, newMono(c, k, NULL) );
    }
    while( k < n);

    return poly;
}
Пример #11
0
Poly PolyFromArray(double *coef, int *index, int N)
{
    Poly poly = newPoly();
    Poly lastnode = poly;
    Poly newnode;
    for (int i = 0; i < N; i++)
    {
        newnode = (PtrToPolyNode)malloc(sizeof(struct _Poly_Node));
        if (newnode == NULL)
        {
            fprintf(stderr, "create polynominal: memory out of space!\n");
            exit(1);
        }
        newnode->coef = coef[i];
        newnode->index = index[i];
        lastnode->next = newnode;
        lastnode = newnode;
    }
    lastnode->next = NULL;
    return poly;
}
Пример #12
0
TyPtr Ty::newPoly (TyPtr ty)
{
	Subs subs;
	return newPoly(ty, subs);
}
Пример #13
0
Poly
polyOne(){
        Poly one = newPoly();
        addItem( 1, 0, one );
        return one;
}
Пример #14
0
void Polygroup::polygonReduction()
{
	//This function will be started in a new thread by the calling function so it will not interfere with main operation
	highEfficientPolys.clear();
	highPolyReady=false;
	std::vector<Poly> gridCopy[10][10];

	logger->LogMessage(LOG_POLYGON,"\nStarting new polygon reduction. Printing grid of heights:\n\n");

	for(int x(0);x<10;++x)
	{
		for(int z(0);z<10;++z)
		{
			for(std::vector<Poly>::iterator copyIt(grid[x][z].begin());copyIt!=grid[x][z].end();++copyIt)
			{
				gridCopy[x][z].push_back((*copyIt));
				logger->LogMessage(3,uiCore->intToString(gridCopy[x][z][0].getPoint(0).y) + " ");
			}
		}

		logger->LogMessage(3,"\n");
	}

	for(int xPos(0);xPos<10;++xPos)
	{
		for(int zPos(0);zPos<10;++zPos)
		{
			for(std::vector<Poly>::iterator gridIt(gridCopy[xPos][zPos].begin());gridIt!=gridCopy[xPos][zPos].end();++gridIt)
			{
				bool breakout=false;
				if(gridIt->getNormal()==Vector3<s32>(0,1,0) || gridIt->getNormal()==Vector3<s32>(0,-1,0))
				{
					Poly storedPoly((*gridIt));
					int xPlus(0),zPlus(0);
					bool xFailed(false),zFailed(false);

					while(!xFailed || !zFailed)
					{
						if(!xFailed)
						{
							++xPlus;
							for(int nextX(zPos);nextX<=(zPos+zPlus);++nextX)
							{
								if(xPos+xPlus==10 && !xFailed)
								{
									xFailed=true;
									if(xPlus>0)
										--xPlus;
								}
								else
								{
									bool fail(true);
									for(std::vector<Poly>::iterator posIt(gridCopy[xPos+xPlus][nextX].begin());posIt!=gridCopy[xPos+xPlus][nextX].end();++posIt)
									{
										if((posIt->getNormal()==storedPoly.getNormal()) && (posIt->getPoint(0).y==storedPoly.getPoint(0).y))
										{
											fail=false;
											break;
										}
									}

									if(fail)
									{
										xFailed=true;
										if(xPlus>0)
											--xPlus;
									}
								}
							}

						}

						if(!zFailed)
						{
							++zPlus;
							for(int nextZ(xPos);nextZ<=(xPos+xPlus);++nextZ)
							{
								if(zPos+zPlus==10 && !zFailed)
								{
									zFailed=true;
									if(zPlus>0)
										--zPlus;
								}
								else
								{
									bool fail(true);
									for(std::vector<Poly>::iterator posIt(gridCopy[nextZ][zPos+zPlus].begin());posIt!=gridCopy[nextZ][zPos+zPlus].end();++posIt)
									{
										if((posIt->getNormal()==storedPoly.getNormal()) && (posIt->getPoint(0).y==storedPoly.getPoint(0).y))
										{
											fail=false;
											break;
										}
									}

									if(fail)
									{
										zFailed=true;
										if(zPlus>0)
											--zPlus;
									}
								}
							}

						}
					}

					Poly newPoly(storedPoly.getPoint(0),
						Vector3<s32>(storedPoly.getPoint(0).x,storedPoly.getPoint(0).y,storedPoly.getPoint(0).z+zPlus+1),
						Vector3<s32>(storedPoly.getPoint(0).x+xPlus+1,storedPoly.getPoint(0).y,storedPoly.getPoint(0).z+zPlus+1),
						Vector3<s32>(storedPoly.getPoint(0).x+xPlus+1,storedPoly.getPoint(0).y,storedPoly.getPoint(0).z),
						storedPoly.getType());	//removing +1 temporarily

					for(int x(xPos);x<=xPos+xPlus;++x)
					{
						for(int z(zPos);z<=zPos+zPlus;++z)
						{
							for(std::vector<Poly>::iterator posIt(gridCopy[x][z].begin());posIt!=gridCopy[x][z].end();++posIt)
							{
								if(posIt->getNormal()==storedPoly.getNormal() && (posIt->getPoint(0).y==storedPoly.getPoint(0).y))
								{
									gridCopy[x][z].erase(posIt);
									logger->LogMessage(LOG_POLYGON,"Deleting Poly from grid at X: " + uiCore->intToString(x) + " Z: " + uiCore->intToString(z) + "\n");
					
									breakout=true;
									break;
								}
							}
						}
					}

					highEfficientPolys.push_back(newPoly);
					logger->LogMessage(LOG_POLYGON,"Creating new Poly:\n");
					logger->LogMessage(LOG_POLYGON,"minX: " + uiCore->intToString(newPoly.getPoint(0).x) + " minZ: " + uiCore->intToString(newPoly.getPoint(0).z) + "\n");
					logger->LogMessage(LOG_POLYGON,"maxX: " + uiCore->intToString(newPoly.getPoint(2).x-1) + " maxZ: " + uiCore->intToString(newPoly.getPoint(2).z-1) + "\n");
				}
				else
				{
					highEfficientPolys.push_back((*gridIt));
				}

				if(breakout)
					break;
			}
		}
	}

	highPolyReady=true;
}