mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
Fixed a mathematical edge-case in line-intersection calculations
This commit is contained in:
parent
08788c3e05
commit
dd576a5192
1 changed files with 26 additions and 25 deletions
|
|
@ -99,7 +99,8 @@ namespace PathStrokeHelpers
|
|||
|
||||
return along >= 0 && along <= 1.0f;
|
||||
}
|
||||
else if (dy2 == 0 && dy1 != 0)
|
||||
|
||||
if (dy2 == 0 && dy1 != 0)
|
||||
{
|
||||
const float along = (y3 - y1) / dy1;
|
||||
intersectionX = x1 + along * dx1;
|
||||
|
|
@ -112,7 +113,8 @@ namespace PathStrokeHelpers
|
|||
|
||||
return along >= 0 && along <= 1.0f;
|
||||
}
|
||||
else if (dx1 == 0 && dx2 != 0)
|
||||
|
||||
if (dx1 == 0 && dx2 != 0)
|
||||
{
|
||||
const float along = (x1 - x3) / dx2;
|
||||
intersectionX = x1;
|
||||
|
|
@ -126,7 +128,8 @@ namespace PathStrokeHelpers
|
|||
|
||||
return along >= 0 && along <= 1.0f;
|
||||
}
|
||||
else if (dx2 == 0 && dx1 != 0)
|
||||
|
||||
if (dx2 == 0 && dx1 != 0)
|
||||
{
|
||||
const float along = (x3 - x1) / dx1;
|
||||
intersectionX = x3;
|
||||
|
|
@ -147,33 +150,31 @@ namespace PathStrokeHelpers
|
|||
distanceBeyondLine1EndSquared = 0.0f;
|
||||
return false;
|
||||
}
|
||||
else
|
||||
|
||||
const float along1 = ((y1 - y3) * dx2 - (x1 - x3) * dy2) / divisor;
|
||||
|
||||
intersectionX = x1 + along1 * dx1;
|
||||
intersectionY = y1 + along1 * dy1;
|
||||
|
||||
if (along1 >= 0 && along1 <= 1.0f)
|
||||
{
|
||||
const float along1 = ((y1 - y3) * dx2 - (x1 - x3) * dy2) / divisor;
|
||||
const float along2 = ((y1 - y3) * dx1 - (x1 - x3) * dy1) / divisor;
|
||||
|
||||
intersectionX = x1 + along1 * dx1;
|
||||
intersectionY = y1 + along1 * dy1;
|
||||
|
||||
if (along1 >= 0 && along1 <= 1.0f)
|
||||
if (along2 >= 0 && along2 <= 1.0f)
|
||||
{
|
||||
const float along2 = ((y1 - y3) * dx1 - (x1 - x3) * dy1);
|
||||
|
||||
if (along2 >= 0 && along2 <= divisor)
|
||||
{
|
||||
distanceBeyondLine1EndSquared = 0.0f;
|
||||
return true;
|
||||
}
|
||||
distanceBeyondLine1EndSquared = 0.0f;
|
||||
return true;
|
||||
}
|
||||
|
||||
distanceBeyondLine1EndSquared = along1 - 1.0f;
|
||||
distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
|
||||
distanceBeyondLine1EndSquared *= (dx1 * dx1 + dy1 * dy1);
|
||||
|
||||
if (along1 < 1.0f)
|
||||
distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
distanceBeyondLine1EndSquared = along1 - 1.0f;
|
||||
distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
|
||||
distanceBeyondLine1EndSquared *= (dx1 * dx1 + dy1 * dy1);
|
||||
|
||||
if (along1 < 1.0f)
|
||||
distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
intersectionX = x2;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue