| 214 | } |
| 215 | |
| 216 | bool segmentIntersectionOrder( const std::array<PreciseVertCoords, 8> & vs ) |
| 217 | { |
| 218 | // s=01, ta=234, tb=567 |
| 219 | auto as = { vs[2], vs[3], vs[4] }; |
| 220 | auto bs = { vs[5], vs[6], vs[7] }; |
| 221 | |
| 222 | assert( doTriangleSegmentIntersect( { vs[2], vs[3], vs[4], vs[0], vs[1] } ) ); |
| 223 | assert( doTriangleSegmentIntersect( { vs[5], vs[6], vs[7], vs[0], vs[1] } ) ); |
| 224 | |
| 225 | // check for shared points in ta and tb |
| 226 | PreciseVertCoords firstSharedPoint; |
| 227 | for ( auto va : as ) |
| 228 | for ( auto vb : bs ) |
| 229 | if ( va.id == vb.id ) |
| 230 | { |
| 231 | assert( va.pt == vb.pt ); |
| 232 | firstSharedPoint = va; |
| 233 | goto exitLoop1; |
| 234 | } |
| 235 | exitLoop1: |
| 236 | |
| 237 | if ( firstSharedPoint.id ) |
| 238 | { |
| 239 | PreciseVertCoords secondSharedPoint; |
| 240 | for ( auto va : as ) |
| 241 | for ( auto vb : bs ) |
| 242 | if ( va.id == vb.id && va.id != firstSharedPoint.id ) |
| 243 | { |
| 244 | assert( va.pt == vb.pt ); |
| 245 | secondSharedPoint = va; |
| 246 | goto exitLoop2; |
| 247 | } |
| 248 | exitLoop2: |
| 249 | |
| 250 | if ( secondSharedPoint.id ) |
| 251 | { |
| 252 | PreciseVertCoords thirdPointB; |
| 253 | for ( auto vb : bs ) |
| 254 | if ( vb.id != firstSharedPoint.id && vb.id != secondSharedPoint.id ) |
| 255 | { |
| 256 | thirdPointB = vb; |
| 257 | break; |
| 258 | } |
| 259 | assert( thirdPointB.id ); |
| 260 | assert( thirdPointB.id != vs[2].id && thirdPointB.id != vs[3].id && thirdPointB.id != vs[4].id ); // the case when both triangles share all 3 points is not valid |
| 261 | return orient3d( { vs[2], vs[3], vs[4], thirdPointB } ) |
| 262 | == orient3d( { vs[2], vs[3], vs[4], vs[1] } ); |
| 263 | } |
| 264 | |
| 265 | // only one shared point in ta and tb |
| 266 | |
| 267 | PreciseVertCoords secondPointA, thirdPointA; |
| 268 | for ( auto va : as ) |
| 269 | if ( va.id != firstSharedPoint.id ) |
| 270 | { |
| 271 | if ( !secondPointA.id ) |
| 272 | secondPointA = va; |
| 273 | else |