Esempio n. 1
0
void Node::merge() const
{
    int i, j;
    int x, y, idx;

    int lDofsSize, lDofsToElim;
    int rDofsSize, rDofsToElim;

    lDofsSize = getLeft()->getDofs().size();
    lDofsToElim = getLeft()->getDofsToElim();

    rDofsSize = getRight()->getDofs().size();
    rDofsToElim = getRight()->getDofsToElim();

    for (j = lDofsToElim; j < lDofsSize; ++j) {
        x = leftPlaces[j - lDofsToElim];
        for (i = lDofsToElim; i < lDofsSize; ++i) {
	    y = leftPlaces[i - lDofsToElim];
	    idx = system->index(x, y);
            system->matrix[idx] = left->system->matrix[system->index(j, i)];
        }
        system->rhs[x] = left->system->rhs[j];
    }
    for (j = rDofsToElim; j < rDofsSize; ++j) {
        x = rightPlaces[j - rDofsToElim];
        for (i = rDofsToElim; i < rDofsSize; ++i) {
            y = rightPlaces[i - rDofsToElim];
	    idx = system->index(x, y);
            system->matrix[idx] += right->system->matrix[system->index(j, i)];
        }
        system->rhs[x] += right->system->rhs[j];
    }
}
Esempio n. 2
0
void OpNode::writeToFile(std::ofstream &os) const
{
    os <<"(" << " " << this->_nId << " "; 
 
    // To-Do print node data
    
    if( getLeft() != nullptr)
    {
        getLeft()->writeToFile(os);
    }
    else
    {
        os << "NULL" << " ";    
    }

    if( getRight() != nullptr)
    {
        getRight()->writeToFile(os);
    }
    else
    {
        os << "NULL" << " ";
    }

    os << ")" << " ";
    
}
Esempio n. 3
0
void TopWindow::processEvent( EvtMotion &rEvtMotion )
{
    // New control hit by the mouse
    CtrlGeneric *pNewHitControl =
        findHitControl( rEvtMotion.getXPos() - getLeft(),
                        rEvtMotion.getYPos() - getTop() );

    setLastHit( pNewHitControl );

    /// Update the help text
    VarManager *pVarManager = VarManager::instance( getIntf() );
    if( pNewHitControl )
    {
        pVarManager->getHelpText().set( pNewHitControl->getHelpText() );
    }

    // Send a motion event to the hit control, or to the control
    // that captured the mouse, if any
    CtrlGeneric *pActiveControl = pNewHitControl;
    if( m_pCapturingControl )
    {
        pActiveControl = m_pCapturingControl;
    }
    if( pActiveControl )
    {
        // Compute the coordinates relative to the window
        int xPos = rEvtMotion.getXPos() - getLeft();
        int yPos = rEvtMotion.getYPos() - getTop();
        // Send a motion event
        EvtMotion evt( getIntf(), xPos, yPos );
        pActiveControl->handleEvent( evt );
    }
}
Esempio n. 4
0
void Evidence::print(FILE* file, int indent) {
  fprintf(file, "%*sEvidence:\n", indent, "");
  if (getLeft() != nullptr) {
    fprintf(file, "%*sleft: type = %s\n", indent + 2, "", getLeft()->getTyp()->toString().c_str());
    getLeft()->print(file, indent + 4);
  }
  if (getRight() != nullptr) {
    fprintf(file, "%*sright: type = %s\n", indent + 2, "", getRight()->getTyp()->toString().c_str());
    getRight()->print(file, indent + 4);
  }
  if (flag_forloop) {
    fprintf(file, "%*sFor: ", indent + 2, "");
    if (istmp) {
      fprintf(file, "  %s", tmparg->toString().c_str());
    }
    for (size_t i = 0; i < args.size(); ++i) {
      fprintf(file, "  %s", args[i]->toString().c_str());
    }
    fprintf(file, "\n");
    if (cond != nullptr) {
      fprintf(file, "%*sCond:\n", indent + 2, "");
      getCond()->print(file, indent + 4);
    }
  }
}
Esempio n. 5
0
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);
        }
      }
    }
  }

}
Esempio n. 6
0
void Node::display ()
{
	std::cout << getValue() << std::endl;
	if (getLeft() != NULL)
		getLeft()->display();
	if (getRight() != NULL)
		getRight()->display();
}
Esempio n. 7
0
void Cell<D,C>::WriteTree(std::ostream& os, int indent) const
{
    os<<std::string(indent*2,'.')<<*this<<std::endl;
    if (getLeft()) {
        getLeft()->WriteTree(os, indent+1);
        getRight()->WriteTree(os, indent+1);
    }
}
Esempio n. 8
0
// dieses Rect relativ zum anderen...
eTouchType Rect::getTouchType(const Rect& rect) const
{
	if(!isTouched(rect)) {
		return TOUCHES_NO_TOUCH;
	}

	// ist 'rect' innerhalb dieses Rects?
	if(isRectInside(rect)) {
		return TOUCHES_IS_COMPLETELY_INSIDE;
	} else if(isTopLeftCornerInside(rect.getTopLeft()) && isBottomLeftCornerInside(rect.getBottomLeft())) {
		return TOUCHES_CROSSES_RIGHT_BORDER;
	} else if(isTopLeftCornerInside(rect.getTopLeft()) && isTopRightCornerInside(rect.getTopRight())) {
		return TOUCHES_CROSSES_LOWER_BORDER;
	} else if(isTopRightCornerInside(rect.getTopRight()) && isBottomRightCornerInside(rect.getBottomRight())) {
		return TOUCHES_CROSSES_LEFT_BORDER;
	} else if(isBottomRightCornerInside(rect.getBottomRight()) && isBottomLeftCornerInside(rect.getBottomLeft())) {
		return TOUCHES_CROSSES_UPPER_BORDER;
	} else if(isTopLeftCornerInside(rect.getTopLeft())) {
		return TOUCHES_CROSSES_BOTTOM_RIGHT_CORNER;
	} else if(isTopRightCornerInside(rect.getTopRight())) {
		return TOUCHES_CROSSES_BOTTOM_LEFT_CORNER;
	} else if(isBottomRightCornerInside(rect.getBottomRight())) {
		return TOUCHES_CROSSES_TOP_LEFT_CORNER;
	} else if(isBottomLeftCornerInside(rect.getBottomLeft())) {
		return TOUCHES_CROSSES_TOP_RIGHT_CORNER;
	}

	else if((rect.getLeft() < getLeft()) && (rect.getRight() > getRight()) && (rect.getTop() >= getTop()) && (rect.getBottom() <= getBottom())) { // ? = 
		return TOUCHES_CROSSES_LEFT_AND_RIGHT_BORDER;
	} else if((rect.getTop() < getTop()) && (rect.getBottom() > getBottom()) && (rect.getLeft() >= getLeft()) && (rect.getRight() <= getRight())) {
		return TOUCHES_CROSSES_TOP_AND_BOTTOM_BORDER;
	}

	else if((rect.getLeft() == getRight()) && (rect.getTop() == getTop()) && (rect.getBottom() == getBottom())) {
		return TOUCHES_RIGHT_BORDER;
	} else if((rect.getTop() == getBottom()) && (rect.getLeft() == getLeft()) && (rect.getRight() == getRight())) {
		return TOUCHES_LOWER_BORDER;
	} else if((rect.getRight() == getLeft()) && (rect.getTop() == getTop()) && (rect.getBottom() == getBottom())) {
		return TOUCHES_LEFT_BORDER;
	} else if((rect.getBottom() == getTop()) && (rect.getLeft() == getLeft()) && (rect.getRight() == getRight())) {
		return TOUCHES_UPPER_BORDER;
	}

	else if((rect.isTopLeftCornerInside(getTopLeft())) && (rect.isTopRightCornerInside(getTopRight())) && (!rect.isBottomRightCornerInside(getBottomRight())) && (!rect.isBottomLeftCornerInside(getBottomLeft()))) {
		return TOUCHES_CROSSES_UPPER_AREA;
	} else if((!rect.isTopLeftCornerInside(getTopLeft())) && (rect.isTopRightCornerInside(getTopRight())) && (rect.isBottomRightCornerInside(getBottomRight())) && (!rect.isBottomLeftCornerInside(getBottomLeft()))) {
		return TOUCHES_CROSSES_RIGHT_AREA;
	} else if((!rect.isTopLeftCornerInside(getTopLeft())) && (!rect.isTopRightCornerInside(getTopRight())) && (rect.isBottomRightCornerInside(getBottomRight())) && (rect.isBottomLeftCornerInside(getBottomLeft()))) {
		return TOUCHES_CROSSES_LOWER_AREA;
	} else if((rect.isTopLeftCornerInside(getTopLeft())) && (!rect.isTopRightCornerInside(getTopRight())) && (!rect.isBottomRightCornerInside(getBottomRight())) && (rect.isBottomLeftCornerInside(getBottomLeft()))) {
		return TOUCHES_CROSSES_LEFT_AREA;
	}

	else { 
		return TOUCHES_NO_TOUCH;
	}
}
Esempio n. 9
0
void Button::draw()
{
	COLOUR farg1, farg2, farg3, farg4;
	if ( getStatus() == Pressed || getStatus() == Active)
	{
		farg1 = WHITE;
		farg2 = BLACK;
		farg3 = DARKGREY;
		farg4 = LIGHTGREY;
	}
	else {
		farg1 = BLACK;
		farg2 = WHITE;
		farg3 = LIGHTGREY;
		farg4 = DARKGREY;
	}
//Bakgrund
	rectfill(bmp, getLeft(), getTop(), getRight(), getBottom(), GREY);
//Texten
	textout(bmp, font, getText(), getTextPosX(), getTextPosY(), getTextColor());
//Yttre boxen
	line(bmp, getLeft(), getBottom(), getRight(), getBottom(), farg1);
	line(bmp, getRight(), getBottom(), getRight(), getTop(), farg1);
	line(bmp, getLeft(), getBottom()-1, getLeft(), getTop(), farg2);
	line(bmp, getLeft(), getTop(), getRight()-1, getTop(), farg2);
//Inre boxen
	line(bmp, getLeft()+1, getBottom()-1, getLeft()+1, getTop()+1, farg3);
	line(bmp, getLeft()+1, getTop()+1, getRight()-1, getTop()+1, farg3);
	line(bmp, getRight()-1, getBottom()-1, getRight()-1, getTop()+1, farg4);
	line(bmp, getLeft()+1, getBottom()-1, getRight()-1, getBottom()-1, farg4);
}
Esempio n. 10
0
File: main.c Progetto: ctag/cpe495
/*
 * ======== main ========
 */
void main(void)
{
    WDT_A_hold(WDT_A_BASE); //Stop watchdog timer

    // Minimum Vcore setting required for the USB API is PMM_CORE_LEVEL_2
    PMM_setVCore(PMM_CORE_LEVEL_2);
    USBHAL_initPorts();           // Config GPIOS for low-power (output low)
    USBHAL_initClocks(8000000);   // Config clocks. MCLK=SMCLK=FLL=8MHz; ACLK=REFO=32kHz
    USB_setup(TRUE,TRUE);  // Init USB & events; if a host is present, connect
    initRTC();             // Start the real-time clock

    __enable_interrupt();  // Enable interrupts globally

    int prevLeft = getLeft();
    int prevRight = getRight();
    int left;
    int right;

    while (1)
    {
        // Enter LPM0, which keeps the DCO/FLL active but shuts off the
        // CPU.  For USB, you can't go below LPM0!
        __bis_SR_register(LPM0_bits + GIE);

        // If USB is present, sent the time to the host.  Flag is set every sec

        left = getLeft();
        right = getRight();
        timeStr[0] = '[';
        itoa(left, &timeStr[1], 10);
        itoa(right, &timeStr[2], 10);
        timeStr[3] = ']';
        timeStr[4] = '\n';
        timeStr[5] = '\0';
//
//        if (bSendTimeToHost)
//        {
//            bSendTimeToHost = FALSE;
//            convertTimeBinToASCII(timeStr);

            // This function begins the USB send operation, and immediately
            // returns, while the sending happens in the background.
            // Send timeStr, 9 bytes, to intf #0 (which is enumerated as a
            // COM port).  1000 retries.  (Retries will be attempted if the
            // previous send hasn't completed yet).  If the bus isn't present,
            // it simply returns and does nothing.
            if (USBCDC_sendDataInBackground(timeStr, 6, CDC0_INTFNUM, 1000))
            {
              _NOP();  // If it fails, it'll end up here.  Could happen if
                       // the cable was detached after the connectionState()
            }           // check, or if somehow the retries failed
//        }
    }  //while(1)
}  //main()
Esempio n. 11
0
 int getLeft(int A[], int start, int idx, int target) {
     if (A[start] == target)
         return start;
     int mid = (start + idx) / 2;
     if (A[mid] < target)
         return getLeft(A, mid+1, idx, target);
     else if (A[mid-1] == target)
         return getLeft(A, start, mid-1, target);
     else 
         return mid;
 }
Esempio n. 12
0
int Node::treeSize(){
    int ret = 1;

    if (getLeft() != NULL)
    	    ret += getLeft()->treeSize();

    if (getRight() != NULL)
        ret += getRight()->treeSize();

    return (ret);
}
Esempio n. 13
0
// ok, laeuft perfekt.
std::list<Rect> Rect::withoutRect(const Rect& rect) const
{

	// Schnittmenge:
	std::list<Rect> rects;
	if(rect == *this) {
		return rects;
	}

	Rect cut = commonRect(rect);

	// Schnitt ist gleich dem Rechteck
	if(cut == *this) {
		return rects;
	} else if(cut.getWidth() == 0 || cut.getHeight() == 0) {
		rects.push_back(*this);
		return rects;
	} else
	{
		// Sonst: bis zu 4 rectangles:
		// Rechteck mit vollstaendiger Breite, wenn cut im unteren Teil stattgefunden hat
		if(cut.getTop() > getTop()) {
			Rect r(getTopLeft(), Point(getRight(), cut.getTop()));
			if(r.getWidth() > 0 && r.getHeight() > 0) {
				rects.push_back(r);
			}
		}
		// links
		if(cut.getLeft() > getLeft()) {
			Rect r(Point(getLeft(), cut.getTop()), cut.getBottomLeft());
			if(r.getWidth() > 0 && r.getHeight() > 0) {
				rects.push_back(r);
			}
		}
		// rechts
		if(cut.getRight() < getRight()) {
			Rect r(cut.getTopRight(), Point(getRight(), cut.getBottom()));
			if(r.getWidth() > 0 && r.getHeight() > 0) {
				rects.push_back(r);
			}
		}
		// unten
		// Rechteck mit vollstaendiger Breite, wenn unter dem cut Recht noch Platz ist
		if(cut.getBottom() < getBottom()) {
			Rect r(Point(getLeft(), cut.getBottom()), getBottomRight());
			if(r.getWidth() > 0 && r.getHeight() > 0) {
				rects.push_back(r);
			}
		}
	}
	return rects;
}
Esempio n. 14
0
			void inorder(::std::ostream & out, uint64_t node) const
			{
				out << "(";
				if ( getLeft(node) != n )
					inorder(out,getLeft(node));
				out << getKey(node);
				out << "[";
				out << getIndex(node);
				out << "]";
				if ( getRight(node) != n )
					inorder(out,getRight(node));
				out << ")";
			}
void Radiolist::genericFunc3(int x, int y, bool arg)
{
	if (getVisible())
	{
		for (int i = 0; i < lines.size(); i++)
		{
			if ((x >= lines[i].getLeft() - getLeft()) && (x <= (lines[i].getLeft() - getLeft() + lines[i].getMaxWidth())))
			if (y >= lines[i].getTop() - getTop() && y <= (lines[i].getTop() - getTop() + lines[i].getHight()))
			{
				lines[i].genericFunc1();
			}
		}
	}
}
Esempio n. 16
0
Int32 StagedViewport::getPixelLeft(void) const
{
    if(!getFrameBufferObject())
    {   // => behave like normal viewport
        return Viewport::calcPixelLeft();
    }
    else
    {   // => behave like FBOViewport
        if(getLeft() > 1)
            return Int32(getLeft());

        return Int32(getFrameBufferObject()->getWidth() * getLeft());
    }
}
Esempio n. 17
0
void test_inserting_two_childrens_at_depth_two(){
	BinaryTree tree = createBinaryTree(cmpInt);
	int element1  = 10,element2 = 20,element3 = 30,element4 = 40,element5 = 50;
	BinaryTreeNode *node;
	insert(&tree,&element1,NULL);
	insert(&tree,&element2,&element1);
	insert(&tree,&element3,&element1);
	insert(&tree,&element4,&element2);
	insert(&tree,&element5,&element2);
	ASSERT(&element2 == getLeft(&tree,&element1));
	ASSERT(&element3 == getRight(&tree,&element1));
	ASSERT(&element4 == getLeft(&tree,&element2));
	ASSERT(&element5 == getRight(&tree,&element2));
};
Esempio n. 18
0
void TCODBsp::resize(int x,int y, int w, int h) {
	this->x=x;
	this->y=y;
	this->w=w;
	this->h=h;
	if ( getLeft() ) {
		if ( horizontal ) {
			getLeft()->resize(x,y,w,position-y);
			getRight()->resize(x,position,w,y+h-position);
		} else {
			getLeft()->resize(x,y,position-x,h);
			getRight()->resize(position,y,x+w-position,h);
		}
	}
}
Esempio n. 19
0
void straight() {
    LD.setLeftDigit('S');
    LPC_GPIO0->FIOCLR = (1 << AMUX);        // 0b10 = turn right
    LPC_GPIO0->FIOSET = (1 << BMUX);
    bool exit=true;
    while(exit)
    {
        if( (!getLeft()&&!getRight())
                || (!getLLeft() && !getLeft() && !getRRight())
                || (!getLLeft() && !getRight() && !getRRight()) )
        {
            exit=false;
        }
    }
}
Esempio n. 20
0
void
BddNodeV::drawBddRecur(ofstream& ofile) const
{
   // TODO
   BddNodeVInt* n = getBddNodeVInt();
   if (n->isVisited())
      return;
   n->setVisited();
   if(isTerminal())
      return;
   BddNodeV left = getLeft();
   BddNodeV right = getRight();

   ofile << "   { rank = same; " << getLevel() << "; \"" << getLabel()
         << "\"; }\n";

   ofile << "   \"" << getLabel() << "\" -> \"" << left.getLabel() << "\"";
   ofile << ((left.isNegEdge())? " [arrowhead=odot]" : ";") << endl;

   ofile << "   \"" << getLabel() << "\" -> \"" << right.getLabel()
         << "\"[style = dotted ] [color=red]";
   ofile << ((right.isNegEdge())? " [arrowhead=odot]" : ";") << endl;

   left.drawBddRecur(ofile);
   right.drawBddRecur(ofile);
}
Esempio n. 21
0
File: gui.cpp Progetto: emlai/zenith
Rect GUI::getCommandLineArea(const Window& window)
{
    auto worldViewport = getWorldViewport(window);
    auto questionArea = getQuestionArea(window);
    return Rect(worldViewport.getLeft() + spacing.x, worldViewport.getTop() + spacing.y,
                worldViewport.getWidth() - spacing.x * 2, questionArea.getHeight());
}
Esempio n. 22
0
// Technically, this is incorrect. This is a intersect
bool Rect::contains(const Rect &rect) const
{
	return getLeft() < rect.getRight() &&
		getRight() > rect.getLeft() &&
		getTop() < rect.getBottom() &&
		getBottom() > rect.getTop();
}
Esempio n. 23
0
bool Recti::contains(const Vector2i &pt) const
{
	return getLeft() < pt.x &&
		getTop() < pt.y &&
		getRight() > pt.x &&
		getBottom() > pt.y;
}
Esempio n. 24
0
	bool Rectangle::overlapping(const Rectangle &rectangle)
	{
		return (rectangle.getLeft() < getRight()) &&
				(rectangle.getRight() > getLeft()) &&
				(rectangle.getTop() > getBottom()) &&
				(rectangle.getBottom() < getTop());
	}
Esempio n. 25
0
void TopWindow::processEvent( EvtDragDrop &rEvtDragDrop )
{
    // Get the control hit by the mouse
    int xPos = rEvtDragDrop.getXPos() - getLeft();
    int yPos = rEvtDragDrop.getYPos() - getTop();

    CtrlGeneric *pHitControl = findHitControl( xPos, yPos );
    if( pHitControl && pHitControl->getType() == "tree" )
    {
        // Send a dragDrop event
        EvtDragDrop evt( getIntf(), xPos, yPos, rEvtDragDrop.getFiles() );
        pHitControl->handleEvent( evt );
    }
    else
    {
        list<string> files = rEvtDragDrop.getFiles();
        list<string>::const_iterator it = files.begin();
        for( bool first = true; it != files.end(); ++it, first = false )
        {
            bool playOnDrop = m_playOnDrop && first;
            CmdAddItem( getIntf(), it->c_str(), playOnDrop ).execute();
        }
    }
    m_pDragControl = NULL;
}
Esempio n. 26
0
inline Box<float>::operator Box<int>() const
{
	Box<int> box;
	box.setCoords(static_cast<int>(roundf(getLeft())), static_cast<int>(roundf(getTop())), 
			static_cast<int>(roundf(getRight())), static_cast<int>(roundf(getBottom())));
	return box;
}
Esempio n. 27
0
inline Box<double>::operator Box<long>() const
{
	Box<long> box;
	box.setCoords(static_cast<long>(round(getLeft())), static_cast<long>(round(getTop())), 
			static_cast<long>(round(getRight())), static_cast<long>(round(getBottom())));
	return box;
}
Esempio n. 28
0
//----------------------------------------------------------
//	isActive används när man vill skriva till TextFältet
//----------------------------------------------------------
void TextField::isActive()
{
	bool stop = false;
	while(!stop)
	{
		gotoxy(getLeft(), getTop());
		this->draw();
		char key=getch();
	/*Special*/
		if(key==0)
		{
			char key=getch();
			switch(key)
			{
/*Pil VÄNSTER*/	case CHLEFT: TextObjekt::left(); break;
	/*Pil HÖGER*/	case CHRIGHT: TextObjekt::right(); break;
	/*Del*/			case CHDEL: TextObjekt::del(); break;
	/*ANNAN*/		default: break;
			}
		}
		switch(key)
		{
/*Baksteg*/		case 8: this->baksteg(); break;
/*TAB <-->*/	case 9: for(int i=0; i<4; ++i)
							{	this->putIn(' ');	}
					break;
	/*Esc*/		case CHESC: stop = true; break;
	/*Enter*/	case ENTER: stop = true; break;
/*Tecken a-z*/	default: this->putIn(key); break;
		}
	}
}
void matrixCreate(SparseMatrix& outMatrix, int n, int mn, IImage& maskImage) {
	cout << "ImageEditingUtils::matrixCreate("<<((intptr_t)(&outMatrix))<<","<<n<<","<<mn<<","<<((intptr_t)(&maskImage))<<")"<<endl;
	for (int pixel = 0; pixel < mn; pixel++) {
		int pxlX = pixel % n;
		int pxlY = (int) floor((float)pixel / (float)n);
		int maskRGB = maskImage.getRGB(pxlX, pxlY);
		if ((maskRGB & 0x00ffffff) == BLACK) {
			outMatrix(pixel,pixel) = 1;
		} else {
			// add 1s in sides
			int numOfNeighbors = 0;
			int neighborsArray[4] = {0};
			neighborsArray[0] = getUpper(pixel, n);
			neighborsArray[1] = getLower(pixel, n, mn);
			neighborsArray[2] = getRight(pixel, n);
			neighborsArray[3] = getLeft(pixel, n);
			for (int j = 0; j < 4; j++) {
				if (neighborsArray[j] >= 0) {
					outMatrix(pixel,neighborsArray[j]) = 1;
					numOfNeighbors++;
				}
			}

			//add -4, -3 or -2 in middle
			outMatrix(pixel,pixel) = (-1) * numOfNeighbors;
		}
	}
}
 virtual void accept(FieldVisitor& v)
 {
   v.enter(*this);
   getLeft().accept(v);
   getRight().accept(v);
   v.exit(*this);
 }