00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00031 #ifndef __CLAW_RECTANGLE_HPP__
00032 #define __CLAW_RECTANGLE_HPP__
00033
00034 #include <claw/coordinate_2d.hpp>
00035 #include <claw/box_2d.hpp>
00036
00037 namespace claw
00038 {
00039 namespace math
00040 {
00050 template<class T>
00051 class rectangle
00052 {
00053 public:
00055 typedef T value_type;
00056
00058 typedef rectangle<value_type> self_type;
00059
00060 public:
00061 rectangle();
00062
00063 template<typename U>
00064 rectangle( const rectangle<U>& that );
00065
00066 template<typename U>
00067 rectangle( const box_2d<U>& that );
00068
00069 rectangle( const value_type& _x, const value_type& _y,
00070 const value_type& _width, const value_type& _height);
00071
00072 template<typename U>
00073 rectangle( const coordinate_2d<U>& pos, const value_type& _width,
00074 const value_type& _height );
00075
00076 template<typename U>
00077 rectangle( const coordinate_2d<U>& pos, const coordinate_2d<U>& size );
00078
00079 template<typename U>
00080 rectangle<U> cast_value_type_to() const;
00081
00082 value_type area() const;
00083 bool includes( const coordinate_2d<value_type>& p ) const;
00084 bool includes( const self_type& r ) const;
00085 bool intersects( const self_type& r ) const;
00086 self_type intersection( const self_type& r ) const;
00087
00088 void set( const value_type& new_x, const value_type& new_y,
00089 const value_type& new_width, const value_type& new_height );
00090
00091 value_type left() const;
00092 value_type right() const;
00093 value_type bottom() const;
00094 value_type top() const;
00095
00096 coordinate_2d<value_type> size() const;
00097
00098 private:
00099 void x_intersection( const self_type& r, self_type& result ) const;
00100 void y_intersection( const self_type& r, self_type& result ) const;
00101
00102 public:
00104 coordinate_2d<value_type> position;
00105
00107 value_type width;
00108
00110 value_type height;
00111
00112 };
00113 }
00114 }
00115
00116 #include <claw/impl/rectangle.tpp>
00117
00118 #endif // __CLAW_RECTANGLE_HPP__