point.h

Go to the documentation of this file.
00001 /*
00002   libwt - Vassilis Virvilis Toolkit - a widget library
00003   Copyright (C) 2006 Vassilis Virvilis <vasvir2@fastmail.fm>
00004  
00005   This library is free software; you can redistribute it and/or
00006   modify it under the terms of the GNU Lesser General Public
00007   License as published by the Free Software Foundation; either
00008   version 2.1 of the License, or (at your option) any later version.
00009   
00010   This library is distributed in the hope that it will be useful,
00011   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013   Lesser General Public License for more details.
00014   
00015   You should have received a copy of the GNU Lesser General Public
00016   License along with this library; if not, write to the
00017   Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00018   Boston, MA  02111-1307, SA.
00019 */
00020 
00021 #ifndef WT_POINT_H
00022 #define WT_POINT_H
00023 
00024 #include <iosfwd>
00025 #include <vector>
00026 
00027 namespace Wt {
00028 
00029 /// Class to handle x,y - points on the screen
00030 class Point {
00031 public:
00032     /// Construct a point at (0, 0)
00033     Point() : x_(0), y_(0) {}
00034 
00035     /// Construct a point
00036     Point(int x_, int y_) : x_(x_), y_(y_) {}
00037 
00038     int x() const {
00039         return x_;
00040     }
00041 
00042     int y() const {
00043         return y_;
00044     }
00045 
00046     void setX(int x_new) {
00047         x_ = x_new;
00048     }
00049 
00050     void setY(int y_new) {
00051         y_ = y_new;
00052     }
00053 
00054     /// Shift a point
00055     Point& operator+=(const Point& other) {
00056         x_ += other.x_;
00057         y_ += other.y_;
00058         return *this;
00059     }
00060 
00061     /// Shift a point
00062     Point& operator-=(const Point& other) {
00063         x_ -= other.x_;
00064         y_ -= other.y_;
00065         return *this;
00066     }
00067 
00068     /// Return a shifted point
00069     Point operator+(const Point& other) const {
00070         return Point(x_ + other.x_, y_ + other.y_);
00071     }
00072 
00073     /// Return a shifted point
00074     Point operator-(const Point& other) const {
00075         return Point(x_ - other.x_, y_ - other.y_);
00076     }
00077 
00078     /// return the negative of a point
00079     Point operator-() const {
00080         return Point(-x_, -y_);
00081     }
00082 
00083     /// Compare two points
00084     bool operator==(const Point &other) const {
00085         return (x_ == other.x_) && (y_ == other.y_);
00086     }
00087 
00088     /// Compare two points
00089     bool operator!=(const Point &other) const {
00090         return !(*this == other);
00091     }
00092 
00093 private:
00094     /// The point's x coordinate
00095     int x_;
00096     /// The point's y coordinate
00097     int y_;
00098 };
00099 
00100 /// Print a point to a stream
00101 std::ostream& operator<<(std::ostream& s, const Point& p);
00102 
00103 typedef std::vector<Point> PointArray;
00104 
00105 } // namespace Wt
00106 
00107 #endif // WT_POINT_H

Generated Fri Jul 28 19:23:00 2006.
Copyright © 1998-2003 by the respective authors.

This document is licensed under the terms of the GNU Free Documentation License and may be freely distributed under the conditions given by this license.