1 #ifndef GINTENLIB_PLANE_INCLUDED_RECT_HPP_
2 #define GINTENLIB_PLANE_INCLUDED_RECT_HPP_
6 <gintenlib/plane/rect.hpp>
8 rect ¡§ Æ󼡸µ¶õ´Ö¾å¤Î¶ë·Á
12 template<typename Real>
15 typedef Real real_type;
16 typedef basic_point<Real> pos_type;
17 typedef basic_vector<Real> vec_type;
19 real_type x1, y1, x2, y2;
22 basic_rect( real_type x1_, real_type y1_, real_type x2_, real_type y2_ );
25 basic_rect( const basic_rect<T>& src );
28 // ĺÅÀ¤ÎºÂɸ¤òÊÖ¤·¤Þ¤¹¡£
29 pos_type operator[]( std::size_t index ) const;
31 pos_type at( std::size_t index ) const;
32 static std::size_t size()
38 // ¤³¤Î¶ë·Á¼«¿È¤ò¥·¥Õ¥È¤µ¤»¤Þ¤¹¡£
39 basic_rect& shift( const vec_type& d );
40 // friend ÈǤϥ³¥Ô¡¼¤·¤Æ¤«¤é¥·¥Õ¥È¤·¤Þ¤¹¡£
41 friend basic_rect shift( const basic_rect& target, const vec_type& d );
44 // ¤³¤Î¶ë·Á¼«¿È¤ò²óž¤µ¤»¤¿¤¤¤¬¡¢¤½¤¦¤¹¤ë¤È¶ë·Á¤Ç¤Ê¤¯¤Ê¤Ã¤Æ¤·¤Þ¤¦¤Î¤Ç¡¢
45 // ¤ä¤à¤Ê¤¯»Í³Ñ·Á¤È¤·¤Æ¥³¥Ô¡¼¤·¤Æ¤«¤é²óž¤µ¤»¤Þ¤¹¡£
46 // Angle ÈǤϳÑÅÙ¤«¤é¥µ¥¤¥ó¥³¥µ¥¤¥ó¤òµá¤á¤Æ²óž¡¢
47 // s, c ÈǤϥµ¥¤¥ó¥³¥µ¥¤¥óÃͤ«¤éľÀܲ󞤵¤»¤Þ¤¹¡£
48 template<typename Angle>
49 basic_quadrangle<Real> rotate( const Angle& theta ) const;
50 basic_quadrangle<Real> rotate( real_type s, real_type c ) const;
51 template<typename Angle>
52 friend basic_quadrangle<Real> rotate( const basic_rect& x, const Angle& theta );
53 basic_quadrangle<Real> rotate( const basic_rect& x, real_type s, real_type c );
56 typedef basic_rect<double> rect;
59 Æ󼡸µ¶õ´Ö¾å¤Î¡¢°ÌÃ֤γÎÄꤷ¤¿¶ë·Á¤òɽ¤¹¥¯¥é¥¹¡£
60 ²óž¤µ¤»¤ë¤È»Í³Ñ·Á¤ËÊѲ½¤¹¤ë°Ê³°¤ÏÉáÄ̤«¤È¡£
71 #include "quadrangle.hpp"
78 template<typename Real>
81 typedef Real real_type;
82 typedef basic_point<Real> pos_type;
83 typedef basic_vector<Real> vec_type;
85 real_type x1, y1, x2, y2;
88 : x1(), y1(), x2(), y2() {}
90 basic_rect( real_type x1_, real_type y1_, real_type x2_, real_type y2_ )
91 : x1(x1_), y1(y1_), x2(x2_), y2(y2_) {}
94 basic_rect( const basic_rect<T>& src )
95 : x1(src.x1), y1(src.y1), x2(src.x2), y2(src.y2) {}
98 pos_type operator[]( std::size_t index ) const
105 return pos_type( x1, y1 );
108 return pos_type( x2, y1 );
111 return pos_type( x2, y2 );
114 return pos_type( x1, y2 );
117 assert( !"should not get here." );
121 pos_type at( std::size_t index ) const
125 throw std::out_of_range();
128 return operator[](index);
130 static std::size_t size()
136 basic_rect& shift( const vec_type& d )
145 friend basic_rect shift( const basic_rect& target, const vec_type& d )
147 basic_rect temp = target;
148 return temp.shift(d);
152 template<typename Angle>
153 basic_quadrangle<Real> rotate( const Angle& theta ) const
155 using std::sin; using std::cos;
156 return rotate( sin(theta), cos(theta) );
158 basic_quadrangle<Real> rotate( real_type s, real_type c ) const
160 pos_type center( (x1 + x2) / 2, (y1 + y2) / 2 );
161 real_type w = (x2 - x1) / 2, h = (x2 - x1) / 2;
162 real_type sw = s * w, sh = s * h, cw = c * w, ch = c * h;
164 vec_type p1( -cw - sh, -ch + sw ), p2( cw - sh, -ch - sw );
166 return basic_quadrangle<Real>( center, p1, p2, -p1, -p2 );
168 template<typename Angle>
169 friend basic_quadrangle<Real> rotate( const basic_rect& x, const Angle& theta )
171 return x.rotate(theta);
173 basic_quadrangle<Real> rotate( const basic_rect& x, real_type s, real_type c )
175 return x.rotate( s, c );
179 typedef basic_rect<double> rect;
182 } // namespace gintenlib
184 #endif // #ifndef GINTENLIB_PLANE_INCLUDED_RECT_HPP_