/*************************************************************************** * Copyright (C) 2003-2004 by David Saxton * * david@bluehaze.org * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * ***************************************************************************/ #include "vec.h" #include #include #include using namespace std; Vector::Vector( const int size ) { m_size = size; m_vec = new double[m_size]; reset(); b_changed = true; } Vector::~Vector() { // Hmm...this looks like it's the correct format, although valgrind complains // about improper memory use. Interesting. "delete m_vec" definitely leaks // memory, so this seems like the lesser of two evils. I miss C memory allocation // somtimes, with a nice simple free :p delete [] m_vec; } void Vector::reset() { for ( int i=0; isize() == size() ); for ( int i = 0; i < m_size; ++i ) { double limitAbs = std::abs( limitVector->m_vec[i] ); if ( limitAbs < 1e-6 ) limitAbs = 1e-6; double thisAbs = std::abs( m_vec[i] ); if ( thisAbs < 1e-6 ) thisAbs = 1e-6; if ( (thisAbs / limitAbs) > scaleMax ) m_vec[i] /= (thisAbs / limitAbs); else if ( (limitAbs / thisAbs) > scaleMax ) m_vec[i] /= (limitAbs / thisAbs); } b_changed = true; } void Vector::operator += ( Vector *rhs ) { if (!rhs) return; for ( int i=0; i