Sutherland-Hodgman clipping.
(vOut []B2ClipVertex, vIn []B2ClipVertex, normal B2Vec2, offset float64, vertexIndexA int)
| 442 | |
| 443 | // Sutherland-Hodgman clipping. |
| 444 | func B2ClipSegmentToLine(vOut []B2ClipVertex, vIn []B2ClipVertex, normal B2Vec2, offset float64, vertexIndexA int) int { |
| 445 | |
| 446 | // Start with no output points |
| 447 | numOut := 0 |
| 448 | |
| 449 | // Calculate the distance of end points to the line |
| 450 | distance0 := B2Vec2Dot(normal, vIn[0].V) - offset |
| 451 | distance1 := B2Vec2Dot(normal, vIn[1].V) - offset |
| 452 | |
| 453 | // If the points are behind the plane |
| 454 | if distance0 <= 0.0 { |
| 455 | vOut[numOut] = vIn[0] |
| 456 | numOut++ |
| 457 | } |
| 458 | |
| 459 | if distance1 <= 0.0 { |
| 460 | vOut[numOut] = vIn[1] |
| 461 | numOut++ |
| 462 | } |
| 463 | |
| 464 | // If the points are on different sides of the plane |
| 465 | if distance0*distance1 < 0.0 { |
| 466 | // Find intersection point of edge and plane |
| 467 | interp := distance0 / (distance0 - distance1) |
| 468 | vOut[numOut].V = B2Vec2Add( |
| 469 | vIn[0].V, |
| 470 | B2Vec2MulScalar(interp, B2Vec2Sub(vIn[1].V, vIn[0].V)), |
| 471 | ) |
| 472 | |
| 473 | // VertexA is hitting edgeB. |
| 474 | vOut[numOut].Id.IndexA = uint8(vertexIndexA) |
| 475 | vOut[numOut].Id.IndexB = vIn[0].Id.IndexB |
| 476 | vOut[numOut].Id.TypeA = B2ContactFeature_Type.E_vertex |
| 477 | vOut[numOut].Id.TypeB = B2ContactFeature_Type.E_face |
| 478 | numOut++ |
| 479 | } |
| 480 | |
| 481 | return numOut |
| 482 | } |
| 483 | |
| 484 | func B2TestOverlapShapes(shapeA B2ShapeInterface, indexA int, shapeB B2ShapeInterface, indexB int, xfA B2Transform, xfB B2Transform) bool { |
| 485 | input := MakeB2DistanceInput() |
no test coverage detected