File: vector.h

package info (click to toggle)
kmplot 4%3A16.08.3-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,552 kB
  • ctags: 1,244
  • sloc: cpp: 12,200; xml: 314; sh: 5; makefile: 1
file content (78 lines) | stat: -rw-r--r-- 2,552 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
* KmPlot - a math. function plotter for the KDE-Desktop
*
* Copyright (C) 2006  David Saxton <david@bluehaze.org>
*               
* This file is part of the KDE Project.
* KmPlot is part of the KDE-EDU Project.
*
* 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.
* 
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
* 
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/

#ifndef VECTOR_H
#define VECTOR_H

#include <QVector>

class Value;

/**
 * Mathematical vector.
 */
class Vector
{
	public:
		Vector() {}
		Vector( int size ) : m_data(size) {}
		Vector( const Vector & other ) : m_data( other.m_data ) {}
		
		int size() const { return m_data.size(); }
		void resize( int s ) { if ( size() != s ) m_data.resize( s ); }
		double *data() { return m_data.data(); }
		const double *data() const { return m_data.data(); }
		Vector operator * ( double x ) const;
		Vector & operator *= ( double x );
		Vector operator + ( const Vector & other ) const;
		Vector & operator += ( const Vector & other );
		Vector operator - ( const Vector & other ) const;
		Vector & operator -= ( const Vector & other );
		Vector & operator = ( const Vector & other );
		Vector & operator = ( const QVector<Value> & other );
		bool operator==( const Vector & other ) const { return m_data == other.m_data; }
		bool operator!=( const Vector & other ) const { return m_data != other.m_data; } 
		double & operator[] ( int i ) { return m_data[i]; }
		double operator[] ( int i ) const { return m_data[i]; }
		/**
		 * Optimization for use in solving differential equations. Sets the
		 * contents of this vector to a+k*b.
		 */
		void combine( const Vector & a, double k, const Vector & b );
		/**
		 * Another optimization for use in solving differential equaions.
		 */
		void addRK4( double dx, const Vector & k1, const Vector & k2, const Vector & k3, const Vector & k4 );
		
	protected:
		QVector<double> m_data;
};


inline Vector operator *( double x, const Vector & v )
{
	return v * x;
}

#endif // VECTOR_H