| 198 | } |
| 199 | |
| 200 | void insertRoundCorner( Contour2f& cont, const CornerParameters& params, float minAnglePrecision, int* shiftMap ) |
| 201 | { |
| 202 | int numSteps = int( std::floor( std::abs( params.lrAng ) / minAnglePrecision ) ); |
| 203 | if ( numSteps == 0 ) |
| 204 | return; |
| 205 | |
| 206 | auto lVec = params.lc - params.lp; |
| 207 | auto rVec = params.rc - params.rn; |
| 208 | bool round = std::abs( dot( params.lc - params.org, lVec ) / ( params.lc - params.org ).lengthSq() ) < std::numeric_limits<float>::epsilon() * 10.0f; |
| 209 | round = round && std::abs( dot( params.rc - params.org, rVec ) / ( params.rc - params.org ).lengthSq() ) < std::numeric_limits<float>::epsilon() * 10.0f; |
| 210 | |
| 211 | if ( !round ) |
| 212 | { |
| 213 | auto offset = ( params.org - params.lc ).length(); |
| 214 | auto width = std::abs( params.lrAng ) / PI_F * 1.5f; |
| 215 | |
| 216 | auto ln = params.lc + lVec.normalized() * width * offset; |
| 217 | auto rp = params.rc + rVec.normalized() * width * offset; |
| 218 | |
| 219 | for ( int s = 0; s < numSteps; ++s ) |
| 220 | { |
| 221 | float t = float( s + 1 ) / float( numSteps + 1 ); |
| 222 | auto invt = ( 1 - t ); |
| 223 | auto tSq = t * t; |
| 224 | auto invtSq = invt * invt; |
| 225 | auto tCb = tSq * t; |
| 226 | auto invtCb = invtSq * invt; |
| 227 | const auto& p1 = params.lc; |
| 228 | const auto& p2 = ln; |
| 229 | const auto& p3 = rp; |
| 230 | const auto& p4 = params.rc; |
| 231 | cont.emplace_back( p1 * invtCb + 3.0f * p2 * invtSq * t + 3.0f * p3 * invt * tSq + p4 * tCb ); |
| 232 | if ( shiftMap ) |
| 233 | ++( *shiftMap ); |
| 234 | } |
| 235 | } |
| 236 | else |
| 237 | { |
| 238 | for ( int s = 0; s < numSteps; ++s ) |
| 239 | { |
| 240 | float stepAng = ( params.lrAng / ( numSteps + 1 ) ) * ( s + 1 ); |
| 241 | auto rotXf = AffineXf2f::xfAround( Matrix2f::rotation( stepAng ), params.org ); |
| 242 | cont.emplace_back( rotXf( params.lc ) ); |
| 243 | if ( shiftMap ) |
| 244 | ++( *shiftMap ); |
| 245 | } |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | void insertSharpCorner( Contour2f& cont, const CornerParameters& params, float maxSharpAngle, int* shiftMap ) |
| 250 | { |