void GenerateNGon( int faces, std::vector<cCoord3>& vertices )
{
	//assert(faces > 2 && faces < 254);
	vertices.clear();
	vertices.reserve(faces);
	//want: the closest vertex to be as far as possible
	//find the closest vertex, then find the next closest vertex
	// rotate half way between them
	const double center_arc = 1.0/faces;
	const float cos_factor = static_cast<float>(cos(center_arc * 2.0 * AKJ_PIf));
	const float rotate_arc = static_cast<float>(1.0/(2.0*LeastCommonMultiple(4,faces)));
	const cAngleAxis rotation(rotate_arc*2.0f*AKJ_PIf, 0.0f, 0.0f, 1.0f);
	const float length_factor = 1.0f/cosf(rotate_arc * 2.0f * AKJ_PIf);
	const float sin_factor = static_cast<float>(sin(center_arc * 2.0 * AKJ_PIf));
	cCoord3 out_vector(1.0f, 0.0f, 0.0f);

	out_vector = rotation.rotate(out_vector);

	vertices.push_back(length_factor*out_vector);
	for (int i = 2 ; i <= faces; ++i)
	{
		const cCoord3 perp_vec(-out_vector.y, out_vector.x, 0.0f);
		out_vector = cos_factor*out_vector;
		out_vector = out_vector + sin_factor*perp_vec;
		vertices.push_back(length_factor*out_vector);
	}
}
Beispiel #2
0
const Rational Rational::operator+ (const Rational & rValue) const
{
	long lcm = LeastCommonMultiple(rValue.denominator, denominator);
	long resultNumerator = (numerator * (lcm / denominator)) +
		(rValue.numerator * (lcm / rValue.denominator));
	Rational result(resultNumerator, lcm);
	return result;
}
Beispiel #3
0
void SegAlign (unsigned long Alignment, int FillVal)
/* Align the PC segment to Alignment. If FillVal is -1, emit fill fragments
 * (the actual fill value will be determined by the linker), otherwise use
 * the given value.
 */
{
    unsigned char Data [4];
    unsigned long CombinedAlignment;
    unsigned long Count;

    /* The segment must have the combined alignment of all separate alignments
     * in the source. Calculate this alignment and check it for sanity.
     */
    CombinedAlignment = LeastCommonMultiple (ActiveSeg->Align, Alignment);
    if (CombinedAlignment > MAX_ALIGNMENT) {
        Error ("Combined alignment for active segment is %lu which exceeds %lu",
               CombinedAlignment, MAX_ALIGNMENT);

        /* Avoid creating large fills for an object file that is thrown away
         * later.
         */
        Count = 1;

    } else {
        ActiveSeg->Align = CombinedAlignment;

        /* Output a warning for larger alignments if not suppressed */
        if (CombinedAlignment > LARGE_ALIGNMENT && !LargeAlignment) {
            Warning (0, "Combined alignment is suspiciously large (%lu)",
                     CombinedAlignment);
        }

        /* Calculate the number of fill bytes */
        Count = AlignCount (ActiveSeg->PC, Alignment);

    }


    /* Emit the data or a fill fragment */
    if (FillVal != -1) {
       	/* User defined fill value */
       	memset (Data, FillVal, sizeof (Data));
       	while (Count) {
       	    if (Count > sizeof (Data)) {
       	    	EmitData (Data, sizeof (Data));
       	    	Count -= sizeof (Data);
       	    } else {
       	    	EmitData (Data, Count);
       	    	Count = 0;
       	    }
       	}
    } else {
       	/* Linker defined fill value */
       	EmitFill (Count);
    }
}
bool fraction::operator >(const fraction &a) const
{
    int tmpDenominator;
    int cnt1,cnt2;
    tmpDenominator=LeastCommonMultiple(denominator,a.denominator);
    cnt1=tmpDenominator/denominator;
    cnt2=tmpDenominator/a.denominator;
    if(cnt1*numerator>cnt2*a.numerator)
        return true;
    else
        return false;
}
Beispiel #5
0
 static inline bool ReducingNotEqual(const Fractional< Natural > &left, const Fractional< Natural > &right)
 {
   Natural factor;
   bool result;
   if (left.denominator == right.denominator) {
     result = left.numerator != right.numerator;
   } else {
     factor = LeastCommonMultiple(left.denominator, right.denominator);
     if (left.denominator < right.denominator)
       result = left.numerator * (factor / left.denominator) != right.numerator;
     else
       result = left.numerator != right.numerator * (factor / right.denominator);
   }
   return result;
 }
fraction fraction::operator -(const fraction& a) const
{
    int tmpNumerator;
    int tmpDenominator;
    int GCD;
    int cnt1,cnt2;
    tmpDenominator=LeastCommonMultiple(denominator,a.denominator);
    cnt1=tmpDenominator/denominator;
    cnt2=tmpDenominator/a.denominator;
    tmpNumerator=cnt1*numerator-cnt2*a.numerator;
    GCD=GreatestCommonDivisor(tmpNumerator,tmpDenominator);
    if(GCD==1)
    return fraction(tmpNumerator,tmpDenominator);
    else
    return fraction(tmpNumerator/GCD,tmpDenominator/GCD);
}
Beispiel #7
0
 static inline Fractional< Natural > ReducingSubtract(const Fractional< Natural > &left, const Fractional< Natural > &right)
 {
   Fractional< Natural > result;
   Natural factor;
   if (left.denominator == right.denominator) {
     result.numerator = left.numerator - right.numerator;
     result.denominator = left.denominator;
   } else {
     factor = LeastCommonMultiple(left.denominator, right.denominator);
     if (left.denominator < right.denominator) {
       factor /= left.denominator;
       result.numerator = left.numerator * factor - right.numerator;
       result.denominator = right.denominator;
     } else {
       factor /= right.denominator;
       result.numerator = left.numerator - right.numerator * factor;
       result.denominator = left.denominator;
     }
   }
   return Reduce(result);
 }
Beispiel #8
0
Section* ReadSection (FILE* F, ObjData* O)
/* Read a section from a file */
{
    unsigned      Name;
    unsigned      Size;
    unsigned long Alignment;
    unsigned char Type;
    unsigned      FragCount;
    Segment*      S;
    Section*      Sec;

    /* Read the segment data */
    (void) Read32 (F);          /* File size of data */
    Name      = MakeGlobalStringId (O, ReadVar (F));    /* Segment name */
                ReadVar (F);    /* Segment flags (currently unused) */
    Size      = ReadVar (F);    /* Size of data */
    Alignment = ReadVar (F);    /* Alignment */
    Type      = Read8 (F);      /* Segment type */
    FragCount = ReadVar (F);    /* Number of fragments */


    /* Print some data */
    Print (stdout, 2,
           "Module '%s': Found segment '%s', size = %u, alignment = %lu, type = %u\n",
           GetObjFileName (O), GetString (Name), Size, Alignment, Type);

    /* Get the segment for this section */
    S = GetSegment (Name, Type, GetObjFileName (O));

    /* Allocate the section we will return later */
    Sec = NewSection (S, Alignment, Type);

    /* Remember the object file this section was from */
    Sec->Obj = O;

    /* Set up the combined segment alignment */
    if (Sec->Alignment > 1) {
        Alignment = LeastCommonMultiple (S->Alignment, Sec->Alignment);
        if (Alignment > MAX_ALIGNMENT) {
            Error ("Combined alignment for segment '%s' is %lu which exceeds "
                   "%lu. Last module requiring alignment was '%s'.",
                   GetString (Name), Alignment, MAX_ALIGNMENT,
                   GetObjFileName (O));
        } else if (Alignment >= LARGE_ALIGNMENT) {
            Warning ("Combined alignment for segment '%s' is suspiciously "
                     "large (%lu). Last module requiring alignment was '%s'.",
                     GetString (Name), Alignment, GetObjFileName (O));
        }
        S->Alignment = Alignment;
    }

    /* Start reading fragments from the file and insert them into the section . */
    while (FragCount--) {

        Fragment* Frag;

        /* Read the fragment type */
        unsigned char Type = Read8 (F);

        /* Extract the check mask from the type */
        unsigned char Bytes = Type & FRAG_BYTEMASK;
        Type &= FRAG_TYPEMASK;

        /* Handle the different fragment types */
        switch (Type) {

            case FRAG_LITERAL:
                Frag = NewFragment (Type, ReadVar (F), Sec);
                ReadData (F, Frag->LitBuf, Frag->Size);
                break;

            case FRAG_EXPR:
            case FRAG_SEXPR:
                Frag = NewFragment (Type, Bytes, Sec);
                Frag->Expr = ReadExpr (F, O);
                break;

            case FRAG_FILL:
                /* Will allocate memory, but we don't care... */
                Frag = NewFragment (Type, ReadVar (F), Sec);
                break;

            default:
                Error ("Unknown fragment type in module '%s', segment '%s': %02X",
                       GetObjFileName (O), GetString (S->Name), Type);
                /* NOTREACHED */
                return 0;
        }

        /* Read the line infos into the list of the fragment */
        ReadLineInfoList (F, O, &Frag->LineInfos);

        /* Remember the module we had this fragment from */
        Frag->Obj = O;
    }

    /* Return the section */
    return Sec;
}