| 288 | } |
| 289 | |
| 290 | bool segmentIntersectionOrder( const std::array<PreciseVertCoords2, 6> & vs ) |
| 291 | { |
| 292 | // s=01, sa=23, sb=45 |
| 293 | assert( doSegmentSegmentIntersect( { vs[0], vs[1], vs[2], vs[3] } ) ); |
| 294 | assert( doSegmentSegmentIntersect( { vs[0], vs[1], vs[4], vs[5] } ) ); |
| 295 | |
| 296 | // if sa and sb have a shared point |
| 297 | PreciseVertCoords2 sharedPoint; |
| 298 | for ( auto va : { vs[2], vs[3] } ) |
| 299 | for ( auto vb : { vs[4], vs[5] } ) |
| 300 | if ( va.id == vb.id ) |
| 301 | { |
| 302 | assert( va.pt == vb.pt ); |
| 303 | sharedPoint = va; |
| 304 | goto exitLoop; |
| 305 | } |
| 306 | exitLoop: |
| 307 | |
| 308 | if ( sharedPoint.id ) |
| 309 | { |
| 310 | // segments sa and sb have one shared point |
| 311 | auto secondPointB = ( sharedPoint.id == vs[4].id ) ? vs[5] : vs[4]; |
| 312 | assert( secondPointB.id != vs[2].id && secondPointB.id != vs[3].id ); // the case when both segments share all 2 points is not valid |
| 313 | return ccw( { vs[2], vs[3], secondPointB } ) == ccw( { vs[2], vs[3], vs[1] } ); |
| 314 | } |
| 315 | else |
| 316 | { |
| 317 | // segments sa and sb have no shared points |
| 318 | const bool a1 = ccw( { vs[4], vs[5], vs[2] } ); |
| 319 | if ( a1 == ccw( { vs[4], vs[5], vs[3] } ) ) |
| 320 | { |
| 321 | // all a-points are on one side of sb |
| 322 | return a1 == ccw( { vs[4], vs[5], vs[0] } ); |
| 323 | } |
| 324 | |
| 325 | const bool b1 = ccw( { vs[2], vs[3], vs[4] } ); |
| 326 | if ( b1 == ccw( { vs[2], vs[3], vs[5] } ) ) |
| 327 | { |
| 328 | // all b-points are on one side of sa |
| 329 | return b1 == ccw( { vs[2], vs[3], vs[1] } ); |
| 330 | } |
| 331 | |
| 332 | // segments sa and sb intersect one another, process it as general case |
| 333 | } |
| 334 | |
| 335 | // res = ( ccw(sa,s[0])*ccw(sb,s[1]) - ccw(sb,s[0])*ccw(sa,s[1]) ) / |
| 336 | // ( ccw(sa,s[0])-ccw(sa,s[1]) ) * ( ccw(sb,s[0])-ccw(sb,s[1]) ) |
| 337 | const auto areaSaOrg = area( vs[2].pt, vs[3].pt, vs[0].pt ); |
| 338 | const auto areaSaDest = area( vs[2].pt, vs[3].pt, vs[1].pt ); |
| 339 | assert( ( areaSaOrg <= 0 && areaSaDest >= 0 ) || ( areaSaOrg >= 0 && areaSaDest <= 0 ) ); |
| 340 | |
| 341 | const auto areaSbOrg = area( vs[4].pt, vs[5].pt, vs[0].pt ); |
| 342 | const auto areaSbDest = area( vs[4].pt, vs[5].pt, vs[1].pt ); |
| 343 | assert( ( areaSbOrg <= 0 && areaSbDest >= 0 ) || ( areaSbOrg >= 0 && areaSbDest <= 0 ) ); |
| 344 | |
| 345 | const auto nomSimple = FastInt128( areaSaOrg ) * FastInt128( areaSbDest ) - FastInt128( areaSbOrg ) * FastInt128( areaSaDest ); |
| 346 | if ( nomSimple != 0 ) |
| 347 | { |
nothing calls this directly
no test coverage detected