| 10 | #include "BoundingFrustum.h" |
| 11 | |
| 12 | void CollisionsHelper::ClosestPointPointLine(const Float2& point, const Float2& p0, const Float2& p1, Float2& result) |
| 13 | { |
| 14 | const Float2 p = point - p0; |
| 15 | Float2 n = p1 - p0; |
| 16 | |
| 17 | const float length = n.Length(); |
| 18 | if (length < 1e-10f) |
| 19 | { |
| 20 | // Both points are the same, just give any |
| 21 | result = p0; |
| 22 | return; |
| 23 | } |
| 24 | n /= length; |
| 25 | |
| 26 | const float dot = Float2::Dot(n, p); |
| 27 | if (dot <= 0.0f) |
| 28 | { |
| 29 | // Before first point |
| 30 | result = p0; |
| 31 | } |
| 32 | else if (dot >= length) |
| 33 | { |
| 34 | // After first point |
| 35 | result = p1; |
| 36 | } |
| 37 | else |
| 38 | { |
| 39 | // Inside |
| 40 | result = p0 + n * dot; |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | Float2 CollisionsHelper::ClosestPointPointLine(const Float2& point, const Float2& p0, const Float2& p1) |
| 45 | { |
no test coverage detected