summaryrefslogtreecommitdiff
path: root/fpcsrc/tests/webtbs/tw10425.pp
blob: 96909ee0e83ee55149eb6bce68e20dd309456675 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
{ %norun }

unit tw10425;

{$mode delphi}

interface

type
  TFloat      = double;
  TPoint2D    = record x,y:TFloat; end;
  TRectangle  = array [1..2] of TPoint2D;

  TPoint2DArray  = array of TPoint2D;
  TPolygon2D     = array of TPoint2D;
  
  function AABB(const Polygon   : TPolygon2D   ):TRectangle; overload;
  function AABB(const Curve     : TPoint2DArray):TRectangle; overload;

implementation

function AABB(const Polygon : TPolygon2D):TRectangle;
var
  i  : Integer;
begin
  Result[1].x := Polygon[0].x;
  Result[1].y := Polygon[0].y;
  Result[2].x := Polygon[0].x;
  Result[2].y := Polygon[0].y;
  for i := 1 to Length(Polygon) - 1 do
  begin
    if Polygon[i].x < Result[1].x then
      Result[1].x := Polygon[i].x
    else if Polygon[i].x > Result[2].x then
      Result[2].x := Polygon[i].x;
    if Polygon[i].y < Result[1].y then
      Result[1].y := Polygon[i].y
    else if Polygon[i].y > Result[2].y then
      Result[2].y := Polygon[i].y;
  end;
end;

function AABB(const Curve : TPoint2DArray):TRectangle;
var
  i  : Integer;
begin
  Result[1].x := Curve[0].x;
  Result[1].y := Curve[0].y;
  Result[2].x := Curve[0].x;
  Result[2].y := Curve[0].y;
  for i := 1 to Length(Curve) - 1 do
  begin
    if Curve[i].x < Result[1].x then
      Result[1].x := Curve[i].x
    else if Curve[i].x > Result[2].x then
      Result[2].x := Curve[i].x;
    if Curve[i].y < Result[1].y then
      Result[1].y := Curve[i].y
    else if Curve[i].y > Result[2].y then
      Result[2].y := Curve[i].y;
  end;
end;


end.