本文整理汇总了C++中Operand::IsScalar方法的典型用法代码示例。如果您正苦于以下问题:C++ Operand::IsScalar方法的具体用法?C++ Operand::IsScalar怎么用?C++ Operand::IsScalar使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Operand
的用法示例。
在下文中一共展示了Operand::IsScalar方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Select
bool GradeSelector::Select( void )
{
if( !operand )
return false;
Expander expander;
expander.expansionTarget = Expander::SUM_OF_BLADES;
expander.ManipulateTree( &operand );
Addition* addition = dynamic_cast< Addition* >( operand );
if( !addition )
return false;
Addition::OperandList::Node* node = addition->operandList.Head();
while( node )
{
Addition::OperandList::Node* nextNode = node->Next();
Operand* nestedOperand = node->data;
int count = -1;
OuterProduct* outerProduct = dynamic_cast< OuterProduct* >( nestedOperand );
Vector* vector = dynamic_cast< Vector* >( nestedOperand );
if( outerProduct && outerProduct->IsHomogeneousOfVectors() )
count = outerProduct->operandList.Count();
else if( vector )
count = 1;
else if( nestedOperand->IsScalar() )
count = 0;
if( ( count == grade && type == TYPE_EXCLUSIVE ) || ( count != grade && type == TYPE_INCLUSIVE ) )
addition->operandList.Remove( node );
node = nextNode;
}
return true;
}
示例2: CombineLikeOperands
bool Sum::CombineLikeOperands( void )
{
for( OperandList::Node* nodeA = operandList->Head(); nodeA; nodeA = nodeA->Next() )
{
Operand* operandA = nodeA->data;
for( OperandList::Node* nodeB = nodeA->Next(); nodeB; nodeB = nodeB->Next() )
{
Operand* operandB = nodeB->data;
if( operandA->IsScalar() && operandB->IsScalar() )
{
Operand* scalar = AddScalars( operandA, operandB );
if( scalar )
{
operandList->InsertAfter()->data = scalar;
operandList->Remove( nodeA );
operandList->Remove( nodeB );
return true;
}
}
else if( dynamic_cast< Vector* >( operandA ) && dynamic_cast< Vector* >( operandB ) )
{
Vector* vectorA = ( Vector* )operandA;
Vector* vectorB = ( Vector* )operandB;
if( 0 == strcmp( vectorA->GetName(), vectorB->GetName() ) )
{
Operand* scalarA = vectorA->GetScalar();
Operand* scalarB = vectorB->GetScalar();
vectorA->SetScalar( 0, false );
vectorB->SetScalar( 0, false );
if( !scalarA )
{
NumericScalar* numericScalar = new NumericScalar();
numericScalar->SetReal( 1.0 );
scalarA = numericScalar;
}
if( !scalarB )
{
NumericScalar* numericScalar = new NumericScalar();
numericScalar->SetReal( 1.0 );
scalarB = numericScalar;
}
Sum* scalar = new Sum();
scalar->operandList->InsertAfter()->data = scalarA;
scalar->operandList->InsertAfter()->data = scalarB;
vectorB->SetScalar( scalar );
operandList->Remove( nodeA );
return true;
}
}
else if( ( operandA->IsBlade() && operandB->IsBlade() ) ||
( operandA->IsVersor() && operandB->IsVersor() ) )
{
Operation* operationA = ( Operation* )operandA;
Operation* operationB = ( Operation* )operandB;
if( OperationsAlike( operationA, operationB ) )
{
// Degenerates are removed well before we can get here, so this shouldn't happen.
Vector* vector = operationB->FindLeadingVector();
if( !vector )
{
Error* error = new Error();
error->Format( "Sum expected to find a leading vector, but didn't." );
throw error;
}
// An empty geometric product in either case will do fine.
GeometricProduct* scalarA = operationA->StripScalars();
GeometricProduct* scalarB = operationB->StripScalars();
Sum* scalar = new Sum();
scalar->operandList->InsertAfter()->data = scalarA;
scalar->operandList->InsertAfter()->data = scalarB;
vector->MarryWithScalar( scalar );
operandList->Remove( nodeA );
return true;
}
}
}
}
return false;
}