// This may look like C code, but it is really -*- C++ -*- // Point3Df.h // (C) 2002 Bill Lenhart #ifndef POINT3DF_H #define POINT3DF_H #include //////////////////// // class Point3Df // //////////////////// class Point3Df { public: // Default constructor: Initializes point to (0,0,0) Point3Df(); // Initializes point to (x,y,z) Point3Df(float xval, float yval, float zval); // Copy Constructor Point3Df(const Point3Df& other); // Copies other to this Point3Df& operator=(const Point3Df& other); // Destructor: Does nothing ~Point3Df(); // coordinates of point float x; float y; float z; // coordinate-wise addition/subtraction/multiplication of self with other // modifies (and returns) self Point3Df& operator+=(const Point3Df& other); Point3Df& operator-=(const Point3Df& other); Point3Df& operator*=(const Point3Df& other); // add, subtract, multiply, every element by scalar // modifies (and returns) self Point3Df& operator+=(const float scalar); Point3Df& operator-=(const float scalar); Point3Df& operator*=(const float scalar); // Point3Df component-wise addition, subtraction and multiplication Point3Df operator+(const Point3Df& other) const; Point3Df operator-(const Point3Df& other) const; Point3Df operator*(const Point3Df& other) const; // dot product float dot(const Point3Df& other) const; // magnitude of vector float Point3Df::norm(void) const; // scale point to unit length Point3Df& Point3Df::normalize(void); // operators for addition, subtraction, multiplication by scalar // Note: always put point on the left Point3Df operator*(const float x) const; Point3Df operator+(const float x) const; Point3Df operator-(const float x) const; // read point from stream istream& in(istream& is); // append point to end of stream ostream& out(ostream&) const; }; // friends // read a point: a binary operator istream& operator>>(istream& is, Point3Df& p); // print a point: a binary operator ostream& operator<<(ostream& o, const Point3Df& p); #endif POINT3DF_H