| 1446 | } |
| 1447 | |
| 1448 | bool Tr2Sprite2dScene::IsInsideLineSegment( const Vector2& pointIn, const Vector2& start, const Vector2& end, float lineWidth ) |
| 1449 | { |
| 1450 | if( !IsInsideClipRect( pointIn ) ) |
| 1451 | { |
| 1452 | return false; |
| 1453 | } |
| 1454 | |
| 1455 | Vector2 startTransformed; |
| 1456 | Vector2 endTransformed; |
| 1457 | |
| 1458 | if( m_transformStack->empty() ) |
| 1459 | { |
| 1460 | startTransformed.x = start.x; |
| 1461 | startTransformed.y = start.y; |
| 1462 | endTransformed.x = end.x; |
| 1463 | endTransformed.y = end.y; |
| 1464 | } |
| 1465 | else |
| 1466 | { |
| 1467 | const TransformStackEntry& topEntry = m_transformStack->back(); |
| 1468 | |
| 1469 | if( topEntry.isTranslationOnly ) |
| 1470 | { |
| 1471 | startTransformed.x = start.x + topEntry.translation.x; |
| 1472 | startTransformed.y = start.y + topEntry.translation.y; |
| 1473 | endTransformed.x = end.x + topEntry.translation.x; |
| 1474 | endTransformed.y = end.y + topEntry.translation.y; |
| 1475 | } |
| 1476 | else |
| 1477 | { |
| 1478 | const Matrix& transform = topEntry.transform; |
| 1479 | |
| 1480 | TransformPoint( startTransformed, start, transform ); |
| 1481 | TransformPoint( endTransformed, end, transform ); |
| 1482 | } |
| 1483 | } |
| 1484 | |
| 1485 | // http://en.wikipedia.org/wiki/Distance_from_a_point_to_a_line |
| 1486 | |
| 1487 | float dx = endTransformed.x - startTransformed.x; |
| 1488 | float dy = endTransformed.y - startTransformed.y; |
| 1489 | |
| 1490 | float den = sqrtf( dx * dx + dy * dy ); |
| 1491 | if( den < FLT_EPSILON ) |
| 1492 | { |
| 1493 | return false; |
| 1494 | } |
| 1495 | |
| 1496 | float nom = fabs( dy * pointIn.x - dx * pointIn.y - startTransformed.x * endTransformed.y + startTransformed.y * endTransformed.x ); |
| 1497 | float distance = nom / den; |
| 1498 | |
| 1499 | if( distance > lineWidth ) |
| 1500 | { |
| 1501 | return false; |
| 1502 | } |
| 1503 | |
| 1504 | // Check that we are between the end points of the segment |
| 1505 |
nothing calls this directly
no test coverage detected