mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-11 10:19:13 +02:00
TAChart: Partially support infinite coordinates in LineIntersectsRect
git-svn-id: trunk@32795 -
This commit is contained in:
parent
bfd5aebbd4
commit
f7b3333c60
@ -243,24 +243,28 @@ end;
|
||||
|
||||
function LineIntersectsRect(
|
||||
var AA, AB: TDoublePoint; const ARect: TDoubleRect): Boolean;
|
||||
var
|
||||
dx, dy: Double;
|
||||
|
||||
procedure AdjustX(var AP: TDoublePoint; ANewX: Double); inline;
|
||||
var
|
||||
dx: Double;
|
||||
begin
|
||||
AP.Y += dy / dx * (ANewX - AP.X);
|
||||
dx := AB.X - AA.X;
|
||||
if not IsInfinite(dx) then
|
||||
AP.Y += (AB.Y - AA.Y) / dx * (ANewX - AP.X);
|
||||
AP.X := ANewX;
|
||||
end;
|
||||
|
||||
procedure AdjustY(var AP: TDoublePoint; ANewY: Double); inline;
|
||||
var
|
||||
dy: Double;
|
||||
begin
|
||||
AP.X += dx / dy * (ANewY - AP.Y);
|
||||
dy := AB.Y - AA.Y;
|
||||
if not IsInfinite(dy) then
|
||||
AP.X += (AB.X - AA.X) / dy * (ANewY - AP.Y);
|
||||
AP.Y := ANewY;
|
||||
end;
|
||||
|
||||
begin
|
||||
dx := AB.X - AA.X;
|
||||
dy := AB.Y - AA.Y;
|
||||
case CASE_OF_TWO[AA.X < ARect.a.X, AB.X < ARect.a.X] of
|
||||
cotFirst: AdjustX(AA, ARect.a.X);
|
||||
cotSecond: AdjustX(AB, ARect.a.X);
|
||||
|
@ -82,7 +82,7 @@ type
|
||||
implementation
|
||||
|
||||
uses
|
||||
TAGeometry, TAMath;
|
||||
Math, TAGeometry, TAMath;
|
||||
|
||||
{ TIntervalListTest }
|
||||
|
||||
@ -252,6 +252,12 @@ begin
|
||||
p1 := DoublePoint(10, 20);
|
||||
p2 := DoublePoint(15, -10);
|
||||
Check(p1, p2, DoublePoint(11.6667, 10), DoublePoint(13.3333, 0));
|
||||
|
||||
p1 := DoublePoint(10, 5);
|
||||
p2 := DoublePoint(SafeInfinity, 5);
|
||||
Check(p1, p2, p1, DoublePoint(20, 5));
|
||||
p2 := DoublePoint(10, NegInfinity);
|
||||
Check(p1, p2, p1, DoublePoint(10, 0));
|
||||
end;
|
||||
|
||||
procedure TGeometryTest.TestPointInPolygon;
|
||||
|
Loading…
Reference in New Issue
Block a user