Mercurial > hg > soniczoomios
view 2dvector.h @ 49:178642d134a7 tip
xtra files
author | Robert Tubb <rt300@eecs.qmul.ac.uk> |
---|---|
date | Wed, 01 May 2013 17:34:33 +0100 |
parents | 7541aeaebcdc |
children |
line wrap: on
line source
/* * 2dvector.h * simplespring * * Created by Robert Tubb on 01/06/2011. * Copyright 2011 __MyCompanyName__. All rights reserved. * */ #ifndef _2DVECTORH #define _2DVECTORH #include <iostream> class TwoVector{ public: double x, y; TwoVector(); TwoVector(double ax, double ay); // public methods double norm(); void setCoord(double ax, double ay); TwoVector minus(TwoVector otherPoint); TwoVector operator-(TwoVector otherPoint); TwoVector operator+(TwoVector otherPoint); TwoVector operator*(TwoVector otherPoint); TwoVector operator*(const double& scalar); // scalar is right operand //TwoVector operator=(TwoVector otherPoint); double distanceTo(TwoVector otherPoint); }; using namespace std; // output text formatting: (x,y) in super precise output inline ostream& operator<<(ostream& ostr, const TwoVector& tvec){ ostr.setf(ios_base::fixed,ios_base::floatfield); ostr.precision(1); ostr << "(" << tvec.x << "," << tvec.y << ")"; return ostr; } inline istream& operator>>(istream& istr, TwoVector& tvec){ // um char l_paren , comma, r_paren; if(istr.bad()){ cout << "BAD INPUT"; return istr; } istr.setf(ios_base::fixed,ios_base::floatfield); istr.precision(1); istr >> l_paren >> tvec.x >> comma >> tvec.y >> r_paren; if(l_paren != '('){ cout << "BAD INPUT ("; return istr; } if(comma != ','){ cout << "BAD INPUT ,"; return istr; } if(r_paren != ')'){ cout << "BAD INPUT )"; return istr; } return istr; } #endif // #ifndef _2DVECTORH