annotate 2dvector.h @ 52:89944ab3e129 tip

fix oF linker errors ios8
author Robert Tubb <rt300@eecs.qmul.ac.uk>
date Tue, 03 Feb 2015 13:18:23 +0000
parents a223551fdc1f
children
rev   line source
rt300@0 1 /*
rt300@0 2 * 2dvector.h
rt300@0 3 * simplespring
rt300@0 4 *
rt300@0 5 * Created by Robert Tubb on 01/06/2011.
rt300@0 6 * Copyright 2011 __MyCompanyName__. All rights reserved.
rt300@0 7 *
rt300@0 8 */
rt300@0 9 #ifndef _2DVECTORH
rt300@0 10 #define _2DVECTORH
rt300@0 11 #include <iostream>
rt300@0 12
rt300@0 13 class TwoVector{
rt300@0 14 public:
rt300@0 15 double x, y;
rt300@0 16 TwoVector();
rt300@0 17 TwoVector(double ax, double ay);
rt300@0 18
rt300@0 19 // public methods
rt300@0 20 double norm();
rt300@0 21 void setCoord(double ax, double ay);
rt300@0 22 TwoVector minus(TwoVector otherPoint);
rt300@0 23 TwoVector operator-(TwoVector otherPoint);
rt300@0 24 TwoVector operator+(TwoVector otherPoint);
rt300@0 25
rt300@0 26 TwoVector operator*(TwoVector otherPoint);
rt300@0 27 TwoVector operator*(const double& scalar); // scalar is right operand
rt300@0 28
rt300@0 29 //TwoVector operator=(TwoVector otherPoint);
rt300@0 30
rt300@0 31 double distanceTo(TwoVector otherPoint);
rt300@0 32
rt300@0 33 };
rt300@0 34 using namespace std;
rt300@0 35 // output text formatting: (x,y) in super precise output
rt300@0 36 inline ostream& operator<<(ostream& ostr, const TwoVector& tvec){
rt300@0 37 ostr.setf(ios_base::fixed,ios_base::floatfield);
rt300@0 38 ostr.precision(1);
rt300@0 39
rt300@0 40 ostr << "(" << tvec.x << "," << tvec.y << ")";
rt300@0 41 return ostr;
rt300@0 42 }
rt300@0 43 inline istream& operator>>(istream& istr, TwoVector& tvec){
rt300@0 44 // um
rt300@0 45
rt300@0 46 char l_paren , comma, r_paren;
rt300@0 47
rt300@0 48
rt300@0 49 if(istr.bad()){
rt300@0 50 cout << "BAD INPUT";
rt300@0 51 return istr;
rt300@0 52 }
rt300@0 53
rt300@0 54 istr.setf(ios_base::fixed,ios_base::floatfield);
rt300@0 55 istr.precision(1);
rt300@0 56
rt300@0 57 istr >> l_paren >> tvec.x >> comma >> tvec.y >> r_paren;
rt300@0 58 if(l_paren != '('){
rt300@0 59 cout << "BAD INPUT (";
rt300@0 60 return istr;
rt300@0 61 }
rt300@0 62
rt300@0 63 if(comma != ','){
rt300@0 64 cout << "BAD INPUT ,";
rt300@0 65 return istr;
rt300@0 66 }
rt300@0 67
rt300@0 68 if(r_paren != ')'){
rt300@0 69 cout << "BAD INPUT )";
rt300@0 70 return istr;
rt300@0 71 }
rt300@0 72 return istr;
rt300@0 73 }
rt300@0 74 #endif // #ifndef _2DVECTORH