view 2dvector.h @ 3:43df75088d85

fixed sticking scroll more file fiddling
author Robert Tubb <rt300@eecs.qmul.ac.uk>
date Mon, 03 Dec 2012 18:29:07 +0000
parents 307e5fb699fb
children 7541aeaebcdc
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 << "(" << 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 >> l_paren;
    if(l_paren != '('){
        cout << "BAD INPUT";
        return istr;
    }
    istr >> tvec.x;
    if(comma != ','){
        cout << "BAD INPUTa";
        return istr;
    }
    istr >> tvec.y;
    if(r_paren != ')'){
        cout << "BAD INPUT";
        return istr;
    }
    return istr;
}
#endif // #ifndef _2DVECTORH