RectT<T> RectT<T>::transformed( const Mat3T& matrix ) const { Vec2T center = Vec2T( x1 + x2, y1 + y2 ) / (T) 2; Vec2T extents = glm::abs( Vec2T( x2, y2 ) - center ); Vec3T x = matrix * Vec3T( extents.x, 0, 0 ); Vec3T y = matrix * Vec3T( 0, extents.y, 0 ); extents = Vec2T( glm::abs( x ) + glm::abs( y ) ); center = Vec2T( matrix * Vec3T( center, 1 ) ); return RectT<T>( center.x - extents.x, center.y - extents.y, center.x + extents.x, center.y + extents.y ); }
RectT<T> RectT<T>::transformCopy( const MatrixAffine2<T> &matrix ) const { RectT<T> result; result.x1 = numeric_limits<T>::max(); result.x2 = -numeric_limits<T>::max(); result.y1 = numeric_limits<T>::max(); result.y2 = -numeric_limits<T>::max(); result.include( matrix.transformPoint( Vec2T( x1, y1 ) ) ); result.include( matrix.transformPoint( Vec2T( x2, y1 ) ) ); result.include( matrix.transformPoint( Vec2T( x2, y2 ) ) ); result.include( matrix.transformPoint( Vec2T( x1, y2 ) ) ); return result; }
void RectT<T>::transform( const Mat3T &matrix ) { Vec2T center = Vec2T( x1 + x2, y1 + y2 ) / (T) 2; Vec2T extents = glm::abs( Vec2T( x2, y2 ) - center ); Vec3T x = matrix * Vec3T( extents.x, 0, 0 ); Vec3T y = matrix * Vec3T( 0, extents.y, 0 ); extents = Vec2T( glm::abs( x ) + glm::abs( y ) ); center = Vec2T( matrix * Vec3T( center, 1 ) ); x1 = center.x - extents.x; y1 = center.y - extents.y; x2 = center.x + extents.x; y2 = center.y + extents.y; }
void RectT<T>::include( const RectT<T> &rect ) { include( Vec2T( rect.x1, rect.y1 ) ); include( Vec2T( rect.x2, rect.y2 ) ); }