Example #1
0
	Joint* PartContainer::findJoint(std::string partName, PartContainer::searchDirection sd)
	{
		if (sd == PartContainer::searchDirection::NEXT) {

			// find the given element
			std::vector<std::string>::iterator it = orderedPartList.begin();
			for (; it != orderedPartList.end(); it++) {
				if (*it == partName)break;
			}

			// if element not found
			if (it == orderedPartList.end())return nullptr;

			// if element found try to found the next one
			Part* tempPtr;
			for (it++; it != orderedPartList.end(); it++) {
				tempPtr = findPart(*it);
				if (tempPtr->getType() == TYPE_JOINT)return dynamic_cast<Joint*>(tempPtr);
			}

			// if we tried to found it but we failed
			return nullptr;

		}
		
		if (sd == PartContainer::searchDirection::PREVIOUS) {
			// find the given element
			std::vector<std::string>::reverse_iterator it = orderedPartList.rbegin();
			for (; it != orderedPartList.rend(); it++) {
				if (*it == partName)break;
			}

			// if element not found
			if (it == orderedPartList.rend())return nullptr;

			// if element found try to found the next one
			Part* tempPtr;
			for (it++; it != orderedPartList.rend(); it++) {
				tempPtr = findPart(*it);
				if (tempPtr->getType() == TYPE_JOINT)return dynamic_cast<Joint*>(tempPtr);
			}

			// if we tried to found it but failed
			return nullptr;
		
		}

		return nullptr;
	}
double KSimExponentStep::next(double value) const
{
	tParts part;
	double res;
	if(countSteps() && findPart(value, part))
	{
		if (part.result > value)
		{
			res = part.result;
		}
		else if(part.factorIndex < stepList.count()-1)
		{
			res = convert (part.factorIndex+1,part.exponent);
		}
		else
		{
			res = convert (0,part.exponent+1);
		}
	}
	else
	{
		res = value;
	}
	return res;
}
double KSimExponentStep::previous(double value) const
{
	tParts part;
	double res;
	
	if(countSteps() && findPart(value, part))
	{
		if (part.result < value)
		{
			res = part.result;
		}
		else if(part.factorIndex > 0)
		{
			res = convert (part.factorIndex-1,part.exponent);
		}
		else
		{
			res = convert (stepList.count()-1,part.exponent-1);
		}
	}
	else
	{
		res = value;
	}
	return res;
}
Example #4
0
// -----------------------------------------------------------------
void printPart( const_Part pt )
{
	int root;
	for (int k=0; k<pt->num; k++) {
		root = findPart( pt, k );
		printf( "Element %i belongs to block %i\n",
				pt->universe[k].id, root );
	}
}
Example #5
0
File: main.c Project: dougvk/CS223
// ------------------------------------------------------------------------
static void testPartition( Part pt )
{
	char c;
	int n;
	int x, y, xroot, yroot, newroot;
	int ch;

	for (;;) {
		printf( "Command: ");
		n = scanf( " %c", &c );
		if (n==EOF) break;
		if (c=='.') break;
		switch (c) {
		case 'u':
			n = scanf( "%i%i", &x, &y);
			if (n!=2) break;
			if (x<0 || x >= SIZE || y<0 || y >= SIZE) break;
			xroot = findPart( pt, x );
			yroot = findPart( pt, y );
			newroot = unionPart( pt, xroot, yroot );
			printf( "Union has block id %i\n", newroot );
			break;
		case 'f':
			n = scanf( "%i", &x );
			if (n!=1) break;
			if (x<0 || x >= SIZE) break;
			xroot = findPart( pt, x );
			printf( "%i is in block %i\n", x, xroot );
			break;
		case 'p':
			printPart( pt );
			break;
		default:
			printf( "Unknown command '%c'\n", c);
		}
		// skip remainder of line
		do {
			ch = getchar();
			if (ch == EOF) break;
		} while( ch != '\n' );
	}
}
double KSimExponentStep::adjust(double value) const
{
	tParts part;
	if(countSteps() && findPart(value, part))
	{
		return part.result;
	}
	else
	{
		return value;
	}
}
Example #7
0
bool DescriptionPaint::select( int x, int y )
//-------------------------------------------
{
    bool                ret = false;
    DescriptionPart *   part;
    int                 idx;

    if( x < _rect.x() || x > _rect.x() + _rect.w() )
        return false;

    if( y < _rect.y() || y > _rect.y() + _rect.h() )
        return false;

    part = findPart( x, y, idx );

    if( part && part->_symbol ) {
        _current = idx;
        return true;
    }

    return false;
}