예제 #1
0
파일: Power.cpp 프로젝트: Ziple/ShadeGen
Operator* Power::Simplified(
    Context* nctx,
    TypeCorrespondanceTable& table )
{
    Operator* sf = mySubOps[0]->Simplified(nctx, table);
    Operator* ss = mySubOps[1]->Simplified(nctx, table);
    
    if( sf->IsConstant() && ss->IsConstant() )
    {
        Constant* csf = reinterpret_cast<Constant*>(sf);
        Constant* css = reinterpret_cast<Constant*>(ss);
        
        return new Constant( nctx, std::pow(csf->GetValue(), css->GetValue() ) );
    }
    else if( ss->IsNull() )
        return new Constant( nctx, 1.0 );
    else if( ss->IsOne() )
        return sf;
    else
        return new Power( nctx, sf, ss );
}
예제 #2
0
파일: Division.cpp 프로젝트: Ziple/ShadeGen
Operator* Division::Simplified(
    Context* nctx,
    TypeCorrespondanceTable& table )
{
    Operator* fp = mySubOps[0]->Simplified(nctx, table);
    Operator* fs = mySubOps[1]->Simplified(nctx, table);
    
    if( fp->IsNull() )
        return new Constant( nctx, 0.0, table[GetType()] );
    else if( fp->IsOne() )
        return new Inverse( nctx, fs );
    else if( fp->IsConstant() && fs->IsConstant() )
    {
        Constant* cfp = reinterpret_cast<Constant*>(fp);
        Constant* cfs = reinterpret_cast<Constant*>(fs);
        
        return new Constant( nctx, cfp->GetValue() / cfs->GetValue(), table[GetType()] );
    }
    else
        return new Division( nctx, fp, fs );
}