1 #ifndef GINTENLIB_PLANE_INCLUDED_VECTOR_HPP_
2 #define GINTENLIB_PLANE_INCLUDED_VECTOR_HPP_
6 <gintenlib/plane/vector.hpp>
8 vector ¡§ Æ󼡸µ¥Ù¥¯¥È¥ë
11 template< typename Real >
13 : private boost::equality_comparable< basic_vector<Real> >,
14 private boost::additive< basic_vector<Real> >,
15 private boost::multiplicative< basic_vector<Real>, Real >
17 typedef Real real_type;
21 basic_vector( real_type x_, real_type y_ );
24 basic_vector( const basic_vector<T>& src );
27 basic_vector( const std::pair<T, T>& src );
30 // ¤½¤ì¤¾¤ì¸«¤¿¤Þ¤ó¤Þ¤Ç¤¹¡£operator+ ¤È¤«¤Ï boost:: operators ¤Ë¤è¤Ã¤Æ³Æ¼ï¼«Æ°ÄêµÁ¤µ¤ì¤Þ¤¹¡£
31 basic_vector& operator+=( const basic_vector& rhs );
32 basic_vector& operator-=( const basic_vector& rhs );
33 basic_vector operator-() const;
34 basic_vector& operator*=( real_type rhs );
35 basic_vector& operator/=( real_type rhs );
36 bool operator==( const basic_vector& rhs ) const;
39 real_type norm() const;
40 friend real_type norm( const basic_vector& target );
43 real_type absolute() const;
44 friend real_type absolute( const basic_vector& target );
47 // Àµµ¬²½¤·¤¿·ë²Ì¤òÊÖ¤¹¤Î¤Ç¤Ï¤Ê¤¯¡¢¤³¤Î¥Ù¥¯¥È¥ë¼«ÂΤòÀµµ¬²½¤·¤Þ¤¹¡£
48 basic_vector& normalize();
49 // friend ÈǤϥ³¥Ô¡¼¤·¤Æ¤«¤éÀµµ¬²½¤·¤Þ¤¹¡£
50 friend basic_vector normalized( const basic_vector& x );
53 real_type argument() const;
54 friend real_type argument( const basic_vector& x );
57 real_type dot( const basic_vector& rhs ) const;
58 friend real_type dot( const basic_vector& lhs, const basic_vector& rhs );
59 friend real_type operator*( const basic_vector& lhs, const basic_vector& rhs );
61 // ¥í¡¼¥Æ¡¼¥È¡£²óž¤µ¤»¤¿·ë²Ì¤òÊÖ¤¹¤Î¤Ç¤Ï¤Ê¤¯¡¢¤³¤Î¥Ù¥¯¥È¥ë¼«ÂΤò²ó¤·¤Þ¤¹¡£
62 // ³ÑÅÙ»ØÄê¥Ð¡¼¥¸¥ç¥ó¡£¥Æ¥ó¥×¥ì¡¼¥È¤Ê¤Î¤Ï¡¢gintenlib::plane::angle ¤âÅϤ»¤ë¤è¤¦¤Ë¡¢¤Ç¤¹¡£
63 template< typename Angle >
64 basic_vector& rotate( const Angle& angle );
65 // ¥µ¥¤¥ó¤È¥³¥µ¥¤¥ó¤ò»ØÄꤷ¤¿¥Ð¡¼¥¸¥ç¥ó¡£¹â®¤Ç¤¹¡£
66 basic_vector& rotate( real_type s, real_type c );
68 // ¾åÆó¤Ä¤Î friend ÈÇ¡£¥³¥Ô¡¼¤·¤Æ¤«¤é²ó¤·¤Þ¤¹¡£
69 template< typename Angle >
70 friend basic_vector rotate( const basic_vector& target, const Angle& angle );
71 friend basic_vector rotate( const basic_vector& target, real_type s, real_type c );
73 typedef basic_vector<double> vector;
76 Æ󼡸µ¤ÎÁêÂÐ¥Ù¥¯¥È¥ë¤òɽ¤¹¥¯¥é¥¹¡£
77 ÀäÂÐÃÍ·×»»¡¢Êгѷ׻»¡¢Àµµ¬²½¡¢²óž¤Ê¤É¡¢¤È¤ê¤¢¤¨¤º°ìÄ̤êɬÍפ½¤¦¤Ê¤â¤Î¤Ï·¤¨¤Æ¤¤¤Þ¤¹¡£
85 #include <boost/operators.hpp>
91 template< typename Real >
93 : private boost::equality_comparable< basic_vector<Real> >,
94 private boost::additive< basic_vector<Real> >,
95 private boost::multiplicative< basic_vector<Real>, Real >
97 typedef Real real_type;
103 basic_vector( real_type x_, real_type y_ )
107 basic_vector( const basic_vector<T>& src )
108 : x(src.x), y(src.y) {}
111 basic_vector( const std::pair<T, T>& src )
112 : x(src.first), y(src.second) {}
115 basic_vector& operator+=( const basic_vector& rhs )
122 basic_vector& operator-=( const basic_vector& rhs )
129 basic_vector operator-() const
131 return basic_vector( -x, -y );
133 basic_vector& operator*=( real_type rhs )
140 basic_vector& operator/=( real_type rhs )
147 bool operator==( const basic_vector& rhs ) const
149 return ( x == rhs.x ) && ( y == rhs.y );
153 real_type norm() const
155 return x * x + y * y;
157 friend real_type norm( const basic_vector& target )
159 return target.norm();
163 real_type absolute() const
165 return std::sqrt( x * x + y * y );
167 friend real_type absolute( const basic_vector& target )
169 return target.absolute();
173 basic_vector& normalize()
175 real_type r = absolute();
190 friend basic_vector normalized( const basic_vector& x )
192 basic_vector temp = x;
198 real_type argument() const
200 if( x == 0 && y == 0 )
204 return std::atan2( y, x );
206 friend real_type argument( const basic_vector& x )
212 real_type dot( const basic_vector& rhs ) const
214 return x * rhs.x + y * rhs.y;
216 friend real_type dot( const basic_vector& lhs, const basic_vector& rhs )
220 friend real_type operator*( const basic_vector& lhs, const basic_vector& rhs )
226 template< typename Angle >
227 basic_vector& rotate( const Angle& angle )
229 using std::sin; using std::cos;
230 return rotate( sin(angle), cos(angle) );
232 basic_vector& rotate( real_type s, real_type c )
234 real_type sx = s*x, sy = s*y, cx = c*x, cy = c*y;
241 template< typename Angle >
242 friend basic_vector rotate( const basic_vector& target, const Angle& angle )
244 basic_vector temp = target;
245 temp.rotate( angle );
248 friend basic_vector rotate( const basic_vector& target, real_type s, real_type c )
250 basic_vector temp = target;
255 typedef basic_vector<double> vector;
258 } // namespace gintenlib
260 #endif // #ifndef GINTENLIB_PLANE_INCLUDED_VECTOR_HPP_