| 129 | } |
| 130 | |
| 131 | bool CircleIntersectsWithSquare( |
| 132 | const m_Vec2& cirecle_center, |
| 133 | float circle_radius, |
| 134 | unsigned int square_x, unsigned int square_y ) |
| 135 | { |
| 136 | const float c_square_inner_radius= 0.5f; |
| 137 | const float c_square_outer_radius= 0.5f * std::sqrt( 2.0f ); |
| 138 | |
| 139 | const m_Vec2 square_start{ float(square_x), float(square_y) }; |
| 140 | const m_Vec2 square_center= square_start + m_Vec2( 0.5f, 0.5f ); |
| 141 | |
| 142 | const m_Vec2 vec_from_square_center_to_circle_center= cirecle_center - square_center; |
| 143 | const float square_distance_to_circle= vec_from_square_center_to_circle_center.SquareLength(); |
| 144 | |
| 145 | const float reject_distance= c_square_outer_radius + circle_radius; |
| 146 | if( square_distance_to_circle > reject_distance * reject_distance ) |
| 147 | return false; |
| 148 | |
| 149 | const float accept_distance= c_square_inner_radius + circle_radius; |
| 150 | if( square_distance_to_circle < accept_distance * accept_distance ) |
| 151 | return true; |
| 152 | |
| 153 | m_Vec2 tmp; |
| 154 | if( CollideCircleWithLineSegment( |
| 155 | square_start, square_start + m_Vec2( 1.0f, 0.0f ), |
| 156 | cirecle_center, circle_radius, |
| 157 | tmp ) ) |
| 158 | return true; |
| 159 | |
| 160 | if( CollideCircleWithLineSegment( |
| 161 | square_start + m_Vec2( 1.0f, 0.0f ), square_start + m_Vec2( 1.0f, 1.0f ), |
| 162 | cirecle_center, circle_radius, |
| 163 | tmp ) ) |
| 164 | return true; |
| 165 | |
| 166 | if( CollideCircleWithLineSegment( |
| 167 | square_start + m_Vec2( 1.0f, 1.0f ), square_start + m_Vec2( 0.0f, 1.0f ), |
| 168 | cirecle_center, circle_radius, |
| 169 | tmp ) ) |
| 170 | return true; |
| 171 | |
| 172 | if( CollideCircleWithLineSegment( |
| 173 | square_start + m_Vec2( 0.0f, 1.0f ), square_start, |
| 174 | cirecle_center, circle_radius, |
| 175 | tmp ) ) |
| 176 | return true; |
| 177 | |
| 178 | return false; |
| 179 | } |
| 180 | |
| 181 | bool RayIntersectWall( |
| 182 | const m_Vec2& v0, const m_Vec2& v1, |
no test coverage detected