Complex add (Complex& a, Complex& b) { double real = a.getReal() + b.getReal(); double imag = a.getImag() + b.getImag(); Complex sum (real, imag); return sum; }
const Complex operator/( const Complex& lComplex, const Complex& rComplex ) // Non-member non-friend operator function // // PRE: (none) // // POST: the quotient of this Complex and rComplex is returned { double divisor = rComplex.getReal()*rComplex.getReal() + rComplex.getImag()*rComplex.getImag(); double realNum = lComplex.getReal()*rComplex.getReal() + lComplex.getImag()*rComplex.getImag(); double imagNum = lComplex.getImag()*rComplex.getReal() - lComplex.getReal()*rComplex.getImag(); return Complex( realNum/divisor, imagNum/divisor ); }
void Console::draw( ofVec2f pos, int state, int seed, Complex complexStateZero, Complex complexStateOne ) { // Draw console to the screen ofPushMatrix(); ofTranslate(pos.x, pos.y); mFont.drawString("***************************************",0,0); for(int i = 1; i < 23; i++) { mFont.drawString("*", 0, LINE_SPACING * i); mFont.drawString("*", 267, LINE_SPACING * i); } mFont.drawString("Summary", 55, 2 * LINE_SPACING); mFont.drawString("=============================", 55, 3 * LINE_SPACING); mFont.drawString("Measured: " + ofToString(state), 55,LINE_SPACING*4); mFont.drawString("QuantumSeed: " + ofToString(seed), 55,LINE_SPACING*5); mFont.drawString("Zero State: " + ofToString(abs(complexStateZero.getReal())) + " + " + ofToString(complexStateZero.getImag()) + "i", 55,LINE_SPACING*6); mFont.drawString("One State: " + ofToString(abs(complexStateOne.getReal())) + " + " + ofToString(complexStateOne.getImag()) + "i", 55,LINE_SPACING*7); mFont.drawString("***************************************", 0,LINE_SPACING*23); mFont.drawString("console log", 55, 9 * LINE_SPACING); mFont.drawString("=============================", 55, 10 * LINE_SPACING); int lineNum = 0; for (std::list<string>::const_iterator iterator = mLog.begin(); iterator != mLog.end(); ++iterator) { string line = *iterator; mFont.drawString(" > " + line, 55, (11+lineNum) * LINE_SPACING); lineNum++; } ofPopMatrix(); addMessage("Measured state: " + ofToString(state)); // If the quantum seed has changed then write this to the console if(seed != mLastQuantumSeed) { mLastQuantumSeed = seed; addMessage("Updated seed: " + ofToString(seed)); } }
Complex::Complex(const Complex &orig) { setReal(orig.getReal()); setImag(orig.getImag()); }