Esempio n. 1
0
int circleLineIntersect(float x1, float y1, float x2, float y2, float cx, float cy, float r, float *f) {
	float dx = x2 - x1;
	float dy = y2 - y1;
	
	float a = dx * dx + dy * dy;
	float b = 2 * (dx * (x1 - cx) + dy * (y1 - cy));
	float c = cx * cx + cy * cy;
	
	c += x1 * x1 + y1 * y1;
	c -= 2 * (cx * x1 + cy * y1);
	c -= r * r;
	
	float delta = b * b - 4 * a * c;
	
	if (delta < 1) {  // Not intersecting or just tangent
    return 0;
	}
	else {
		
		float mu = (-b + sqrt( delta )) / (2*a);
		f[0] = x1 + mu*(dx);
		f[1] = y1 + mu*(dy);
		mu = (-b - sqrt( delta )) / (2*a);
		f[2] = x1 + mu*(dx);
		f[3] = y1 + mu*(dy);
		
		if(!inLine(&f[0], x1, y1, x2, y2))
		{
			if (inLine(&f[2], x1, y1, x2, y2))
			{
				f[0] = f[2];
				f[1] = f[3];
				return 1;
			}
			else
			{
				return 0;
			}
			
		}
		
		if(!inLine(&f[2], x1, y1, x2, y2))
		{
			return 1;
		}
		
		return (delta == 0) ? 1 : 2;
	}
}
Esempio n. 2
0
Type Foam::SubModelBase<CloudType>::getModelProperty
(
    const word& entryName,
    const Type& defaultValue
) const
{
    Type result = defaultValue;

    const dictionary& properties = this->owner().outputProperties();

    if (properties.found(baseName_))
    {
        const dictionary& baseDict = properties.subDict(baseName_);

        if (inLine() && baseDict.found(modelName_))
        {
            baseDict.subDict(modelName_).readIfPresent(entryName, result);
        }
        else if (baseDict.found(modelType_))
        {
            baseDict.subDict(modelType_).readIfPresent(entryName, result);
        }
    }

    return result;
}
Esempio n. 3
0
File: debug.c Progetto: fmccabe/cafe
static DebugWaitFor cmder(debugOptPo opts, processPo p, methodPo mtd, termPo loc, insWord ins) {
  static bufferPo cmdBuffer = Null;

  if (cmdBuffer == Null)
    cmdBuffer = newStringBuffer();

  while (interactive) {
    dbgPrompt(p);
    clearBuffer(cmdBuffer);

    setEditLineCompletionCallback(cmdComplete, (void *) opts);
    retCode res = (debuggerListener == Null ? consoleInput(cmdBuffer) : inLine(debugInChnnl, cmdBuffer, "\n"));
    clearEditLineCompletionCallback();

    switch (res) {
      case Eof:
        return quitDbg;
      case Ok: {
        integer cmdLen = 0;
        char *cmdLine = getTextFromBuffer(cmdBuffer, &cmdLen);

        cmdLine = defltLine(cmdLine, cmdLen, &cmdLen);

        codePoint cmd;
        integer nxt = 0;
        cmd = nextCodePoint(cmdLine, &nxt, cmdLen);

        if (isNdChar((codePoint) cmd)) {
          cmd = 'n';
          nxt = 0;
        }

        for (int ix = 0; ix < opts->count; ix++) {
          if (opts->opts[ix].c == cmd)
            return opts->opts[ix].cmd(&cmdLine[nxt], p, loc, ins, opts->opts[ix].cl);
        }
        outMsg(debugOutChnnl, "invalid debugger command: %s\n", cmdLine);
      }
      default:
        for (int ix = 0; ix < opts->count; ix++)
          outMsg(debugOutChnnl, "%s\n", opts->opts[ix].usage);
        flushFile(debugOutChnnl);
        return moreDebug;
    }
  }
  return moreDebug;
}
Esempio n. 4
0
void Foam::SubModelBase<CloudType>::getModelProperty
(
    const word& entryName,
    Type& value
) const
{
    const dictionary& properties = this->owner().outputProperties();

    if (properties.found(baseName_))
    {
        const dictionary& baseDict = properties.subDict(baseName_);

        if (inLine() && baseDict.found(modelName_))
        {
            baseDict.subDict(modelName_).readIfPresent(entryName, value);
        }
        else if (baseDict.found(modelType_))
        {
            baseDict.subDict(modelType_).readIfPresent(entryName, value);
        }
    }
}
void firstPage::setUp_LineTable(){

    lineTable=ui->lineTable;
    lineTable->verticalHeader()->setVisible(false);
    lineTable->horizontalHeader()->setVisible(false);
    lineTable->setShowGrid(false);

    //column 2 is only used as a spacer
    lineTable->setColumnWidth(2,cWidth);
    lineTable->setTabKeyNavigation(false);

    //////////////////////////////////////////
    //          Format 1. Column            //
    //////////////////////////////////////////

    for(int i = 0; i<lineTable->rowCount() ; i++)
    {
        lineTable->item(i,0)->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
    }

    //make 1. Column unaccesible
    for(int i = 0;i<lineTable->rowCount();i++){

        lineTable->item(i,0)->setFlags(lineTable->item(i,0)->flags() ^ Qt::ItemIsEditable);
        lineTable->item(i,0)->setFlags(lineTable->item(i,0)->flags() ^ Qt::ItemIsSelectable);
        lineTable->item(i,0)->setFlags(lineTable->item(i,0)->flags() ^ Qt::ItemIsUserCheckable);
    }

    // http://www.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/MAC/GREEK.TXT
    lineTable->item(1,0)->setText(QString(QChar(0x03C6))+" =");
    lineTable->item(2,0)->setText(QString(QChar(0x0398))+" =");


    //////////////////////////////////////////////////////////
    //      Put DoubleSpinBoxes in 2.Column of Table        //
    //////////////////////////////////////////////////////////
    for( int i = 0; i < lineTable->rowCount(); i++ )
    {

        if(i==3){
            QSpinBox *spinBox = new QSpinBox();
            spinBox->setValue(0);
            lineTable->setCellWidget( i, 1, spinBox );
        }else
        {

            QDoubleSpinBox *spinBox = new QDoubleSpinBox();
            spinBox->setValue(0);
            lineTable->setCellWidget( i, 1, spinBox );
        }
    }

    //Format SpinBoxes Manually

    static_cast<QSpinBox*>(lineTable->cellWidget(0,1))->setMinimum(0);
    static_cast<QSpinBox*>(lineTable->cellWidget(0,1))->setMaximum(maxA/2);

    static_cast<QSpinBox*>(lineTable->cellWidget(1,1))->setMinimum(-1000);
    static_cast<QSpinBox*>(lineTable->cellWidget(1,1))->setMaximum(1000);

    static_cast<QSpinBox*>(lineTable->cellWidget(2,1))->setMinimum(-1000);
    static_cast<QSpinBox*>(lineTable->cellWidget(2,1))->setMaximum(1000);

    static_cast<QSpinBox*>(lineTable->cellWidget(3,1))->setMinimum(1);
    static_cast<QSpinBox*>(lineTable->cellWidget(3,1))->setMaximum(1000);

    static_cast<QSpinBox*>(lineTable->cellWidget(4,1))->setMinimum(0);
    static_cast<QSpinBox*>(lineTable->cellWidget(4,1))->setMaximum(veloMax);

    ////////////////////////////////////////////////////////////////////////
    //      Load stored values and assign them in 3. and 2. Column        //
    ////////////////////////////////////////////////////////////////////////

    cout<<mLine.getStoredValuesPath()<<endl;
    QFile lineFile(QString::fromStdString(mLine.getStoredValuesPath()));
    lineFile.open(QIODevice::ReadOnly | QIODevice::Text);

    QTextStream inLine(&lineFile);
    for( int i = 0; i < lineTable->rowCount(); i++ )
    {
        if(i==3){
            QLabel *label = new QLabel();
            int x = inLine.readLine().toInt();
            label->setNum(x);
            cout<<x<<endl;
            label->setAlignment(Qt::AlignVCenter);
            lineTable->setCellWidget( i, 3, label );
            static_cast<QSpinBox*>(lineTable->cellWidget(i,1))->setValue(x);
        }else
        {
            QLabel *label = new QLabel();
            double x = inLine.readLine().toDouble();

            if((i==1)||(i==2)){
                x=(x/(2*pi))*360;
            }

            label->setNum(x);
            cout<<x<<endl;
            label->setAlignment(Qt::AlignVCenter);
            lineTable->setCellWidget( i, 3, label );
            static_cast<QDoubleSpinBox*>(lineTable->cellWidget(i,1))->setValue(x);
        }
    }
    lineFile.close();

}
Esempio n. 6
0
void Foam::SubModelBase<CloudType>::setModelProperty
(
    const word& entryName,
    const Type& value
)
{
    dictionary& properties = this->owner().outputProperties();

    if (properties.found(baseName_))
    {
        dictionary& baseDict = properties.subDict(baseName_);

        if (inLine())
        {
            if (baseDict.found(modelName_))
            {
                baseDict.subDict(modelName_).add(entryName, value, true);
            }
            else
            {
                baseDict.add(modelName_, dictionary());
                baseDict.subDict(modelName_).add(entryName, value, true);
            }
        }
        else
        {
            if (baseDict.found(modelType_))
            {
                baseDict.subDict(modelType_).add(entryName, value, true);
            }
            else
            {
                baseDict.add(modelType_, dictionary());
                baseDict.subDict(modelType_).add(entryName, value, true);
            }
        }
    }
    else
    {
        properties.add(baseName_, dictionary());

        if (inLine())
        {
            properties.subDict(baseName_).add(modelName_, dictionary());
            properties.subDict(baseName_).subDict(modelName_).add
            (
                entryName,
                value
            );
        }
        else
        {
            properties.subDict(baseName_).add(modelType_, dictionary());
            properties.subDict(baseName_).subDict(modelType_).add
            (
                entryName,
                value
            );
        }
    }
}